CircleCI-Public / node-orb

An orb for working with Node.js on CircleCI
https://circleci.com/orbs/registry/orb/circleci/node
MIT License
52 stars 80 forks source link

`node/test`: Add support to store code coverage #162

Closed ValorMorgan closed 1 month ago

ValorMorgan commented 2 years ago

Describe Request:

Update node/test to add support for exporting the coverage results of ran tests. Currently tests can have their results stored via store_test_results which exposes the pass/fail statuses to CircleCI. But the coverage is lost and a second testing operation has to happen to generate the coverage. This means the tests must be ran twice: 1) to get the pass/fail via node/test, 2) to get coverage via something like yarn jest --coverage with store_artifacts.

Examples:

Current

version: 2.1

orbs:
  node: circleci/node@X.Y.Z

jobs:
  collect_covearge:
    executor: node/default
    steps:
      - checkout
      - run: yarn install --frozen-lockfile
      - run: yarn jest --coverage
      - store_artifacts:
          path: coverage

workflows:
  main:
    jobs:
      - node/install-packages:
          pkg-manager: yarn
      - node/test:
          requires:
            - node/install-packages
          pkg-manager: yarn
          test-results-for: jest
      - collect_coverage:
          requires:
            - node/test

Future

version: 2.1

orbs:
  node: circleci/node@X.Y.Z

workflows:
  main:
    jobs:
      - node/install-packages:
          pkg-manager: yarn
      - node/test:
          requires:
            - node/install-packages
          pkg-manager: yarn
          test-results-for: jest
+         store-coverage: true

Supporting Documentation Links:

Coverage guide: https://circleci.com/docs/code-coverage#javascript store_test_results docs: https://circleci.com/docs/configuration-reference#storetestresults

marboledacci commented 1 month ago

I think the PR #207 added this. The feature is available since version 6.0.0