我所有的测试都在 test 文件夹下,当我给 npm test
时,所有的测试都会被执行。现在我正在尝试按文件或描述运行我的测试脚本。我的 package.json 中有以下内容
"scripts": {
"test": "set NODE_ENV=test&& nyc --reporter=html --reporter=text mocha 'test/**/*.js' --exit --timeout 7000"}
当我给出 npm test --grep 'filename/describe/it'
时,它没有获取给定的输入,而是收到以下警告 Warning: Cannot find any files匹配模式“给定文件名/描述/it”
即使给定的输入匹配。
我的文件名模式是 filename.test.js
并且文件夹结构类似于 test\***\filename.test.js
任何人都可以指导我了解我在这方面缺少什么。
最佳答案
您需要在 npm
命令中包含 grep
选项:
"scripts": {
"test": "set NODE_ENV=test&& nyc --reporter=html --reporter=text mocha 'test/**/*.js' --exit --timeout 7000 --grep"
}
然后调用它:
npm run test <name of test>
关于node.js - 使用 Node js Mocha 运行单个测试文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62996498/