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

Most upvoted comments

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

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.

@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 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.

what fixed it for me was making sure all my jest deps were installed with a yarn install