Reputation: 133
I've had a Ruby on Rails project for several years set up with Semaphore CI. The Semaphore project is set to use Ruby 2.2.2 as it's language. Over time the project adopted npm with browserify and babelify, and we're using all the latest ES6 features. We added npm install
as a setup step to our Semaphore build, and this was working fine.
Now we are starting to use Jest to test our javascripts, and this is working fine locally. But when I added npm test
to our Semaphore test commands, npm test
fails on semaphore CI with the following errors:
FAIL app/assets/javascripts/tests/selectors/conversations.test.js
● Test suite failed to run
SyntaxError: Unexpected token {
at _load_jsdom (node_modules/jest/node_modules/jest-cli/node_modules/jest-environment-jsdom/build/index.js:17:41)
FAIL app/assets/javascripts/tests/reducers/conversations.test.js
● Test suite failed to run
SyntaxError: Unexpected token {
at _load_jsdom (node_modules/jest/node_modules/jest-cli/node_modules/jest-environment-jsdom/build/index.js:17:41)
Test Suites: 2 failed, 2 total
Tests: 0 total
Snapshots: 0 total
Time: 0.65s
Ran all test suites.
npm ERR! Test failed. See above for more details.
This is some relavent information from the project's package.json
:
"scripts": {
"test": "jest --debug --verbose"
},
"jest": {
"roots": [
"<rootDir>/app/assets/javascripts"
]
},
"dependencies": {
"babel-plugin-syntax-async-functions": "^6.3.13",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-regenerator": "^6.3.18",
"babel-polyfill": "^6.3.14",
"babel-preset-env": "^1.5.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2016": "^6.24.1",
"babel-preset-es2017": "^6.24.1",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babelify": "^7.2.0",
"browserify": "^14.0.0",
"browserify-incremental": "^3.1.0",
"es6-promise": "^3.0.2",
"fetch": "^0.3.6"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-jest": "^22.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"bootstrap": "^4.0.0-beta.3",
"browserify": "^14.4.0",
"browserify-incremental": "^3.1.1",
"jest": "^22.1.1"
}
This is the .babelrc
file located in the project :
{
"presets": ["env", "es2015", "es2016", "es2017", "stage-0", "react"]
}
Locally, I am on node v7.10.0
. I SSH'ed into my Semaphore CI session and discovered that node v4.8.4
is installed there. I tried installing node v4.8.4
on my local machine and with that version installed, I get the same test errors (posted above) locally as I did on CI. So this is a node version issue.
I added:
"engines": {
"node": ">= 7.1.0"
}
to my package.json
file, but that did not affect the node version installed on Semaphore.
So if I already have Ruby 2.2.2
chosen as my language and version in the Semaphore Build Settings, how to I change my node version?
Thanks in advance for the help.
Upvotes: 1
Views: 545
Reputation: 56
Ervin from Semaphore here,
To change the current Node.js version in the environment, whilst Ruby 2.2 is selected, add nvm use 7.1
to your setup steps. This will switch to the desired Node.js version and everything should work as expected. There's also an example of this in the docs.
Get in touch on support if you run into any issues.
Upvotes: 0
Reputation: 27114
It looks like SemaphoreCI is not using the same version of NPM as you. But you can set that within the build settings like this :
nvm install v8.9.4
npm install
npm test
You can test it out in the SSH
Upvotes: 1