I used create-react-app
to bootstrap a new project and left it as it is by default.
Added GitHub actions config for node.js:
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '10.x'
- run: npm ci
- run: npm test
The code never passes the npm test
step.
What am I doing wrong?
It seems that when you execute the command npm test , you should explicitly set the environment variable CI , no matter its value is true or false.
You can try the below 2 methods to set this environment variable:
-
Set CI directly in the command line, for example on Linux, macOS (Bash).
CI=true npm test
-
Define CI as an environment variable in the workflow.
env:
CI: true
We can define it on workflow level, job level or step level, so that it can be available for different scopes.
4 Likes
Do you need both? CI=true npm test works but just setting the env var hangs when you add another command after the npm test
- run: npm test
- run: echo hangs in the line above even though the env var is set
env:
CI: true
- run: CI=true npm test
- run: echo works and pipeline continues
env:
CI: true
When just using env and I run -run: env I don’t see the CI var
1 Like
when my workflow runs i have everything setup as you said but though it takes forever to run test
on local it works fine but on github it takes forever
For anybody still reading this.
I faced the same issue, found that I had --watch
flag added to jest
in the test
script.
The test won’t end in that case. Removed and everything is fine.
3 Likes
[If you are still reading this article]
I have faced the same issue with angular “ng test” and followed below steps:
- set “singleRun: true” in karma.conf.js
- update the ng test in package.json to “ng test --browsers=ChromeHeadless”
- Changed the action workflow to [apt statement is for ubuntu, you can use the equivalent install statement for other platforms as well ]
- run: sudo apt install chromium-browser
- name: Install dependencies
run: npm ci
- name: NPM Test
run: |
export CHROME_BIN=/usr/bin/chromium-browser
CI=true npm run test-headless
env:
CI: true
Problem was related to the missing chromium package on ubuntu runner. After installing the chromium and exporting the environment variable, test has started running.
Run sudo apt install chromium-browser
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Reading package lists…
Building dependency tree…
Reading state information…
E: Unable to locate package chromium-browser
Error: Process completed with exit code 100.
cannot find chromium could you please help ?