reactjs 如何使用Github操作运行jest单元测试

jbose2ul  于 2022-12-03  发布在  React
关注(0)|答案(1)|浏览(158)

继续运行工作流时,我不断收到以下错误:

Run npm test
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/runner/work/armoire/armoire/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/runner/work/armoire/armoire/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2022-11-12T17_08_44_277Z-debug.log
Error: Process completed with exit code 254.

yaml工作流程为:

name: frontendTesting
run-name: ${{ github.actor }} is testing her frontend
on: [push]
jobs:
  check-bats-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '14'
      - run: npm install -g bats
      - run: bats -v
  run-unit-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '14'
      - run: cd frontend
      - run: npm install
      - run: npm test

我认为这个错误是因为我没有一个package.json,而.github/workflows是.我有两个文件夹:frontend和backend。它们各自的package.json文件都在那些文件夹里。我该怎么解决这个问题呢?提前谢谢!

xxhby3vn

xxhby3vn1#

修复非常简单,只需重定向到package.json使用“工作目录”的位置-例如:

name: frontendTesting
run-name: ${{ github.actor }} is testing her frontend
on: [push]
jobs:
  run-defined-frontend-tests:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./frontend
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '14'
      - run: npm ci
      - run: npm run test

相关问题