Skip to content

Commit

Permalink
Merge pull request #272 from ferdinandhummel-gph/feature-coverage-dir…
Browse files Browse the repository at this point in the history
…ectory

Add coverage directory option
  • Loading branch information
yannbf committed Aug 4, 2023
2 parents 6dc3a4e + 2b4ffdb commit 817388f
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 @@ -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` |
Expand Down
9 changes: 8 additions & 1 deletion src/test-storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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';
}
Expand Down
2 changes: 2 additions & 0 deletions src/util/getCliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type CliOptions = {
configDir?: string;
eject?: boolean;
coverage?: boolean;
coverageDirectory?: string;
junit?: boolean;
browsers?: BrowserType | BrowserType[];
};
Expand All @@ -25,6 +26,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 @@ -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',
Expand Down

0 comments on commit 817388f

Please sign in to comment.