【问题标题】:Is there a way for getting a list of all created tests in my emberjs app?有没有办法在我的 emberjs 应用程序中获取所有已创建测试的列表?
【发布时间】:2020-10-14 20:46:58
【问题描述】:

我需要一种方法来获取所有 ember 测试的名称,因为我想使用 --filter "TEST-NAME" 标志在单独的线程中运行它们。

现在,我使用的是硬编码数组。

【问题讨论】:

  • 你可以使用ember-exam在线程中运行(并行)
  • 好消息@GokulKathirvel。这至少可以提供另一种选择。我真的很想单独运行它们,并得到一个布尔输出(失败/通过)来探索我得到的一些脆弱性。

标签: testing ember.js qunit


【解决方案1】:

它没有记录,但是您可以使用根 QUnit 对象上的 config 对象来获取测试套件中的所有模块,然后是每个模块中的测试及其名称。请注意,模块中的任何 not 测试仍然会出现,但带有一个空名称的模块。这是runnable jsfiddle with the example,然后是下面的代码。

QUnit.test('no-module', (assert) => { assert.equal(0,0) })

QUnit.module('foobar', () => {
  QUnit.test('foo', (assert) => { assert.equal(1, 1) })
  QUnit.test('bar', (assert) => { assert.equal(2, 2) })
})

QUnit.module('batbaz', () => {
  QUnit.test('bat', (assert) => { assert.equal(3, 3) })
  QUnit.test('baz', (assert) => { assert.equal(4, 4) })
})

const testNames = []
QUnit.config.modules.forEach((module) => {
  testNames.push(...module.tests.map(test => test.name))
})

console.log(testNames)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    • 2021-04-09
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 2011-01-04
    • 2010-09-07
    相关资源
    最近更新 更多