From b9ed7dfaaf3521028e7523d617c54271d5f891ab Mon Sep 17 00:00:00 2001 From: Clint Andrew Hall Date: Thu, 29 Aug 2019 20:02:19 -0400 Subject: [PATCH 1/2] Update Jest script to output coverage --- x-pack/legacy/plugins/canvas/scripts/jest.js | 41 +++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/x-pack/legacy/plugins/canvas/scripts/jest.js b/x-pack/legacy/plugins/canvas/scripts/jest.js index 0aea9fdda9c77..e6d5af49e8dc4 100644 --- a/x-pack/legacy/plugins/canvas/scripts/jest.js +++ b/x-pack/legacy/plugins/canvas/scripts/jest.js @@ -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'; @@ -36,13 +60,9 @@ 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); + console.log(path, options); runXPackScript('jest', [path].concat(options)); }, { @@ -50,13 +70,14 @@ run( 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 Runs any tests at a given path. + --coverage Collect coverage statistics. `, }, } From 586b191c310c7a1a8407f55e5bacacfd886d7373 Mon Sep 17 00:00:00 2001 From: Clint Andrew Hall Date: Thu, 29 Aug 2019 20:05:16 -0400 Subject: [PATCH 2/2] kill console.log --- x-pack/legacy/plugins/canvas/scripts/jest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/canvas/scripts/jest.js b/x-pack/legacy/plugins/canvas/scripts/jest.js index e6d5af49e8dc4..12a2b9921455b 100644 --- a/x-pack/legacy/plugins/canvas/scripts/jest.js +++ b/x-pack/legacy/plugins/canvas/scripts/jest.js @@ -62,7 +62,7 @@ run( log.info('Running tests. This does not include Storybook Snapshots...'); } } - console.log(path, options); + runXPackScript('jest', [path].concat(options)); }, {