通过CircleCI中的Cypress代码覆盖插件运行时,nyc报告失败,并带有ENOENT

问题描述 投票:1回答:1

我正在使用Cypress的code-coverageinstrument-cra插件。当在我自己的计算机上本地运行时,这很好用,但是通过CircleCI运行时,我得到:

CypressError: cy.task('coverageReport') failed with the following error:
> Error: Command failed with ENOENT: nyc report --report-dir ./coverage --temp-dir /root/app/.nyc_output --reporter=lcov --reporter=clover --reporter=json
spawn nyc ENOENT

尚不清楚它抱怨哪个文件。我已验证/root/app/.nyc_output存在并且包含coverage数据。

我已经在赛普拉斯中启用了调试日志记录并得到:

code-coverage parsed sent coverage +0ms
code-coverage created folder /root/app/.nyc_output for output coverage +1ms
code-coverage wrote coverage file /root/app/.nyc_output/out.json +17ms
cypress:server:plugins:child execute plugin event: task ({ eventId: 2, invocationId: 'inv11' }) +100ms
code-coverage saving coverage report using command: "nyc report --report-dir ./coverage --temp-dir /root/app/.nyc_output --reporter=lcov --reporter=clover --reporter=json" +68ms
code-coverage current working directory is /root/app +0ms

完整版本可在https://circleci.com/gh/magjac/graphviz-visual-editor/114获得

我已按照this guide进行设置。

这是我的CircleCI config.yaml(有很多可怕的调试和解决方法:

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  integration-test:
    docker:
      - image: cypress/base:8
        environment:
          ## this enables colors in the output
          TERM: xterm
    working_directory: ~/app
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-deps-{{ .Branch }}-{{ checksum "package.json" }}
            - v1-deps-{{ .Branch }}
            - v1-deps
      - run:
          name: Install Dependencies
          no_output_timeout: 30m
          command: npm ci

      - save_cache:
          key: v1-deps-{{ .Branch }}-{{ checksum "package.json" }}
          # cache NPM modules and the folder with the Cypress binary
          paths:
            - ~/.npm
            - ~/.cache
      - run: ls -la
      - run: ls -la ./node_modules/.bin
      - run: ls -la .nyc_output/out.json || true
      - run: mkdir -p ./coverage
      - run: ls -la -R coverage || true
      - run: make
# This is the line that fails, but we ignore it and let the workaround below do its job
      - run: npm run start:coverage & $(npm bin)/wait-on http://localhost:3000/ && env CYPRESS_DEBUG="code-coverage" DEBUG="code-coverage" $(npm bin)/cypress run --record --key a12725d3-851c-4e67-b432-079b4fb1a875 --spec cypress/integration/rendering.spec.js || true
      - run: find . -name coverage || true
      - run: ls -la -R coverage || true
      - run: ls -la
      - run: ls -la .nyc_output/out.json || true
# Workaround: Run nyc report stand-alone
      - run: ./node_modules/.bin/nyc report --report-dir ./coverage --temp-dir /root/app/.nyc_output --reporter=lcov --reporter=clover --reporter=json
      - run: find . -name .nyc_output || true
      - run: find . -name coverage || true
      - run: ls -la .nyc_output/out.json || true
      - run: ls -la -R coverage || true
      - run: yarn run codecov
workflows:
  version: 2
  build-and-integration-test:
    jobs:
      - integration-test

EDIT:找不到nyc命令。在赛普拉斯调用之前添加`env PATH =“ $ PATH:./ node_modules / .bin”可解决该问题。我真的必须使用此方法还是有更好的方法?

EDIT 2:更好的解决方法是使用npx cypress run,它会自动将路径设置为node_modules / .bin。也许这是真正的解决方案?

code-coverage cypress circleci nyc
1个回答
1
投票
,用$(npm bin)/cypress run替换npx cypress run

我无法确定这实际上是正确的解决方案,还是某种解决方法。

© www.soinside.com 2019 - 2024. All rights reserved.