jest-github-action
jest-github-action copied to clipboard
Error: ENOENT: no such file or directory jest.results.json
Hello @mattallty, I tried to use the Jest github-action as it is in the instructions. However, I get the following error every time. Can you please tell me what's going wrong here?
Best Peter
Run mattallty/[email protected]
}
Run mattallty/[email protected]
Jest execution failed. Tests have likely failed.
Error: ENOENT: no such file or directory, open '/home/runner/work/_actions/mattallty/jest-github-action/v1.0.2/dist/jest.results.json'
at Object.openSync (fs.js:440:3)
##[error]ENOENT: no such file or directory, open '/home/runner/work/_actions/mattallty/jest-github-action/v1.0.2/dist/jest.results.json'
at Object.readFileSync (fs.js:342:35)
at parseResults (/home/runner/work/_actions/mattallty/jest-github-action/v1.0.2/dist/index.js:1:24547)
at Object.<anonymous> (/home/runner/work/_actions/mattallty/jest-github-action/v1.0.2/dist/index.js:1:21809)
at Generator.next (<anonymous>)
at fulfilled (/home/runner/work/_actions/mattallty/jest-github-action/v1.0.2/dist/index.js:1:20705)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/home/runner/work/_actions/mattallty/jest-github-action/v1.0.2/dist/jest.results.json'
}
My Github action in general is configured like this:
name: Jest Annotations & Coverage (Tests)
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
jest-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14.x'
- run: yarn install
- uses: mattallty/[email protected]
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
test-command: 'yarn test'
changes-only: true
- uses: mattallty/[email protected]
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
test-command: 'yarn test'
I was getting same issue after following this link
what fixed it for me was making sure all my jest deps were installed with a yarn install
I am also having this issue, I tried yarn install
but that didn't change anything. If I run npx jest --coverage
it runs my tests fine but with this plugin I get the above error. Here is my action:
name: Test Coverage Before Merge
on:
pull_request:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- run: yarn install
- run: pwd
- run: npx jest --coverage
- uses: mattallty/jest-github-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
test-command: "npx jest --coverage"
The pwd looks fine and the coverage is also fine. It feels like the plugin is executing in the context of the plugin instead of the project directory.
Is there a setting that's missing in the action?
Also, what is the required jest configuration because jest does not output jest.results.json
as far as I can tell.
Same error for me
to fix this add --coverage --json --outputFile=jest.results.json
to your unit test command, my usage
"test:unit":` "vue-cli-service test:unit --coverage --json --outputFile=jest.results.json",`
@mattallty this would be good in the instructions, together with a bit more info on "If you use Vue enable use_vue_cli: true" :D
@mattallty need to be able to bypass const cmd = getJestCommand(RESULTS_FILE)
and just allow processing of the jest.result.json.
Still have the same error. My Action
- name: Run tests
uses: mattallty/jest-github-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
test-command: "npx jest --ci --maxWorkers=3 --coverage --json --outputFile=jest.results.json"
I have tried using test-command
as well as working_directory
and I still get this error - this is a blocker for me unfortunately.
##[warning]Unexpected input(s) 'working_directory', valid inputs are ['test-command', 'coverage-comment', 'changes-only']
Run mattallty/jest-github-action@v1
Jest command executed
Error: ENOENT: no such file or directory, open '/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/jest.results.json'
at Object.openSync (fs.js:440:3)
at Object.readFileSync (fs.js:342:35)
at parseResults (/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/index.js:1:24547)
at Object.<anonymous> (/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/index.js:1:21809)
at Generator.next (<anonymous>)
at fulfilled (/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/index.js:1:20705)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/jest.results.json'
}
##[error]ENOENT: no such file or directory, open '/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/jest.results.json'
Happens with this step (in a monorepo):
- name: Coverage reporter with code annotations (for Github UI).
uses: mattallty/jest-github-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
working_directory: 'packages/app'
And also this step (tweaked slightly - this is running in a Lerna monorepo):
- name: Coverage reporter with code annotations (for Github UI).
uses: mattallty/jest-github-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
test-command: 'jest src --coverage --json --testLocationInResults --outputFile=jest.results.json'
what fixed it for me was making sure all my jest deps were installed with a
yarn install
I confirm that this solved the Error: ENOENT: no such file or directory jest.results.json
issue on my side as well.
- run: yarn install
- name: Jest Annotations & Coverage
uses: mattallty/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Same for us. Forcing a yarn install
beforehand (i.e. skip module cache from Github Actions) doesn't work either.
~/D/frontend [feature/google-actions-firebase]× » yarn list --depth=0 --pattern=jest 09:33:26
yarn list v1.22.10
warning ../../package.json: No license field
├─ @angular-builders/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @jest/[email protected]
├─ @types/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
Same for me, however this seems to fix it:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn
- name: Run tests
run: yarn jest --json --outputFile="jest.results.json"
- name: Add Coverage Comment
uses: mattallty/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
changes-only: true
test-command: "yarn jest"
Same here. I was able to workaround by running the tests before this action, like hollandjake did. However, I updated the test command to be only a test-command: ls
and here's what I got:
Jest execution failed. Tests have likely failed. Error: The process '/bin/ls' failed with exit code 2
at ExecState._setResult (/home/runner/work/_actions/mattallty/jest-github-action/v1.0.3/dist/index.js:1:15037)
at ExecState.CheckComplete (/home/runner/work/_actions/mattallty/jest-github-action/v1.0.3/dist/index.js:1:14599)
at ChildProcess.<anonymous> (/home/runner/work/_actions/mattallty/jest-github-action/v1.0.3/dist/index.js:1:13563)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Socket.<anonymous> (internal/child_process.js:430:11)
at Socket.emit (events.js:210:5)
at Pipe.<anonymous> (net.js:659:12)
```
Same here. It seems it cannot start any process. (There was an error when attempting to execute the process '/usr/bin/yarn') This is why the result json file is not created.
I think I've tried every variant above and nothing worked, but this does:
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: yarn install
- name: Run Tests
run: yarn jest --coverage --json --outputFile=/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/jest.results.json
- uses: mattallty/jest-github-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
test-command: 'echo done'
- The
yarn install
step is necessary - I had to use an absolute path for
outputFile
@jake-nz Woo! Thank you, that worked for me! Initially I ran into #9 but was able to work around it by triggering on pull_request
instead of push
, that did the trick and it left a comment! Sweet!
@jake-nz @davidcalhoun @hollandjake I am getting the same error even with these fixes examples. have a look of my workflow:
name: Tests
on:
pull_request:
branches:
- master
- development
jobs:
build:
runs-on: ubuntu-latest
container: node:14.17.1-alpine3.12
steps:
- name: Code checkout
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.npm
**/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-tests
restore-keys: |
${{ runner.os }}-node-tests
- name: Install dependencies
run: npm install
- name: Run lint
run: npm run lint
- name: Run test
run: npm run test:cov
- name: Run test
uses: mattallty/jest-github-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
coverage-comment: false
test-command: 'echo done'
@ppamorim have you tried changing
run: npm run test:cov
to
run: yarn jest --json --outputFile="jest.results.json"
@hollandjake test:cov
is a script: "test:cov": "jest --runInBand --forceExit --coverage --json --outputFile=/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/jest.results.json"
This was happening because my test was causing a OOM.
tldr; Your test script needs to look something like this:
{
"scripts": {
"test:ci": "jest --runInBand"
}
}
If it looks like this:
{
"scripts": {
"test:ci": "run-s lint test:coverage",
"test:coverage": "jest --runInBand"
}
}
It won't work. You can run stuff like linting in another action step.
I got this working finally for myself. This is a totally MISLEADING error!
The ENOENT error is a result of the test command failing. Unless your test script is able to accept extra Jest options (with a double dash in npm, none in yarn, ofc) like below, it will fail silently.
npm run test:ci -- --testLocationInResults --json --coverage --outputFile="jest.results.json"
Here's where the action script constructs a command like the one above: https://github.com/mattallty/jest-github-action/blob/12c8c9a48ae4543fdcf5faa4d126e922d69783a8/src/action.ts#L150-L163
NPM will throw, but the action runner will continue and try to read the results file. The clue is that the action fails instantly. The tests don't have time to run, so something else must be happening.
The following configuration worked for me:
in package.json.
"scripts": {
"test": "set NODE_ENV=test && jest --detectOpenHandles --coverage --json --outputFile='/home/runner/work/_actions/mattallty/jest-github-action/v1/dist/jest.results.json'",
}
in workflow:
- run: npm install
- run: gulp test
- uses: mattallty/jest-github-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
test-command: 'echo done'