npm error ELIFECYCLE while running the test - node.js

I am using mocha-phantomjs setup for unit testing. I have following package.json scriot to run the tests.
"scripts": {
"test": "npm run testFlickr",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html"
}
This run ok in browser. And when I run the command npm testin cmd, the test run alright but it also gives following error
3 passing (5s)
6 failing
npm ERR! flickr-test# testFlickr: `mocha-phantomjs ./test/FlickrTest.html`
npm ERR! Exit status 6
npm ERR!
npm ERR! Failed at the flickr-test# testFlickr script.
npm ERR! This is most likely a problem with the flickr-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha-phantomjs ./test/FlickrTest.html
npm ERR! You can get their info via:
npm ERR! npm owner ls flickr-test
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "testFlickr"
npm ERR! cwd C:\Users\user\Desktop\test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\user\Desktop\test\npm-debug.log
npm ERR! not ok code 0
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
Please can anyone tell me how can I resolve this error.

I was having this same problem, and what fixed it for me was when I run my unit tests, do NOT use
npm run test
instead use:
npm test

When running npm test it squelches ELIFECYCLE errors so you never encounter this experience.
Reference to code
Once you move a test script to a different script-name you'll start seeing ELIFECYCLE errors.
My fix is to add a exit 0 to the end of the command. For your code it would look like this:
"scripts": {
"test": "npm run testFlickr",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html; exit 0"
}

And when I run the command npm test in cmd, the test run alright
No they aren't. You have 6 failing tests. The exit code of mocha-phantomjs is equal to the number of failing tests. Run mocha-phantomjs ./test/FlickrTest.html directly and see what is failing. Realize the PhantomJS is a bit different than your browser - you may have to debug it.
Your script setup is odd. You should just have:
"scripts": {
"test": "mocha-phantomjs ./test/FlickrTest.html"
}
Then the odd node errors should go away.

This is a problem when using npm run, it has to do with Mocha exiting with code !== 0 whenever a test fails. If you are on Windows try this:
"scripts": {
"test": "npm run testFlickr || ECHO.",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html || ECHO."
}

Related

Trouble building react-webapp with ESLint; ESLint couldn't find the config "developit" to extend from

