How can I solve problem when run test my created node, 'mocha' is not recognized as an internal or external command, operable program or batch file

Hi all,

I have some problem about unit test my created node.

After I follow help for adding test into my created node.

node-red-node-test-helper - npm (npmjs.com)

Then, I run command "npm test", the error has occur.

'mocha' is not recognized as an internal or external command, operable program or batch file.

How can I solve this problem? :thinking:

Please advice me.

In your custom node's package.json file have you defined a "test" script and if so, what is it set to?

Have you added mocha as a devDependency of your module?

Thank you very much for your reply. :blush:

I added "test" in my package.json. But I did not add "mocha" as a devDependencies. So I must add "mocha", right? :thinking:

Below is my package.json

{
  "name": "node-red-contrib-node-line-api",
  "version": "1.0.0",
  "description": "Node Red with LINE API such as LINE Notify and other",
  "license": "Apache-2.0",
  "dependencies": {
    "axios": "^0.24.0",
    "form-data": "4.0.0",
    "querystring": "^0.2.0"
  },
  "main": "node.js",
  "node-red": {
    "nodes": {
      "node-line-notify": "nodes/node-line-notify.js"
    }
  },
  "devDependencies": {
    "node-red": "^2.2.0",
    "node-red-node-test-helper": "^0.2.7"
  },
  "scripts": {
    "test": "mocha \"test/**/*_spec.js\""
  }
}

If you have added a test script that wants to use mocha, then yes, you need to add mocha to your project.

Thank you very much. :blush:

After add mocha into my project. Now it can run test.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.