html 没有使用 --reporter 选项生成报告

html report is not getting generated with --reporter option

这是一个奇怪的行为,需要帮助才能理解为什么会这样。

我使用 -g 和 --save-dev(意思是全局和本地)安装了 testcafe。

我有 package.json 脚本,例如

"scripts":{
"test": "testcafe chrome:headless"
}

现在,当我运行命令
npm test tests/samplefile.js --reporter html:reports/report.html
报告没有生成,但是

如果我 运行 命令,它会起作用
Testcafe chrome:headless tests/samplefile.js --reporter html:reports/report.html
生成报告。在这种情况下,它使用全局安装的包。

这个命令也有效
npx testcafe tests/samplefile.js --reporter html:reports/report.html

所以,我的问题是,为什么 npm test 命令没有生成 HTML 报告?我做错了什么吗?顺便说一句,测试在所有情况下都通过了。

TestCafe 需要 2 个参数:'browser list' 和 'file-or-glob',用于指定 运行 测试的文件或目录(由 space 分隔)。

所以,命令

testcafe chrome:headless tests/samplefile.js --reporter html:reports/report.html

正确。

命令

npm test tests/samplefile.js --reporter html:reports/report.html

不正确,因为 'npm' 不允许您使用这种方式将参数传递给正在执行的命令。