如何仅指定具有特定元标记的测试

How to specify only tests with specific meta tag

我有一个使用元标记的测试套件,我正在尝试 运行 特定测试。

我试过使用以下方法:

  .filter((fixturePath, fixtureName, testMeta) => {
    return testMeta.smoke == 'true';
  })

runner.ts

const createTestCafe = require('testcafe'); let testcafe = null; createTestCafe('localhost', 1337, 1338) .then((tc) => { testcafe = tc; const runner = testcafe.createRunner(); return runner .src(['tests/specs/**/*.spec.ts']) .filter((fixturePath, fixtureName, testMeta) => { return testMeta.smoke == 'true'; }) .browsers(['chrome']) .reporter([ 'list' ]) .run(); }) .then((failedCount) => { console.log('Tests failed: ' + failedCount); testcafe.close(); });

示例测试

test('Login with correct credentials', async (t) => { await LoginPage.login(data.users.userPrivate.username, data.users.userPrivate.password); await t.expect(Helper.getLocation()).contains(endpoints.personalAreaOverview); }).meta('regression', 'true').meta('smoke', 'true');

预期:运行 仅包含 ('smoke'、'true')

的测试

实际:Error: No tests to run. Either the test files contain no tests or the filter function is too restrictive.

filter 方法有另一个参数顺序。您需要按如下方式更改代码:

runner.ts

.filter((testName, fixtureName, fixturePath, testMeta, fixtureMeta) => {
    return testMeta.smoke === 'true';
})