mocha错误:未找到测试文件:“ test /” npm ERR!测试失败

时间:2019-02-21 10:51:33

标签: node.js mocha

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

错误:未找到测试文件:“ 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摩卡 我 并使用npm test运行测试Im

项目结构:

project structure

6 个答案:

答案 0 :(得分:2)

我解决了同样的问题......

"test": "mocha -r ts-node/register 'tests/**/*.ts'"

答案 1 :(得分:1)

也有这个问题,这对我有用:

./node_modules/mocha/bin/mocha -r esm -r ts-node/register "src/**/*Test.ts"

答案 2 :(得分:0)

您需要提供测试文件夹的路径。试试这个:

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

    },

npm测试

答案 3 :(得分:0)

看到您的项目结构,似乎您有一个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",
},

希望有帮助

答案 4 :(得分:0)

如果直接在测试文件夹中没有测试文件,您将得到该错误。

解决方案是在package.json中为测试添加“ --recursive”选项。

"scripts": {
        "test": "mocha --recursive --reporter mocha-junit-reporter --timeout 60000 --exit",

    },

这将告诉摩卡“递归查找测试文件”

答案 5 :(得分:0)

保存测试文件时不使用扩展名,这是我发生的一个原因。是的,我曾经做过一次,因此Mocha无法检测到文件并运行测试。确保它至少具有.js作为扩展名。请注意,某些IDE可能已经将文件显示为JS(因为它检测到文件内容),但是您仍然需要将文件的扩展名为JS。