摩卡与 nodejs

Mocha with nodejs

我正在尝试 运行 在我的 Node.js 应用程序中进行一些 Mocha 测试。

这是我的文件夹结构:

compute/
  folder1/
    app/
      tests/
        mytest.js
  folder2/
    app/
      tests/
        mytest2.js

我在安装了 mocha 的情况下得到了 package.json

当我尝试使用 yarn test 开始测试时,出现错误

Warning: Could not find any test files matching pattern: test

No test files found

我怎样才能运行呢?

因为我的文件夹名称是“tests”而不是默认的“test”,而且它们不在源代码中。

当您不使用默认文件夹时,您需要将它们指定为参数。示例如下:

mocha "folder{1,2}/**/tests/*.js"

如果您只想 运行 npm test/yarn test,那么您需要更新 package.json 文件,如下所示:

  "scripts": {
    "test": "mocha \"folder{1,2}/**/tests/*.js\"",
  },