使用 NPM 测试跳过用户输入

boo*_*tv2 5 node.js reactjs jestjs

运行命令“NPM run test”时,NPM 运行我所有的单元测试,但它显示一个“观察使用情况”对话框,需要用户输入。

我希望能够在我的构建过程中运行“NPM 运行测试”,所以我想有一种方法可以跳过这个“观察使用”对话框。我已经尝试过使用 --forceExit ,它不会改变任何东西。

是否有任何命令行参数可用于在没有此对话框的情况下启动“NPM 运行测试”?或者,我是否可以向 package.json 的脚本部分添加一些内容,从而不显示此对话框?

我的 package.json 的脚本部分:

"scripts": {
    "start": "node node_modules/react-scripts/bin/react-scripts.js start",
    "build": "node node_modules/react-scripts/bin/react-scripts.js build",
    "test": "node node_modules/react-scripts/bin/react-scripts.js test --env=jsdom",
    "test-coverage": "npm test -- --coverage",
    "test-json": "npm test -- --coverage --json",
    "eject": "node node_modules/react-scripts/bin/react-scripts.js eject",
    "flow": "node node_modules/flow-bin/vendor/flow",
    "flow-coverage": "node node_modules/flow-coverage-report/bin/flow-coverage-report.js",
    "flow-coverage-report": "if process.platform === 'win32'; then start ./flow-coverage/index.html; else open ./flow-coverage/index.html; fi",
    "flow-json": "node node_modules/flow-bin/vendor/flow --json",
    "flow-stop": "node node_modules/flow-bin/vendor/flow stop"
   }
Run Code Online (Sandbox Code Playgroud)

上述对话框:

Watch usage
 > Press u to update failing snapshots.
 > Press p to filter by a filename regex pattern.
 > Press t to filter by a test name regex pattern.
 > Press q to quit watch mode.
 > Press Enter to trigger a test run.
Run Code Online (Sandbox Code Playgroud)

boo*_*tv2 0

我找到了一种在将 Jest 作为“NPM 测试”运行时禁用其监视模式的方法。运行 package.json 脚本部分中列出的 test-coverage 时,jest 不会以监视模式启动,而是进行覆盖。

这并不完全是我想要的,但至少我可以使用它来运行“NPM run test-coverage”作为我的构建解决方案的一部分。