没有 mocha 测试 运行 或将 npm 与 | 一起使用时报告xargs

no mocha tests run or report when using npm with | xargs

我正在尝试使用 npm 来 运行 mocha 测试,如下所示:

scripts: {
  test: "find ./src ./test -name *.js | xargs mocha --opts mocha.opts"
}

当我直接从 CLI 执行它时它工作正常,但当我使用 npm 运行 测试时似乎没有执行任何测试(或者至少不显示它们的任何输出)。

仅供参考:我使用的是 xargs,因为 mocha 没有忽略文件的选项,我使用的是 emacs,它会在同一目录中生成用于 linting 的临时文件

您可能需要转义 *.js:

scripts: {
  test: "find ./src ./test -name '*.js' | xargs mocha --opts mocha.opts"
}