Skip to content

Commit

Permalink
Add coverage directory option
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdinandhummel-gph committed Feb 28, 2023
1 parent 917a94d commit ad0a50c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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` |
Expand Down
9 changes: 8 additions & 1 deletion bin/test-storybook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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';
}
Expand Down
2 changes: 2 additions & 0 deletions src/util/getCliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type CliOptions = {
configDir?: string;
eject?: boolean;
coverage?: boolean;
coverageDirectory?: string;
junit?: boolean;
browsers?: BrowserType | BrowserType[];
};
Expand All @@ -23,6 +24,7 @@ const STORYBOOK_RUNNER_COMMANDS: StorybookRunnerCommand[] = [
'eject',
'url',
'coverage',
'coverageDirectory',
'junit',
];

Expand Down
5 changes: 5 additions & 0 deletions src/util/getParsedCliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export const getParsedCliOptions = () => {
'--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',
Expand Down

0 comments on commit ad0a50c

Please sign in to comment.