My react app works as normal using npm start, but when I try npm run build I got trouble.
Oops! Something went wrong! :(
ESLint: 6.8.0.
ESLint couldn't find the config "developit" to extend from. Please check that the name of the config is correct.
The config "developit" was referenced from the config file in "/home/user/beregning-innsikt/beregning-innsikt-webapp/src/main/webapp/node_modules/#babel/preset-modules/package.json".
If you still have problems, please stop by https://gitter.im/eslint/eslint to chat with the team.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! beregning-innsikt-webapp#2.0.0 lint: `eslint 'src/**/*{.ts,.tsx}'`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the beregning-innsikt-webapp#2.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2020-08-11T08_20_44_975Z-debug.log
ERROR: "lint" exited with 2.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! beregning-innsikt-webapp#2.0.0 prebuild: `npm-run-all clean lint && aurora-mi git`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the beregning-innsikt-webapp#2.0.0 prebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2020-08-11T08_20_45_002Z-debug.log
The Babel config file contains this:
"eslintConfig": {
"extends": "developit",
"rules": {
"no-console": 0,
"new-cap": 0
}
},
I have tried node v 13.7.0 and 14.1.0.
Does anybody know how to solve this problem?
Seems like it is linting node_modules too
To fix this you can create file .eslintignore in your root directory and add node_modules/ folder to your eslintignore file

Why is Ava js not showing error logging locally, only in ci

I have a failing ava test that should error out like this:
$ npm run test
> fetch_courses#1.0.0 test /home/travis/build/********/fetch_courses
> tsc && ava
Uncaught exception in test/fetchTerms.test.ts
Error: Cannot find module '../config.js'
Require stack:
- /home/travis/build/********/fetch_courses/src/fetchTerms.ts
- /home/travis/build/********/fetch_courses/test/fetchTerms.test.ts
- /home/travis/build/********/fetch_courses/node_modules/ava/lib/worker/subprocess.js
› - node_modules/ava/lib/worker/subprocess.js
› src/fetchTerms.ts:2:1
› Object.<anonymous> (src/fetchTerms.ts:139:4)
› Module.m._compile (node_modules/ts-node/src/index.ts:858:23)
› require.extensions.<computed> (node_modules/ts-node/src/index.ts:861:12)
✖ test/fetchTerms.test.ts exited with a non-zero exit code: 1
─
1 uncaught exception
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fetch_courses#1.0.0 test: `tsc && ava`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fetch_courses#1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/travis/.npm/_logs/2020-07-21T21_30_16_127Z-debug.log
The command "npm run test" exited with 1.
cache.2
store build cache
which only happens in my travis build.
When I freshly clone [my repository][1] and run npm install and npm run test, which is exactly what happens in travis, this is the logging i see.
$ npm run test
> fetch_courses#1.0.0 test /mnt/c/Users/********/Projects/fetch_courses
> tsc && ava
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fetch_courses#1.0.0 test: `tsc && ava`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fetch_courses#1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /mnt/c/Users/********/.npm/_logs/2020-07-21T22_06_02_028Z-debug.log
So you can see that I'm missing the entire Ava output/error logging.
I don't know what else I can do, but maybe it's some sort of configuration issue? The repository is linked so feel free to poke around and/or try to reproduce.
Couldn't find an answer since it seems like the issue is local to my IDE only, so my workaround was to run ava on the compiled javascript version of the tests. Logging worked there, for whatever reason.

Setting up a task in package.json

I am trying to setup a task in package.json
"scripts": {
"unit-test": "mocha './test/unit/**/*.spec.js'",
}
However when I run
npm run unit-test
the following errors are thrown in the console at the end of the run:
npm ERR! Darwin 16.6.0
npm ERR! argv "/Users/shreya.vakil/.nvm/v6.9.5/bin/node" "/Users/d.bubble/.nvm/v6.9.5/bin/npm" "run" "unit-test"
npm ERR! node v6.9.5
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! myapp#0.0.1-SNAPSHOT unit-test: `mocha './test/unit/**/*.spec.js'`
npm ERR! Exit status 1
However, if I change the command to
"scripts" : {
"unit-test": "mocha './test/unit/**/*.spec.js'; exit 0",
}
this error is not thrown. However, I am not sure if this is the right approach.
The original behavior is correct, if a little ugly - if your tests fail, Mocha returns an exit code of 1, which is technically an error. Your second example makes the output prettier, but it'll cause you issues if you try to integrate your build scripts into other tools (for example, Travis), as they won't be able to detect when your tests fail.
The best solution to this would be to get rid of the exit 0 and upgrade your version of NPM - the output was made much shorter in v4.6.1. You can do this by running the following command:
npm install npm -g

I am getting different results running a script with npm than calling the command directly - Node

I am setting up my environment to lint ES6. I installed eslint and can see it in my node_modules. In my node_modules/bin directory, I have the command eslint.
I can run the command and point it at the directory and I get no errors:
./node_modules/.bin/eslint src/main/webapp/js/lcrf
I can see all of the linting errors that I need to fix.
I have also added the command into my package.json:
"scripts": {
"lint": "eslint src/main/webapp/js/lcrf"
},
Now I try to run the command with npm run lint. It lints my files and I get the same number of linting errors, but then node errors out. Here is my stacktrace:
npm ERR! Darwin 14.3.0
npm ERR! argv "node" "/usr/local/bin/npm" "run" "lint"
npm ERR! node v0.12.2
npm ERR! npm v2.7.4
npm ERR! code ELIFECYCLE
npm ERR! lcrf#0.0.0 lint: `eslint src/main/webapp/js/lcrf`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the lcrf#0.0.0 lint script 'eslint src/main/webapp/js/lcrf'.
npm ERR! This is most likely a problem with the lcrf package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! eslint src/main/webapp/js/lcrf
npm ERR! You can get their info via:
npm ERR! npm owner ls lcrf
npm ERR! There is likely additional logging output above.
What would cause this to happen? What is the difference in the 2 ways that I am running the command?
npm is freaking out over the non-zero return code from eslint. If you want lint errors to be an indication of "whoa, that's not supposed to happen, red alert, something is really wrong if this got published" then that's what you've got.
If you don't use the exit code (say, to stop subsequent build steps) and you just want the output to be just the eslint output and no subsequent npm freak out, use this in your package.json:
"lint": "eslint src/main/webapp/js/lcrf || exit 0"
Note this in "Best Practices" section of the npm scripts docs:
Don't exit with a non-zero error code unless you really mean it. Except for uninstall scripts, this will cause the npm action to fail, and potentially be rolled back. If the failure is minor or only will prevent some optional features, then it's better to just print a warning and exit successfully.

npm run cmd fails while cmd on command line works

In my HTTP Status Check project:
If I run node_modules/.bin/jshint . I get:
$ node_modules/.bin/jshint .
test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon.
1 error
It executes correctly and produces the expected output: 1 error.
But if I add that command to package.json and try and run it through npm run then it works and produces the expected output but also follows that with a bunch of errors:
$ npm run jshint
> http-status-check#0.0.5 jshint /home/guy/source/http-status-check
> jshint .
test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon.
1 error
npm ERR! Linux 3.13.0-24-generic
npm ERR! argv "node" "/home/guy/local/bin/npm" "run" "jshint"
npm ERR! node v0.10.31
npm ERR! npm v2.0.0
npm ERR! code ELIFECYCLE
npm ERR! http-status-check#0.0.5 jshint: `jshint .`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the http-status-check#0.0.5 jshint script.
npm ERR! This is most likely a problem with the http-status-check package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! jshint .
npm ERR! You can get their info via:
npm ERR! npm owner ls http-status-check
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/guy/source/http-status-check/npm-debug.log
This is how it's defined in package.json:
"scripts": {
"jshint": "node_modules/.bin/jshint .",
},
What have I done wrong?
Don't exit with a non-zero error code unless you really mean it. Except for uninstall scripts, this will cause the npm action to fail, and potentially be rolled back. If the failure is minor or only will prevent some optional features, then it's better to just print a warning and exit successfully.
From https://www.npmjs.org/doc/misc/npm-scripts.html
Use:
node_modules/.bin/jshint .; true
Or write a wrapper that calls jshint and then ignores the exit code and exits successfully with a exit code of zero.

Resources