Skip to content

Commit e85f008

Browse files
committed
Add code coverage reporting
https://artsyproduct.atlassian.net/browse/PLATFORM-1136 Problem: One part of the product health matrix story [spike][spike] is code coverage for each service. However, there is no pattern at Artsy for measuring code coverage for Javascript applications. While there are existing tools out there for tracking and reporting code coverage, such as [istanbul.js][istanbul-js], [coveralls][coveralls], and [codecov][codecov], the complexities: 1. A multi-runner test suite (jest and mocha), and 2. A Circle CI -> Docker -> Docker test runtime have resulted in a tough problem to solution around. Solution: After spending a lot of time trying to get Coveralls instrumentation to work, we pivoted to using Codecov. At a high level, this commit does the following: 1. Updates our calls to `jest` and `mocha` to write code coverage information to a `.nyc_output` directory (default for nyc/istanbul) 2. Manipulates the `jest` coverage information to be compatible with `mocha` coverage information via a JS script. See [motivating GH issue][gh-issue]. 3. Merges the `jest` and `mocha` coverage information together using the `nyc` CLI 4. Introduces a bash executable provided by codecov to instrument the merged information to codecov Co-authored-by: Kieran Gillen <[email protected]> [spike]:https://artsyproduct.atlassian.net/browse/PLATFORM-1098 [istanbul-js]:https://github.com/istanbuljs/nyc [coveralls]:https://coveralls.io/ [codecov]:https://codecov.io/gh/artsy/positron/ [gh-issue]:jestjs/jest#2418
1 parent 49e1145 commit e85f008

12 files changed

+1939
-11
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- setup_remote_docker
1010
- run:
1111
name: Test
12-
command: COMMIT_HASH=$(git rev-parse --short HEAD) hokusai test --build
12+
command: COMMIT_HASH=$(git rev-parse HEAD) CODECOV_TOKEN=$CODECOV_TOKEN hokusai test --build
1313
deploy-staging:
1414
docker:
1515
- image: artsy/hokusai

.env.test

+5
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ GEMINI_KEY=REPLACE
2323

2424
# Needed to link Reaction: `yarn link @artsy/reaction`
2525
GRAPHQL_ENDPOINT=https://metaphysics-staging.artsy.net
26+
27+
# Token used to authenticate with the code coverage tracking tool Codecov.
28+
# Token not needed when running tests during dev, intended to only be set
29+
# during CI.
30+
CODECOV_TOKEN

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ data
2121
/public
2222
/src/client/public/assets
2323
/node_modules
24+
25+
coverage.lcov
26+
.nyc_output/

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM node:10.13-alpine
22
ARG COMMIT_HASH
33
RUN test -n "$COMMIT_HASH"
44

5-
RUN apk add curl git nginx
5+
RUN apk add curl git nginx bash
66

77
# Set up deploy user and working directory
88
RUN adduser -D -g '' deploy

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[Positron](https://github.com/artsy/positron) is Artsy Writer or the editorial tool for Artsy.
44

5+
[![codecov](https://codecov.io/gh/artsy/positron/branch/master/graph/badge.svg)](https://codecov.io/gh/artsy/positron)
56
![ArtsyWriter](/doc/images/ArtsyWriter.png)
67

78
## Meta

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414
"prettier-project": "yarn run prettier-write 'src/**/*.{ts,tsx,js,jsx}'",
1515
"prettier-write": "yarn run prettier --write",
1616
"mocha": "sh scripts/mocha.sh",
17+
"jest": "sh scripts/jest.sh",
1718
"start": "sh scripts/start.sh",
1819
"production": "sh scripts/production.sh",
1920
"publish-assets": "sh scripts/publish-assets.sh",
2021
"task": "node -r coffeescript/register -r @babel/register -r dotenv/config",
2122
"test:watch": "yarn jest -- --watch --runInBand",
2223
"test": "sh scripts/test.sh",
23-
"type-check": "tsc --pretty --noEmit"
24+
"type-check": "tsc --pretty --noEmit",
25+
"normalize-jest-coverage": "node scripts/normalize-jest-coverage.js",
26+
"create-merged-coverage": "nyc report --reporter=text-lcov > coverage.lcov",
27+
"report-coverage": "./scripts/codecov -C $(cat COMMIT_HASH.txt) -p app/ -f coverage.lcov",
28+
"publish-coverage": "yarn normalize-jest-coverage && yarn create-merged-coverage && yarn report-coverage"
2429
},
2530
"resolutions": {
2631
"babel-core": "^7.0.0-0",
@@ -181,6 +186,8 @@
181186
"json-loader": "^0.5.7",
182187
"lint-staged": "^7.2.2",
183188
"mocha": "^3.1.2",
189+
"mocha-lcov-reporter": "^1.3.0",
190+
"nyc": "^13.1.0",
184191
"progress-bar-webpack-plugin": "^1.10.0",
185192
"raf": "^3.4.0",
186193
"react-addons-test-utils": "^15.4.2",

0 commit comments

Comments
 (0)