Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: ENOENT: no such file or directory jest.results.json #8

Open
scurrilus-funke opened this issue May 27, 2020 · 22 comments
Open

Error: ENOENT: no such file or directory jest.results.json #8

scurrilus-funke opened this issue May 27, 2020 · 22 comments

Comments

@scurrilus-funke
Copy link

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'
@fahadshehzada
Copy link

I was getting same issue after following this link

@rajington
Copy link

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

@pagameba
Copy link

pagameba commented Jun 12, 2020

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.

@doochik
Copy link

doochik commented Jun 27, 2020

Same error for me

@wildone
Copy link

wildone commented Jul 4, 2020

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",`

@wildone
Copy link

wildone commented Jul 4, 2020

@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

@wildone
Copy link

wildone commented Jul 4, 2020

@mattallty need to be able to bypass const cmd = getJestCommand(RESULTS_FILE) and just allow processing of the jest.result.json.

@doochik
Copy link

doochik commented Jul 6, 2020

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"

@davidcalhoun
Copy link

davidcalhoun commented Sep 15, 2020

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'

@MarcBT
Copy link

MarcBT commented Oct 9, 2020

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 }}

@leeuwd
Copy link

leeuwd commented Oct 14, 2020

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]

@hollandjake
Copy link

hollandjake commented Oct 21, 2020

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"

mateus4k added a commit to ufersa/plataforma-sabia that referenced this issue Jan 5, 2021
@jcandrade
Copy link

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)
    ```

@BenceSiket
Copy link

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.

@jake-nz
Copy link

jake-nz commented Apr 13, 2021

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

@davidcalhoun
Copy link

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

@ppamorim
Copy link

ppamorim commented Jul 15, 2021

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

@hollandjake
Copy link

@ppamorim have you tried changing

run: npm run test:cov

to

run: yarn jest --json --outputFile="jest.results.json"

@ppamorim
Copy link

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

@ppamorim
Copy link

This was happening because my test was causing a OOM.

@jacksteamdev
Copy link

jacksteamdev commented Aug 4, 2021

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:

function getJestCommand(resultsFile: string) {
let cmd = core.getInput("test-command", { required: false })
const jestOptions = `--testLocationInResults --json ${
shouldCommentCoverage() ? "--coverage" : ""
} ${
shouldRunOnlyChangedFiles() && context.payload.pull_request?.base.ref
? "--changedSince=" + context.payload.pull_request?.base.ref
: ""
} --outputFile=${resultsFile}`
const shouldAddHyphen = cmd.startsWith("npm") || cmd.startsWith("npx") || cmd.startsWith("pnpm") || cmd.startsWith("pnpx")
cmd += (shouldAddHyphen ? " -- " : " ") + jestOptions
core.debug("Final test command: " + cmd)
return cmd
}

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.

@hamza-ghufran
Copy link

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests