我很难跑黄瓜。如果标签未作为 CLI 参数传递,我想运行所有场景,或者根据传递的标签作为 CLI 参数运行某些场景。 这是我的配置文件:
module.exports = {
default: {
tags: '@run or ""',
formatOptions: {
snippetInterface: 'async-await'
},
paths: [
'src/features/'
],
dryRun: false,
require: [
'src/step_definitions/**/*.ts',
'hooks.ts'
],
requireModule: [
'ts-node/register'
],
format: [
'json:test-results/json-report.json',
'progress'
],
parallel: process.env.CI ? 10 : 1
}
}
这是运行测试的脚本:
"test": "cucumber-js --config=configs/cucumber.cjs || true"
如果我通过 @run 标签场景,并运行该标签或不运行任何测试。如果我从配置中删除标签属性,无论我通过什么标签,所有测试都会运行。例如,我有这样的场景:
@api
Scenario: Name of the scenario
// Steps
config.js:
module.exports = {
default: {
formatOptions: {
snippetInterface: 'async-await'
},
paths: [
'src/features/'
],
dryRun: false,
require: [
'src/step_definitions/**/*.ts',
'hooks.ts'
],
requireModule: [
'ts-node/register'
],
format: [
'json:test-results/json-report.json',
'progress'
],
parallel: process.env.CI ? 10 : 1
}
}
终端命令:
npm run test --tags="@api"
此命令正在运行所有测试。如果该标签传递了 CLI 参数,我怎样才能让它运行带有特定标签的测试,或者运行所有测试?
非常感谢您的帮助。
在玩完代码后我找到了解决方案:
更新配置:
module.exports = {
default: {
// removed tags property
formatOptions: {
snippetInterface: 'async-await'
},
paths: [
'src/features/'
],
dryRun: false,
require: [
'src/step_definitions/**/*.ts',
'hooks.ts'
],
requireModule: [
'ts-node/register'
],
format: [
'json:test-results/json-report.json',
'progress'
],
parallel: process.env.CI ? 10 : 1
}
}
"scripts": {
"test": ""cucumber-js --config=configs/cucumber.cjs"
}
测试运行命令:
npm run test -- --tags "@TAG_NAME" || true