.circleci/config.yml
version: 2.1
orbs:
cypress: cypress-io/cypress@1.29.0
executors:
default:
docker:
- image: cypress/browsers:node18.12.0-chrome107 # keep in sync with .nvmrc and any other executors
environment:
CC_TEST_REPORTER_ID: 0f2bc6ef737019bfc8eda369cd06b66c54606b144b4d81cec010fb494d2559af
parameters:
workspace_root:
type: string
default: '~/'
primary_cache_key:
type: string
default: 'oc-ci-2-{{ .Branch }}-{{ checksum "yarn.lock" }}'
backup_cache_key:
type: string
default: 'oc-ci-2-{{ .Branch }}-'
org_level_cache_key:
type: string
default: 'oc-ci-2-'
aliases:
- &attach_workspace
attach_workspace:
at: << pipeline.parameters.workspace_root >>
- &restore_cache
restore_cache:
keys:
- << pipeline.parameters.primary_cache_key >>
# Fallback in case checksum fails.
- << pipeline.parameters.backup_cache_key >>
- << pipeline.parameters.org_level_cache_key >>
- &yarn_install
run:
name: 'Installing dependencies...'
command: yarn install --non-interactive --frozen-lockfile --cache_folder << pipeline.parameters.workspace_root >>.cache/yarn
jobs:
install_dependencies:
executor: default
steps:
- checkout
- *attach_workspace
- *restore_cache
- *yarn_install
- save_cache:
key: << pipeline.parameters.primary_cache_key >>
paths:
- node_modules
- << pipeline.parameters.workspace_root >>.cache/yarn
- << pipeline.parameters.workspace_root >>.cache/Cypress
- run: node --version
- run: yarn --version
unit_tests:
executor: default
steps:
- checkout
- *attach_workspace
- *restore_cache
- *yarn_install
- run:
name: Run tests
command: yarn test:ci
- persist_to_workspace:
root: << pipeline.parameters.workspace_root >>
paths:
- project/vitest-coverage
lint:
executor: default
steps:
- checkout
- *attach_workspace
- *restore_cache
- *yarn_install
- run:
name: Lint
command: |
yarn lint:ci
report_coverage:
executor: default
steps:
- checkout
- *attach_workspace
- *restore_cache
- *yarn_install
- run:
name: Initialize CodeClimate
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc_test_reporter
chmod +x ./cc_test_reporter
- run:
name: Merge reports into one file
command: |
mkdir reports
mkdir .nyc_output
ls -al cypress-coverage
cp cypress-coverage/coverage.node-*.json reports
cp vitest-coverage/coverage-final.json reports/from-vitest.json
yarn nyc merge reports
mv coverage.json .nyc_output/out.json
- run:
name: Convert finalized report from JSON to lcov
command: |
yarn nyc report --reporter lcov --report-dir coverage
- run:
name: Format report for Code Climate
command: |
./cc_test_reporter format-coverage -t lcov -o coverage/codeclimate.json coverage/lcov.info
- run:
name: Upload the report to CodeClimate
command: |
./cc_test_reporter upload-coverage --debug --input coverage/codeclimate.json
workflows:
default:
jobs:
- install_dependencies
- unit_tests:
requires:
- install_dependencies
- lint:
requires:
- install_dependencies
- cypress/run:
name: integration_tests
requires:
- install_dependencies
executor: default
pre-steps:
- checkout
- *attach_workspace
- *restore_cache
- *yarn_install
attach-workspace: true
browser: 'chrome' # actually use Chrome (and not Electron)
record: true # record results on Cypress Dashboard
parallel: true # split all specs across machines
parallelism: 3 # use X number of CircleCI machines
command-prefix: yarn # dont use npx
group: 'all tests' # name this group "all tests" on the dashboard
start: 'yarn dev' # start server before running tests
wait-on: http://localhost:3000 # wait until server is ready
post-steps:
- run:
name: Get each parallelized node's coverage report
command: cp cypress-coverage/coverage-final.json "cypress-coverage/coverage.node-$CIRCLE_NODE_INDEX.json"
- persist_to_workspace:
root: << pipeline.parameters.workspace_root >>
paths:
- project/cypress-coverage
- report_coverage:
requires:
- unit_tests
- integration_tests