diff --git a/.c8rc.json b/.c8rc.json new file mode 100644 index 0000000000..fde64f42b6 --- /dev/null +++ b/.c8rc.json @@ -0,0 +1,17 @@ +{ + "reporter": ["html", "text"], + "reportsDirectory": "./coverage", + "src": ["src"], + "exclude": [ + "std/**/*", + "tests/**/*", + "dist/**/*", + "bin/asinit.js", + "lib/**/*", + "scripts/**/*", + "src/glue/wasm/**/*", + "util/browser/**/*" + ], + "clean": true, + "exclude-after-remap": true +} diff --git a/.gitignore b/.gitignore index 98a3ba835b..3166d113d2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ raw/ .idea cli/index.generated.js src/diagnosticMessages.generated.ts +coverage/ diff --git a/package.json b/package.json index bc3bd45d64..6c93b22e33 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "lint": "eslint --max-warnings 0 --ext js . && eslint --max-warnings 0 --ext ts .", "build": "node scripts/build", "watch": "node scripts/build --watch", + "coverage": "npx c8 -- npm test", "test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform", "test:parser": "node --enable-source-maps tests/parser", "test:compiler": "node --enable-source-maps --no-warnings tests/compiler", diff --git a/tests/README.md b/tests/README.md index 3bbaef5656..0163048a04 100644 --- a/tests/README.md +++ b/tests/README.md @@ -116,6 +116,18 @@ Features Tests for experimental features (usually enabled via the `--enable` CLI flag) are disabled by default. To enable a feature, set the `ASC_FEATURES` environment variable to a comma-separated list of feature names (see [`features.json`](./features.json)). You can also set `ASC_FEATURES="*"` to enable all features. +Coverage +-------- + +An optional code coverage report can be generated by running + +``` +$> npm install c8 +$> npm run coverage +``` + +Code coverage runs the tests with [c8](https://github.com/bcoe/c8) using the JS variant of the compiler. It is expected that Wasm-only branches show as untaken. Make sure to enable all (relevant) [features](#features). A convenient HTML report is generated to `coverage/`. + Other ----- diff --git a/tests/compiler.js b/tests/compiler.js index 84cf0928f7..5280a3e47a 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -492,8 +492,9 @@ function evaluateResult(failedTests, skippedTests) { } } -// Run tests in parallel if requested -if (args.parallel && coreCount > 2) { +// Run tests in parallel if requested (except with coverage) +const isCoverage = process.env.NODE_V8_COVERAGE != null; +if (!isCoverage && args.parallel && coreCount > 2) { if (cluster.isWorker) { process.on("message", msg => { if (msg.cmd != "run") throw Error("invalid command: " + JSON.stringify(msg));