1 | import path from 'path';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | export function verifyAllTestFilesHaveCoverage(results, fileNamesWithMutantCoverage) {
|
8 | const allTestFiles = new Set(results.testResults.map(({ testFilePath }) => path.resolve(testFilePath)));
|
9 | const fullFileNamesWithCoverage = [...fileNamesWithMutantCoverage].map((fileName) => path.resolve(fileName));
|
10 | const missing = [...allTestFiles].filter((testFile) => !fullFileNamesWithCoverage.includes(testFile));
|
11 | if (missing.length > 0) {
|
12 | return formatError(missing);
|
13 | }
|
14 | else {
|
15 | return;
|
16 | }
|
17 | }
|
18 | const MAX_FILES_IN_HINT = 3;
|
19 | function formatError(coverageMissingFromFiles) {
|
20 | let fileHints = coverageMissingFromFiles
|
21 | .slice(0, MAX_FILES_IN_HINT)
|
22 | .map((fullName) => ` * ${path.relative(process.cwd(), fullName)}`)
|
23 | .join('\n');
|
24 | if (coverageMissingFromFiles.length > MAX_FILES_IN_HINT) {
|
25 | fileHints += `\n (and ${coverageMissingFromFiles.length - MAX_FILES_IN_HINT} more)`;
|
26 | }
|
27 | return `\nMissing coverage results for:
|
28 | ${fileHints}
|
29 |
|
30 | You probably configured a test environment in jest that is not reporting code coverage to Stryker.
|
31 | See also https://jestjs.io/docs/en/configuration.html#testenvironment-string
|
32 |
|
33 | Are you using node, jsdom or jsdom-sixteen as a test environment? Please change that:
|
34 | * node -> @stryker-mutator/jest-runner/jest-env/node
|
35 | * jsdom -> @stryker-mutator/jest-runner/jest-env/jsdom
|
36 | * jest-environment-jsdom-sixteen -> @stryker-mutator/jest-runner/jest-env/jsdom-sixteen
|
37 |
|
38 | If you're using your own custom test environment, please enrich the environment with this mixin:
|
39 |
|
40 | const { mixinJestEnvironment} = require('@stryker-mutator/jest-runner');
|
41 | module.exports = mixinJestEnvironment(MyCustomTestEnvironment);
|
42 |
|
43 | For more info, see https://stryker-mutator.io/docs/stryker-js/jest-runner#coverage-analysis`;
|
44 | }
|
45 |
|
\ | No newline at end of file |