jest-github-action: 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/jest-github-action@v1.0.24s
}
Run mattallty/jest-github-action@v1.0.2
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/jest-github-action@v1.0.2
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
test-command: 'yarn test'
changes-only: true
- uses: mattallty/jest-github-action@v1.0.2
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
test-command: 'yarn test'
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 31
- Comments: 22
Commits related to this issue
- Attempt to address missing jest.results.json error See https://github.com/mattallty/jest-github-action/issues/8#issuecomment-713778234 — committed to precisely/app by aneilbaboo 4 years ago
- add custom outputFile https://github.com/mattallty/jest-github-action/issues/8 — committed to ufersa/plataforma-sabia by mateus4k 3 years ago
- Updating coverage comment to npx jest run tests as per issues comment. https://github.com/mattallty/jest-github-action/issues/8#issuecomment-818409054 — committed to Freddie-Pike/freddies_testing_playground by Freddie-Pike 3 years ago
I think I’ve tried every variant above and nothing worked, but this does:
yarn install
step is necessaryoutputFile
tldr; Your test script needs to look something like this:
If it looks like this:
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.
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.
@mattallty this would be good in the instructions, together with a bit more info on “If you use Vue enable use_vue_cli: true” 😄
I am also having this issue, I tried
yarn install
but that didn’t change anything. If I runnpx jest --coverage
it runs my tests fine but with this plugin I get the above error. Here is my action: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.what fixed it for me was making sure all my jest deps were installed with a
yarn install