-
-
Save ccpacillos/3778615ec84e3a494111a29430996829 to your computer and use it in GitHub Desktop.
Setting up Mocha Test Coverage and Parallelism In Circle CI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: true | |
check-coverage: false | |
clean: false | |
lines: 80 | |
statements: 80 | |
branches: 50 | |
functions: 50 | |
reporter: | |
- lcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2.1 | |
jobs: | |
checkout_source: | |
docker: | |
- image: circleci/node:14.15.1-stretch | |
steps: | |
- checkout | |
- persist_to_workspace: | |
root: . | |
paths: | |
- . | |
install_dependencies: | |
docker: | |
- image: circleci/node:14.15.1-stretch | |
steps: | |
- attach_workspace: | |
at: . | |
- restore_cache: | |
keys: | |
- dependencies-{{ checksum "package-lock.json" }} | |
- run: | |
name: Install dependencies | |
command: npm install | |
- save_cache: | |
key: dependencies-{{ checksum "package-lock.json" }} | |
paths: | |
- node_modules | |
- persist_to_workspace: | |
root: . | |
paths: | |
- node_modules/* | |
test: | |
docker: | |
- image: circleci/node:14.15.1-stretch | |
parallelism: 8 | |
steps: | |
- attach_workspace: | |
at: . | |
- run: | |
name: Run tests | |
command: | |
circleci tests glob 'test/**/*.spec.ts' | | |
circleci tests split | | |
xargs npx nyc --temp-dir=./.nyc_output_temp/$CIRCLE_JOB-$CIRCLE_NODE_INDEX/nyc_output mocha | |
- persist_to_workspace: | |
root: . | |
paths: | |
- .nyc_output_temp/* | |
test_coverage: | |
docker: | |
- image: circleci/node:14.15.1-stretch | |
steps: | |
- attach_workspace: | |
at: . | |
- run: | |
name: Merge coverage output | |
command: node merge-nyc-output.js | |
- run: | |
name: Check code coverage | |
command: npx nyc report --reporter=lcov --reporter=text-summary --check-coverage | |
workflows: | |
build_workflow: | |
jobs: | |
- checkout_source | |
- install_dependencies: | |
requires: | |
- checkout_source | |
- test: | |
requires: | |
- install_dependencies | |
- test_coverage: | |
requires: | |
- test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const { spawnSync } = require('child_process'); | |
const path = require('path'); | |
const glob = require('glob'); | |
const makeDir = require('make-dir'); | |
const rimraf = require('rimraf'); | |
process.chdir(__dirname); | |
rimraf.sync('.nyc_output'); | |
makeDir.sync('.nyc_output'); | |
// Merge coverage data from each executor. | |
glob.sync('.nyc_output_temp/*/nyc_output').forEach((nycOutput) => { | |
console.log(`Merging: ${nycOutput}`); | |
const cwd = path.dirname(nycOutput); | |
const { status, stderr } = spawnSync( | |
'npx nyc', | |
[ | |
'merge', | |
'nyc_output', | |
path.join(__dirname, '.nyc_output', path.basename(cwd) + '.json'), | |
], | |
{ | |
encoding: 'utf8', | |
shell: true, | |
cwd, | |
}, | |
); | |
if (status !== 0) { | |
process.exit(status); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, Thank you for your sharing.
I wanna ask something, how about the ci/cd for a mocha test when run after deployment from another repository? Thank you