diff --git a/README.md b/README.md index 7f3a2608..adbaa5ed 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,7 @@ Usage: test-storybook [options] | `--watch` | Watch files for changes and rerun tests related to changed files.<br/>`test-storybook --watch` | | `--watchAll` | Watch files for changes and rerun all tests when something changes.<br/>`test-storybook --watchAll` | | `--coverage` | Indicates that test coverage information should be collected and reported in the output <br/>`test-storybook --coverage` | +| `--coverageDirectory` | Directory where to write coverage report output <br/>`test-storybook --coverage --coverageDirectory coverage/ui/storybook` | | `--url` | Define the URL to run tests in. Useful for custom Storybook URLs <br/>`test-storybook --url http://the-storybook-url-here.com` | | `--browsers` | Define browsers to run tests in. One or multiple of: chromium, firefox, webkit <br/>`test-storybook --browsers firefox chromium` | | `--maxWorkers [amount]` | Specifies the maximum number of workers the worker-pool will spawn for running tests <br/>`test-storybook --maxWorkers=2` | diff --git a/src/test-storybook.ts b/src/test-storybook.ts index 43bd6e2f..f732f6c9 100644 --- a/src/test-storybook.ts +++ b/src/test-storybook.ts @@ -52,7 +52,10 @@ const cleanup = () => { 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)) { @@ -260,6 +263,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 fd0371ff..c27ebaa7 100644 --- a/src/util/getCliOptions.ts +++ b/src/util/getCliOptions.ts @@ -10,6 +10,7 @@ export type CliOptions = { configDir?: string; eject?: boolean; coverage?: boolean; + coverageDirectory?: string; junit?: boolean; browsers?: BrowserType | BrowserType[]; }; @@ -25,6 +26,7 @@ const STORYBOOK_RUNNER_COMMANDS: StorybookRunnerCommand[] = [ 'eject', 'url', 'coverage', + 'coverageDirectory', 'junit', ]; diff --git a/src/util/getParsedCliOptions.ts b/src/util/getParsedCliOptions.ts index 67d200ad..ddb0251d 100644 --- a/src/util/getParsedCliOptions.ts +++ b/src/util/getParsedCliOptions.ts @@ -58,6 +58,11 @@ export const getParsedCliOptions = (): ParsedCliOptions => { '--coverage', 'Indicates that test coverage information should be collected and reported in the output' ) + .option( + '--coverageDirectory <directory>', + 'Directory where to write coverage report output', + 'coverage/storybook' + ) .option('--junit', 'Indicates that test information should be reported in a junit file') .option( '--eject',