UNPKG

2.12 kBJavaScriptView Raw
1import path from 'path';
2/**
3 * Verifies that coverage is reported for all files and, if not, will return an error message
4 * @param results The jest test run result
5 * @param fileNamesWithMutantCoverage the file names for which coverage was reported
6 */
7export 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}
18const MAX_FILES_IN_HINT = 3;
19function 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
30You probably configured a test environment in jest that is not reporting code coverage to Stryker.
31See also https://jestjs.io/docs/en/configuration.html#testenvironment-string
32
33Are 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
38If you're using your own custom test environment, please enrich the environment with this mixin:
39
40const { mixinJestEnvironment} = require('@stryker-mutator/jest-runner');
41module.exports = mixinJestEnvironment(MyCustomTestEnvironment);
42
43For more info, see https://stryker-mutator.io/docs/stryker-js/jest-runner#coverage-analysis`;
44}
45//# sourceMappingURL=verify-all-test-files-have-coverage.js.map
\No newline at end of file