首页 > 解决方案 > mocha 错误:未找到测试文件:“test/”npm ERR!测试失败

问题描述

我正在尝试在 linux > @test C:\Users\wd.ssh\tel\qa_test\mocha-api-tests 上运行 mocha 测试

错误:未找到测试文件:“test/”npm ERR!测试失败。有关更多详细信息,请参见上文。

这是我的 package.json

{
    "scripts": {
        "test": "mocha --reporter mocha-junit-reporter --timeout 60000 --exit",
        
    },
    "dependencies": {
        "cassandra-driver": "3.5.0",
        "chai": "4.2.0",
        "chai-http": "4.2.0",
        "express": "4.16.4",
        "mocha-junit-reporter": "1.18.0",
        "request-promise": "4.2.2"
    }
}

使用的命令: npm install --global mocha npm i 并运行我正在使用的测试 npm test

项目结构:

项目结构

标签: javascriptnode.jstestingmocha.js

解决方案


看到你的项目结构,似乎你有一个test.js所以 mocha 应该以这个文件为目标。

"scripts": {
  "test": "mocha test.js --reporter mocha-junit-reporter --timeout 60000 --exit",
},

如果要添加更多测试文件,最好将它们放在测试目录中,例如/test,必须将目标更改为目录中的测试文件。

"scripts": {
  "test": "mocha 'test/**/*.js' --recursive --reporter mocha-junit-reporter --timeout 60000 --exit",
},

希望能帮助到你


推荐阅读