From ad0a50c6773d533093a89e688f36bc37ac877479 Mon Sep 17 00:00:00 2001 From: Ferdinand Hummel Date: Tue, 28 Feb 2023 13:05:46 +0700 Subject: [PATCH] Add coverage directory option --- README.md | 1 + bin/test-storybook.js | 9 ++++++++- src/util/getCliOptions.ts | 2 ++ src/util/getParsedCliOptions.ts | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5721b742..9e1b7269 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ Usage: test-storybook [options] | `--watch` | Watch files for changes and rerun tests related to changed files.
`test-storybook --watch` | | `--watchAll` | Watch files for changes and rerun all tests when something changes.
`test-storybook --watchAll` | | `--coverage` | Indicates that test coverage information should be collected and reported in the output
`test-storybook --coverage` | +| `--coverageDirectory` | Directory where to write coverage report output
`test-storybook --coverage --coverageDirectory coverage/ui/storybook` | | `--url` | Define the URL to run tests in. Useful for custom Storybook URLs
`test-storybook --url http://the-storybook-url-here.com` | | `--browsers` | Define browsers to run tests in. One or multiple of: chromium, firefox, webkit
`test-storybook --browsers firefox chromium` | | `--maxWorkers [amount]` | Specifies the maximum number of workers the worker-pool will spawn for running tests
`test-storybook --maxWorkers=2` | diff --git a/bin/test-storybook.js b/bin/test-storybook.js index 150e1038..b8c5987f 100755 --- a/bin/test-storybook.js +++ b/bin/test-storybook.js @@ -59,7 +59,10 @@ async function reportCoverage() { } const coverageFolderE2E = path.resolve(process.cwd(), '.nyc_output'); - const coverageFolder = path.resolve(process.cwd(), 'coverage/storybook'); + const coverageFolder = path.resolve( + process.cwd(), + process.env.STORYBOOK_COVERAGE_DIRECTORY ?? 'coverage/storybook' + ); // in case something goes wrong and .nyc_output does not exist, bail if (!fs.existsSync(coverageFolderE2E)) { @@ -250,6 +253,10 @@ const main = async () => { process.env.STORYBOOK_COLLECT_COVERAGE = 'true'; } + if (runnerOptions.coverageDirectory) { + process.env.STORYBOOK_COVERAGE_DIRECTORY = runnerOptions.coverageDirectory; + } + if (runnerOptions.junit) { process.env.STORYBOOK_JUNIT = 'true'; } diff --git a/src/util/getCliOptions.ts b/src/util/getCliOptions.ts index cdd62e6e..fcf613c5 100644 --- a/src/util/getCliOptions.ts +++ b/src/util/getCliOptions.ts @@ -8,6 +8,7 @@ type CliOptions = { configDir?: string; eject?: boolean; coverage?: boolean; + coverageDirectory?: string; junit?: boolean; browsers?: BrowserType | BrowserType[]; }; @@ -23,6 +24,7 @@ const STORYBOOK_RUNNER_COMMANDS: StorybookRunnerCommand[] = [ 'eject', 'url', 'coverage', + 'coverageDirectory', 'junit', ]; diff --git a/src/util/getParsedCliOptions.ts b/src/util/getParsedCliOptions.ts index 6f3ec54f..5182ef76 100644 --- a/src/util/getParsedCliOptions.ts +++ b/src/util/getParsedCliOptions.ts @@ -52,6 +52,11 @@ export const getParsedCliOptions = () => { '--coverage', 'Indicates that test coverage information should be collected and reported in the output' ) + .option( + '--coverageDirectory ', + 'Directory where to write coverage report output', + 'coverage/storybook' + ) .option('--junit', 'Indicates that test information should be reported in a junit file') .option( '--eject',