Jest test suite fails to run on Circleci - node.js

I have set my Circleci container in Ubuntu 14.04, and my node version is 6.11.2. I have written a basic test case using Jest.It works perfectly in my local environment, the test suit runs and the test case passes. However, when I am trying to deploy it using Circleci, the build fails as the test suite fails to execute. Here's the error circleci is throwing-
FAIL test/index.test.js
● Test suite failed to run
SyntaxError: Unexpected token {
at _load_jsdom (node_modules/jest-environment-jsdom/build/index.js:17:41)
I can't figure out where the error actually is since it executes perfectly in my local environment. I have used the same node version in my circleci build as well.

Make sure the docker image has exactly the same node version as your local environment. E.g.
docker:
- image: circleci/node:8.9.4

Related

Jest showing error on passed test on Azure

When I run jest test locally I see all my tests as passed.
PASS apps/web/customers/src/components/TelephoneDial/tests/TelephoneDialButton.test.tsx
When I run jest test in my build on Azure I get the following:
'##[error]PASS apps/web/customers/src/components/TelephoneDial/tests/TelephoneDialButton.test.tsx (8.186s)
During the actual build step on azure I also see this:
'##[error]lerna notice cli v3.13.4
While locally it shows:
lerna notice cli v3.13.4
Why is Azure showing this output as errors?
I haven't found what's causing this issue, but switching from Windows 2019 with VS2019 agent to vs2017-win2016 has fixed the issue, now the output doesn't report errors.

Why when test fails jenkins still says success?

I have a MEAN project. Using Jenkins on an EC2 machine I build this using the following shell script:
npm install && PORT=8888 npm test
mocha returns 2 (number of failing tests) but still jenkins says:
Finished: SUCCESS.
If tests are failing I expect to see
Finished: FAILURE
Do you know why its not working fine?
You can:
Use a test runner like Karma, or
Tell Mocha to report in, for example, XUnit format, by passing Mocha the --reporter xunit flag. XUnit closely aligns with JUnit which Jenkins understands, or
Add in a custom reporter — mocha-jenkins-reporter is a decent option.
In the end I used a different solution: installed Jenkins Text Finder and if "expected - actual" is found in log (test failed), I let this plugin to mark the build as "Unstable".

Mocha test that runs locally won't run on Jenkins (environment issue)

I'm currently trying to implement CI with Jenkins for an emberjs node project that uses mocha for unit testing. I'm running Jenkins on an Amazon EC2 server.
When I run mocha locally (both on my desktop, AND on the ec2 server) I get this:
./node_modules/mocha/bin/mocha
Initializing server on port 8090
Unit Test for /test
test API call incoming
key res value is: test!
✓ gives a json object with res: test!
1 passing (35ms)
However, when I have jenkins set up to run this same command:
01:44:46 + ./node_modules/mocha/bin/mocha
01:44:46
01:44:46 /var/lib/jenkins/workspace/Rekindle2_Node/server/routes/test/getTest.js:4
01:44:46 const getTest = (req, res) => {
01:44:46 ^
01:44:46 SyntaxError: Unexpected token >
etc
I've double checked, the package.json has everything I need, and I know that I don't have anything globally installed that changes things (as I managed to git clone, npm install, and run mocha from the ec2 instance). All I know is that jenkins sometimes can have issues with consuming environment variables from the server it's running on? Does anyone know what the issue I'm encountering could be? I've tried uninstalling and reinstalling node as well, it could be that Jenkins is looking at an older installation of node while the ec2 is not. Is there any way to tell this? How do I look at the environment variables of a specific build?
That looks like Jenkins is using an older version of node.js. To confirm this I would add logging to your Jenkins job. node --version will print the version of node.js that Jenkins is aware of. Also if you are interested in the environment there is a view in the Jenkins web ui to show the environment from a particular build. Or you can add env as a line in your Jenkins build script to print out the current environment variables. If it turns out to be a node.js version issue, I would look into using a plugin to manage your nodejs versions: node.js Jenkins plugin

jasmine-node and bamboo - test failed

I using jasmine-node for testing node app, and have integration with bamboo, but the problem is when some of the test failed bamboo reports that command jasmine-node test-name.js exits with 1 and that on bamboo job dashboard I have label testless build without reports about tests.
Also I made wrapper in node to run that command and still getting that output of executing is 1.
Can I use this wrapper for bamboo, because I'm using --junitreport flag and artifact for junit tests?
Or I can setup jasmine-node to prevent throwing error if some of the test fails?
Just put the exit 0 at end of script in bamboo job.

How to run a specific node.js unit test, using test.py?

I'm trying to run the node.js unit tests, on Windows. I can run them all using either vcbuild.bat test, or python ./tools/test.py. Either of those commands will run all available tests. I'm writing my own test and just want to run it. How can I run a specific test file, using test.py?
It ended up being as simple as running the file with the compiled node binary. Simply node path\to\test.js.

Resources