diff --git a/README.md b/README.md index 612a076b4..5a7315995 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,71 @@ This will generate `pdf.js` and `pdf.worker.js` in the `build/generic/build/` di Both scripts are needed but only `pdf.js` needs to be included since `pdf.worker.js` will be loaded by `pdf.js`. The PDF.js files are large and should be minified for production. +## Code coverage + +We track how much of the code is exercised by the test suite on +[Codecov](https://codecov.io/gh/mozilla/pdf.js) (see the badge at the top of this +file). + +### How it is collected + +When coverage is enabled, the build instruments the bundled code with +[`babel-plugin-istanbul`](https://github.com/istanbuljs/babel-plugin-istanbul), +which adds counters that record every line, branch and function that runs: + ++ For browser-based tests (unit, integration and reference tests) the + instrumented code runs in the browser, fills a global `window.__coverage__` + object, and the test runner collects it from each browser session, merges the + results, and writes the report. ++ For the Node-based unit tests (`unittestcli`) the raw data is written to + `build/tmp/unittestcli-coverage.json` and turned into a report afterwards. + +### Collecting coverage locally + +Add the `--coverage` flag to any of the test tasks, for example: + + $ npx gulp unittest --coverage # browser unit tests + $ npx gulp unittestcli --coverage # Node unit tests + $ npx gulp integrationtest --coverage # Puppeteer integration tests + $ npx gulp botbrowsertest --coverage # reference tests + +The following options control the output: + +| Option | Description | Default | +| --- | --- | --- | +| `--coverage` | Enable coverage collection. | off | +| `--coverage-output