'Create script on package.json to run mocha tests
I have an express.js application and I am trying to write a script to run mocha tests "npm run test" but I am getting an error message that "." is not recocnized. This is my package.json file:
{
"name": "node-js-api",
"version": "1.0.0",
"description": "Sample project NodeJS",
"main": "index.js",
"scripts": {
"start": "node src/index.js",
"test": "./node_modules/.bin/mocha --watch-extensions js \"{,!(node_modules)/**/}*.test.js\" "
},
"keywords": [
"API",
"Nodejs"
],
"license": "",
"dependencies": {
"body-parser": "^1.19.2",
"express": "^4.17.1",
"npm-run-all": "^4.1.5"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^7.0.1"
}
}
Getting this error:
'.' is not recognized as an internal or external command,
operable program or batch file.
The idea is to use "npm run test" and run all the files that ends with ".test.js" inside "test" folder
Solution 1:[1]
Assuming your tests are in the ./test directory at the root of your project, your test script should be:
"scripts": {
"test": "mocha"
}
You should not be in ./node_modules/
If you want to run mocha at the command line, you can run npx mocha. The docs in mocha haven't been updated since npx was added to npm.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kevintechie |
