Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Jest script to output coverage #44447

Merged
merged 3 commits into from
Sep 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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