From c8f28d5a92146bf80c7906f9dd422ef7e37cc650 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Thu, 25 Aug 2022 19:12:43 +0200 Subject: [PATCH] make junit flag accept file path --- README.md | 40 ++++++++++++++++----------------- bin/test-storybook.js | 2 +- src/config/jest-playwright.ts | 12 ++++++++-- src/util/getCliOptions.ts | 2 +- src/util/getParsedCliOptions.ts | 5 ++++- 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index c1c13c90..59b1b382 100644 --- a/README.md +++ b/README.md @@ -117,26 +117,26 @@ The Storybook test runner comes with Jest installed as an internal dependency. I Usage: test-storybook [options] ``` -| Options | Description | -| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -| `--help` | Output usage information
`test-storybook --help` | -| `-i`, `--index-json` | Run in index json mode. Automatically detected (requires a compatible Storybook)
`test-storybook --index-json` | -| `--no-index-json` | Disables index json mode
`test-storybook --no-index-json` | -| `-c`, `--config-dir [dir-name]` | Directory where to load Storybook configurations from
`test-storybook -c .storybook` | -| `--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` | -| `--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` | -| `--no-cache` | Disable the cache
`test-storybook --no-cache` | -| `--clearCache` | Deletes the Jest cache directory and then exits without running tests
`test-storybook --clearCache` | -| `--verbose` | Display individual test results with the test suite hierarchy
`test-storybook --verbose` | -| `-u`, `--updateSnapshot` | Use this flag to re-record every snapshot that fails during this test run
`test-storybook -u` | -| `--eject` | Creates a local configuration file to override defaults of the test-runner
`test-storybook --eject` | -| `--json` | Prints the test results in JSON. This mode will send all other test output and user messages to stderr.
`test-storybook --json` | -| `--outputFile` | Write test results to a file when the --json option is also specified.
`test-storybook --json --outputFile results.json` | -| `--junit` | Indicates that test information should be reported in a junit file.
`test-storybook --**junit**` | +| Options | Description | +| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | +| `--help` | Output usage information
`test-storybook --help` | +| `-i`, `--index-json` | Run in index json mode. Automatically detected (requires a compatible Storybook)
`test-storybook --index-json` | +| `--no-index-json` | Disables index json mode
`test-storybook --no-index-json` | +| `-c`, `--config-dir [dir-name]` | Directory where to load Storybook configurations from
`test-storybook -c .storybook` | +| `--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` | +| `--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` | +| `--no-cache` | Disable the cache
`test-storybook --no-cache` | +| `--clearCache` | Deletes the Jest cache directory and then exits without running tests
`test-storybook --clearCache` | +| `--verbose` | Display individual test results with the test suite hierarchy
`test-storybook --verbose` | +| `-u`, `--updateSnapshot` | Use this flag to re-record every snapshot that fails during this test run
`test-storybook -u` | +| `--eject` | Creates a local configuration file to override defaults of the test-runner
`test-storybook --eject` | +| `--json` | Prints the test results in JSON. This mode will send all other test output and user messages to stderr.
`test-storybook --json` | +| `--outputFile` | Write test results to a file when the --json option is also specified.
`test-storybook --json --outputFile results.json` | +| `--junit [outputFilePath]` | Indicates that test information should be reported in a junit file.
`test-storybook --junit` or `test-storybook --junit custom/file.xml` | ## Configuration diff --git a/bin/test-storybook.js b/bin/test-storybook.js index b7550d65..ab366ade 100755 --- a/bin/test-storybook.js +++ b/bin/test-storybook.js @@ -246,7 +246,7 @@ const main = async () => { } if (runnerOptions.junit) { - process.env.STORYBOOK_JUNIT = 'true'; + process.env.STORYBOOK_JUNIT_PATH = runnerOptions.junit; } if (process.env.REFERENCE_URL) { diff --git a/src/config/jest-playwright.ts b/src/config/jest-playwright.ts index 6910ba5f..e19389b0 100644 --- a/src/config/jest-playwright.ts +++ b/src/config/jest-playwright.ts @@ -5,10 +5,18 @@ export const getJestConfig = () => { STORYBOOK_STORIES_PATTERN, TEST_BROWSERS, STORYBOOK_COLLECT_COVERAGE, - STORYBOOK_JUNIT, + STORYBOOK_JUNIT_PATH, } = process.env; - const reporters = STORYBOOK_JUNIT ? ['default', 'jest-junit'] : ['default']; + const jUnitPath = STORYBOOK_JUNIT_PATH + ? STORYBOOK_JUNIT_PATH === 'true' + ? 'junit.xml' + : STORYBOOK_JUNIT_PATH + : undefined; + + const reporters = jUnitPath + ? ['default', ['jest-junit', { outputFile: jUnitPath }]] + : ['default']; let config = { rootDir: process.cwd(), diff --git a/src/util/getCliOptions.ts b/src/util/getCliOptions.ts index cdd62e6e..92f7854c 100644 --- a/src/util/getCliOptions.ts +++ b/src/util/getCliOptions.ts @@ -8,7 +8,7 @@ type CliOptions = { configDir?: string; eject?: boolean; coverage?: boolean; - junit?: boolean; + junit?: string; browsers?: BrowserType | BrowserType[]; }; jestOptions: string[]; diff --git a/src/util/getParsedCliOptions.ts b/src/util/getParsedCliOptions.ts index 91300017..bbdf1a9a 100644 --- a/src/util/getParsedCliOptions.ts +++ b/src/util/getParsedCliOptions.ts @@ -52,7 +52,10 @@ export const getParsedCliOptions = () => { '--coverage', 'Indicates that test coverage information should be collected and reported in the output' ) - .option('--junit', 'Indicates that test information should be reported in a junit file') + .option( + '--junit [outputPath]', + 'Indicates that test information should be reported in a junit file' + ) .option( '--eject', 'Creates a local configuration file to override defaults of the test-runner. Use it only if you want to have better control over the runner configurations'