Skip to content

Commit 632056a

Browse files
committed
Setup nyc to produce code coverage reports
This extends the public TypeScript configuration and sets it to check just our source files. The `all` setting must be `false` otherwise the tool crashes with an OOM because the test runner launches VS Code instances. The `.vscode-test` folder must be excluded or `nyc` will attempt to instrument Code's own sources. The `out` and `src` folders must both be included so that the TypeScript source mapping works (along with the `require` settings in the configuration and in Mocha). The coverage check is set to false because we'll enable failures for reduced coverage later. The Cobertura report is for Azure DevOps (cobertura) and a summary is printed to the console.
1 parent 4c8989d commit 632056a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,28 @@
8484
"lint": "tslint --project tsconfig.json",
8585
"build": "tsc --project tsconfig.json && esbuild ./src/main.ts --outdir=out --sourcemap --bundle --minify --external:vscode --platform=node",
8686
"test": "node ./out/test/runTests.js",
87+
"coverage": "nyc node ./out/test/runTests.js",
8788
"package": "vsce package --no-gitHubIssueLinking",
8889
"publish": "vsce publish"
8990
},
91+
"nyc": {
92+
"extends": "@istanbuljs/nyc-config-typescript",
93+
"all": false,
94+
"require": ["source-map-support/register"],
95+
"check-coverage": false,
96+
"use-spawn-wrap": false,
97+
"include": [
98+
"out/**/*.js",
99+
"src/**/*.ts"
100+
],
101+
"exclude": [
102+
".vscode-test/**"
103+
],
104+
"reporter": [
105+
"cobertura",
106+
"text"
107+
]
108+
},
90109
"contributes": {
91110
"breakpoints": [
92111
{

test/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export function run(): Promise<void> {
1313
const mocha = new Mocha({
1414
color: !process.env.TF_BUILD, // colored output from test results
1515
reporter: "mocha-multi-reporters",
16+
// These are used so that `nyc` can do source mapping.
17+
require: ["ts-node/register", "source-map-support/register"],
1618
timeout: 30000, // 30s because PowerShell startup is slow!
1719
reporterOptions: {
1820
// NOTE: The XML output by Mocha's xUnit reporter is actually in the

0 commit comments

Comments
 (0)