nodemon - 'mocha' is not recognized as an internal or external command, operable program or batch file.
mocha 테스트를 했더니, 다음과 같이 오류가 발생합니다.
c:\temp> nodemon --exec npm test
[nodemon] 1.19.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `npm test`
> tests@1.0.0 test E:\nodejs\weather-app\node-tests
> mocha **/*.test.js
'mocha' is not recognized as an internal or external command, operable program or batch file.
npm ERR! Test failed. See above for more details.
[nodemon] app crashed - waiting for file changes before starting...
간단합니다. mocha를 g 옵션 없이 설치했기 때문입니다.
c:\temp> npm i mocha --save-dev
이렇게 해야 합니다. ^^
c:\temp> npm install -g mocha --save-dev
부가적으로, nodemon을 우회해서 실행할 수 있도록 다음과 같이 설정하는 것도 가능합니다.
{
"name": "tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec npm test"
},
"author": "",
"license": "ISC",
"devDependencies": {
"mocha": "^6.1.4"
}
}
그래서 이렇게 "npm run [사용자_스크립트_이름]"으로 동일한 효과를 낼 수 있습니다.
c:\temp> npm run test-watch
참고로, python 스크립트를 수정해 저장하면 그 즉시 자동으로 해당 스크립트를 실행해 주는 도구가 있긴 하지만, 그냥 nodemon으로도 할 수 있습니다.
c:\temp> nodemon --exec python test.py
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]