简体   繁体   English

NPM测试错误,但未进行Mocha测试node.js

[英]Error with npm test but not mocha test node.js

I am working with node.js and mocha unit testing and I want to be able to run the test command through npm. 我正在使用node.js和mocha单元测试,并且希望能够通过npm运行测试命令。 When I run mocha test in my tests folder, the test runs sucessfully. 当我在我的测试文件夹中运行mocha test时,测试成功运行。 However, when I run npm test, the test gives me an error. 但是,当我运行npm test时,该测试给我一个错误。

在此处输入图片说明

Here is a snippet from my package.json: 这是我的package.json中的一个片段:

  "scripts": {
    "test": "./tests/test.js"
  },

Anyone know why the npm test would give me an error but mocha test runs just fine? 有人知道为什么npm测试会给我一个错误,但是mocha测试运行得很好吗?

Thanks 谢谢

By using ./tests/test.js , because it's executable, it tries to execute the file using your shell. 通过使用./tests/test.js ,因为它是可执行文件,所以它尝试使用您的shell执行文件。

I think that node should be executing the file and not your default shell. 我认为该节点应执行文件,而不是默认外壳程序。

I think you could change it to node ./tests/test.js or to mocha test 我认为您可以将其更改为node ./tests/test.jsmocha test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM