storybookjs / test-runner

🚕 Turn stories into executable tests

Home Page:https://storybook.js.org/docs/writing-tests/interaction-testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[bug] the --outputFile parameter is not working when --junit parameter is issued

squidjam opened this issue · comments

Describe the bug
When you issue the --junit parameter to generate a junitXML test report, the --outputFile parameter doesn't allow you to set the name of the output report file (but it does on --json), and a file with a default name (junit.xml) is generated.

To Reproduce
Steps to reproduce the behavior:

  1. Run yarn test-storybook --junit --outputFile tests.xml
  2. See error

Expected behavior
The output report file should be named using the --outputFile parameter value

Screenshots
image

System
Storybook Environment Info:

System:
OS: Windows 11 10.0.22000
CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12800H
Binaries:
Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD <----- active
npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.5.1 - ~\AppData\Roaming\nvm\v18.12.1\pnpm.CMD
Browsers:
Edge: Spartan (44.22000.2600.0), Chromium (122.0.2365.92)
npmPackages:
@storybook/addon-a11y: ^8.0.0 => 8.0.0
@storybook/addon-designs: ^7.0.9 => 7.0.9
@storybook/addon-essentials: ^8.0.0 => 8.0.0
@storybook/addon-interactions: ^8.0.0 => 8.0.0
@storybook/addon-links: ^8.0.0 => 8.0.0
@storybook/addon-mdx-gfm: 8.0.0 => 8.0.0
@storybook/blocks: ^8.0.0 => 8.0.0
@storybook/react: ^8.0.0 => 8.0.0
@storybook/react-vite: ^8.0.0 => 8.0.0
@storybook/test: 8.0.0 => 8.0.0
@storybook/test-runner: ^0.17.0 => 0.17.0
eslint-plugin-storybook: ^0.8.0 => 0.8.0
storybook: ^8.0.0 => 8.0.0

Additional context
Add any other context about the problem here.

Hey @squidjam thanks for reporting this! I don't think it's an actual issue 🤔

1 - the --outputFile parameter is supposed to be used for the --json mode of jest, to specify the name of the json file, not junit. You can test it like so: yarn test-storybook --json -- --outputFile="tests.json"
2 - For junit, you can configure it via environment variables, check their docs: https://www.npmjs.com/package/jest-junit#configuration
So JEST_JUNIT_OUTPUT_NAME="testing.xml" yarn test-storybook --junit would generate the correct result:
image

Hello, thank you for your answer.
My use case looks to produce separate junit files (one for a11y, another for visual regression testing) so being able to name them is part of it.
I would love that junit output was also possible using the same parameter to have a named file, otherwise one run will overwrite the other.
I'll try your recommendation.
Thanks.

Hello, thank you for your answer. My use case looks to produce separate junit files (one for a11y, another for visual regression testing) so being able to name them is part of it. I would love that junit output was also possible using the same parameter to have a named file, otherwise one run will overwrite the other. I'll try your recommendation. Thanks.

Thanks for explaining! Would you mind sharing a minimal reproduction so I can take a look at?

Hello, thank you for your answer. My use case looks to produce separate junit files (one for a11y, another for visual regression testing) so being able to name them is part of it. I would love that junit output was also possible using the same parameter to have a named file, otherwise one run will overwrite the other. I'll try your recommendation. Thanks.

Thanks for explaining! Would you mind sharing a minimal reproduction so I can take a look at?

Thanks, after further reading, the way described by you should be the right way to do it. Cheers.

For future reference:
https://www.npmjs.com/package/jest-junit#user-content-configuration
(scroll down a little and you'll find the parameter).

I just thought it would be easier to pass through the parameter --output and have test-runner reroute it as the JEST_JUNIT_OUTPUT_NAME="name.xml" when it invokes junit itself.
Closing because your answer is the right one.