提问者:小点点

使用节点js Mocha运行单个测试文件


我的所有测试都在测试文件夹下,当我给出npmtest时,所有测试都在执行。 现在我正在尝试按文件或它的描述运行我的测试脚本。 我的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'时,它没有获取给定的输入,相反,我得到以下警告警告:无法找到任何与模式“gividefilename/describe/it”匹配的文件,即使给定的输入匹配。

我的文件名模式是filename.test.js,文件夹结构类似于test\***\filename.test.js

谁能指点一下我在这件事上遗漏了什么。


共1个答案

匿名用户

您需要在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>