Skip to content

Commit

Permalink
make junit flag accept file path
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Aug 25, 2022
1 parent 36db6d2 commit c8f28d5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
40 changes: 20 additions & 20 deletions README.md
Expand Up @@ -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 <br/>`test-storybook --help` |
| `-i`, `--index-json` | Run in index json mode. Automatically detected (requires a compatible Storybook) <br/>`test-storybook --index-json` |
| `--no-index-json` | Disables index json mode <br/>`test-storybook --no-index-json` |
| `-c`, `--config-dir [dir-name]` | Directory where to load Storybook configurations from <br/>`test-storybook -c .storybook` |
| `--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` |
| `--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` |
| `--no-cache` | Disable the cache <br/>`test-storybook --no-cache` |
| `--clearCache` | Deletes the Jest cache directory and then exits without running tests <br/>`test-storybook --clearCache` |
| `--verbose` | Display individual test results with the test suite hierarchy <br/>`test-storybook --verbose` |
| `-u`, `--updateSnapshot` | Use this flag to re-record every snapshot that fails during this test run <br/>`test-storybook -u` |
| `--eject` | Creates a local configuration file to override defaults of the test-runner <br/>`test-storybook --eject` |
| `--json` | Prints the test results in JSON. This mode will send all other test output and user messages to stderr. <br/>`test-storybook --json` |
| `--outputFile` | Write test results to a file when the --json option is also specified. <br/>`test-storybook --json --outputFile results.json` |
| `--junit` | Indicates that test information should be reported in a junit file. <br/>`test-storybook --**junit**` |
| Options | Description |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `--help` | Output usage information <br/>`test-storybook --help` |
| `-i`, `--index-json` | Run in index json mode. Automatically detected (requires a compatible Storybook) <br/>`test-storybook --index-json` |
| `--no-index-json` | Disables index json mode <br/>`test-storybook --no-index-json` |
| `-c`, `--config-dir [dir-name]` | Directory where to load Storybook configurations from <br/>`test-storybook -c .storybook` |
| `--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` |
| `--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` |
| `--no-cache` | Disable the cache <br/>`test-storybook --no-cache` |
| `--clearCache` | Deletes the Jest cache directory and then exits without running tests <br/>`test-storybook --clearCache` |
| `--verbose` | Display individual test results with the test suite hierarchy <br/>`test-storybook --verbose` |
| `-u`, `--updateSnapshot` | Use this flag to re-record every snapshot that fails during this test run <br/>`test-storybook -u` |
| `--eject` | Creates a local configuration file to override defaults of the test-runner <br/>`test-storybook --eject` |
| `--json` | Prints the test results in JSON. This mode will send all other test output and user messages to stderr. <br/>`test-storybook --json` |
| `--outputFile` | Write test results to a file when the --json option is also specified. <br/>`test-storybook --json --outputFile results.json` |
| `--junit [outputFilePath]` | Indicates that test information should be reported in a junit file. <br/>`test-storybook --junit` or `test-storybook --junit custom/file.xml` |

## Configuration

Expand Down
2 changes: 1 addition & 1 deletion bin/test-storybook.js
Expand Up @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions src/config/jest-playwright.ts
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/util/getCliOptions.ts
Expand Up @@ -8,7 +8,7 @@ type CliOptions = {
configDir?: string;
eject?: boolean;
coverage?: boolean;
junit?: boolean;
junit?: string;
browsers?: BrowserType | BrowserType[];
};
jestOptions: string[];
Expand Down
5 changes: 4 additions & 1 deletion src/util/getParsedCliOptions.ts
Expand Up @@ -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'
Expand Down

0 comments on commit c8f28d5

Please sign in to comment.