有没有办法在我的emberjs应用程序中获得所有已创建测试的列表?

mi7gmzs6  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(148)

我需要一种方法来获得我所有的ember测试的名称,因为我想通过使用--filter“TEST-NAME”标志在一个单独的线程中运行它们。
现在,我使用的是硬编码数组。

qyyhg6bp

qyyhg6bp1#

虽然没有文档说明,但是你可以在根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)

相关问题