Reputation: 1265
On my local pc, I am able to run 'npm test' command without any error. But when I push my feature branch to Github, Circleci is not able to run my tests and ends up with an error like
sh: 1: jest: not found
npm ERR! Test failed. See above for more details.
Exited with code 1
I am using this Circleci config.yml file and it is not working:
version: 2.1
jobs:
build:
docker:
- image: circleci/node:10.1.0
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-
- run: npm install
- save_cache:
key: v1-dependencies-{{ checksum "package.json" }}
paths:
- node_modules
test:
docker:
- image: circleci/node:10.1.0
steps:
- checkout
- run:
name: Test
command: npm test
- run:
name: Generate code coverage
command: './node_modules/.bin/nyc report --reporter=text-lcov'
- store_artifacts:
path: test-results.xml
prefix: tests
- store_artifacts:
path: coverage
prefix: coverage
workflows:
version: 2.1
build_and_test:
jobs:
- build
- test:
requires:
- build
If I use this config.yml instead, it is working:
version: 2.1
jobs:
build:
docker:
- image: circleci/node:10.1.0
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-
- run: npm install
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: npm test
I am wondering why the first config.yml file is not working? Any clue about this? Thank you all.
Upvotes: 0
Views: 2393
Reputation: 4017
In the first config, you are running npm test
in the test
job. You need to have Jest installed but you never installed it, thus it fails.
In the second config, before npm test
is ran, npm install
is run first which I assume is installing Jest.
While you do run npm install
in the first config, it's ran in the build
job not the test
job. Two different jobs, meaning two different containers. They have nothing to do with each other.
Upvotes: 1