Skip to content

Commit

Permalink
Update Jest script to output coverage (#44447)
Browse files Browse the repository at this point in the history
* Update Jest script to output coverage

* kill console.log
  • Loading branch information
clintandrewhall authored Sep 5, 2019
1 parent 16eb033 commit a965a77
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions x-pack/legacy/plugins/canvas/scripts/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,43 @@ const { runXPackScript } = require('./_helpers');
// we're making this script allow
run(
({ log, flags }) => {
const { all, storybook, update } = flags;
const { all, storybook, update, coverage } = flags;
let { path } = flags;
let options = [];
process.argv.splice(2, process.argv.length - 2);

if (path) {
log.info(`Limiting tests to ${path}...`);
path = 'legacy/plugins/canvas/' + path;
} else {
path = 'legacy/plugins/canvas';
}

if (!path) {
if (coverage) {
log.info(`Collecting test coverage and writing to canvas/coverage...`);
options = [
'--coverage',
'--collectCoverageFrom', // Ignore TS definition files
`!${path}/**/*.d.ts`,
'--collectCoverageFrom', // Ignore build directories
`!${path}/**/build/**`,
'--collectCoverageFrom', // Ignore coverage on test files
`!${path}/**/__tests__/**/*`,
'--collectCoverageFrom', // Include JS files
`${path}/**/*.js`,
'--collectCoverageFrom', // Include TS/X files
`${path}/**/*.ts*`,
'--coverageDirectory', // Output to canvas/coverage
'legacy/plugins/canvas/coverage',
];
} else {
// Mitigation for https://github.com/facebook/jest/issues/7267
if (all || storybook || update) {
options = ['--no-cache', '--no-watchman'];
options = options.concat(['--no-cache', '--no-watchman']);
}

if (all) {
log.info('Running all available tests. This will take a while...');
path = 'legacy/plugins/canvas';
} else if (storybook || update) {
path = 'legacy/plugins/canvas/.storybook';

Expand All @@ -36,27 +60,24 @@ run(
}
} else {
log.info('Running tests. This does not include Storybook Snapshots...');
path = 'legacy/plugins/canvas';
}
} else {
log.info(`Running tests found at ${path}...`);
}

process.argv.splice(2, process.argv.length - 2);
runXPackScript('jest', [path].concat(options));
},
{
description: `
Jest test runner for Canvas. By default, will not include Storybook Snapshots.
`,
flags: {
boolean: ['all', 'storybook', 'update'],
boolean: ['all', 'storybook', 'update', 'coverage'],
string: ['path'],
help: `
--all Runs all tests and snapshots. Slower.
--storybook Runs Storybook Snapshot tests only.
--update Updates Storybook Snapshot tests.
--path <string> Runs any tests at a given path.
--coverage Collect coverage statistics.
`,
},
}
Expand Down

0 comments on commit a965a77

Please sign in to comment.