I have worked with github actions
before while setting up github-workflow
, but this is the first time I'm including action/job for npm test
.
I have configured it to run the actions on pull request to develop branch as usual... but the tests never finish running in the github action jobs. I've been googling but can't seem to find a relevant solution.
Github pull-request screenshot 1
Github pull-request screenshot 2
I'm using nodejs
and the test is written with jasmine
. I don't know if it has anything to do with my settings or test configuration which I set up myself, so I've also included some relevant code/files below just in case.
.github/workflows/node.js.yml
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
The node.js.yml
file above☝🏽is already in the develop branch
.
package.json
{
//scripts
"scripts": {
"prestart": "node -r esm src/startMessage.js",
"start": "npm-run-all --parallel lint:watch",
"lint": "esw src --color",
"lint:watch": "npm run lint -- --watch",
"test": "nodemon --exec babel-node spec/run.js"
},
//dependencies
"dependencies": {
"arg": "^5.0.0",
"chalk": "^4.1.0",
"esm": "^3.2.25",
"execa": "^5.0.0",
"inquirer": "^8.0.0",
"listr": "^0.14.3",
"ncp": "^2.0.0",
"npm-run-all": "^4.1.5",
"pkg-install": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"eslint": "^7.21.0",
"eslint-plugin-import": "^2.22.1",
"eslint-watch": "^7.0.0"
"eslint-watch": "^7.0.0",
"jasmine": "^3.6.4",
"nodemon": "^2.0.7"
}
}
src/cli.js
export let cli = (args) => {
console.log(args);
}
spec/cli.spec.js
import { cli as cli } from '../src/cli';
describe('cli function', () => {
it('should return undefined', () => {
let test = cli();
expect(test).toBeUndefined();
});
});
spec/run.js
import Jasmine from 'jasmine';
const jasmine = new Jasmine();
jasmine.loadConfigFile('spec/support/jasmine.json');
jasmine.execute();
spec/support/jasmine.json
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}
.babelrc
{
"presets": [
"env"
]
}
The test works fine locally when I run npm test
in my terminal. I need help with the github action/workflow on push or pull request (so that I can merge the feature branch which contains the test into the development branch):
What is making the test run non-stop in the GitHub action?
How can I get the github action checks to pass and run successfully?
While I've not had the chance to look at your GitHub repo, from what you've posted here, one solution I'll propose is to:
nodemon --exec babel-node spec/run.js
in your package.json configurationbabel-node spec/run.js
.This will ensure that the tests will be run only once when a change is pushed. SO, when working locally, you can use npm run dev-test
to keep the test on for the entire period you are making changes locally.