Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Replace Vitest plugin with Test addon #29315

Merged
merged 9 commits into from
Oct 23, 2024

Conversation

kylegach
Copy link
Contributor

@kylegach kylegach commented Oct 9, 2024

(Part of #29088)

What I did

  • Replace /docs/writing-tests/vitest-plugin with /docs/writing-tests/test-addon
  • Revise and add to the content to cover the Storybook UI enhancements and other details

Checklist for Contributors

Manual testing

  1. In this repo, check out this branch, addon-test-docs
  2. In the web repo
    1. Run npm run sync-docs
    2. In another terminal tab, run npm run dev
    3. Open the docs page http://localhost:3000/docs/writing-tests/test-addon

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

Greptile Summary

This pull request replaces the Vitest plugin documentation with the new Test addon documentation, providing a comprehensive guide for using the Test addon in Storybook.

  • Renamed docs/writing-tests/vitest-plugin.mdx to docs/writing-tests/test-addon.mdx
  • Updated content to cover Storybook UI enhancements for running tests directly in the UI
  • Added sections on installation, setup, usage, configuration, and comparison with the test runner
  • Included new information on debugging and running tests in CI environments
  • Updated docs/_snippets/vitest-plugin-vitest-workspace.md with renderer-specific configurations

@kylegach kylegach self-assigned this Oct 9, 2024
Comment on lines +261 to +268
#### Debugging

While the plugin does not require Storybook to run when testing, you may still want to run Storybook to debug your tests. To enable this, provide the [`storybookScript` option](#storybookscript) in the plugin configuration. When you run Vitest in watch mode, the plugin will start Storybook using this script and provide links to the story in the output on test failures. This allows you to quickly jump to the story in Storybook to debug the issue.

You can also provide a [`storybookUrl` option](#storybookurl) to the plugin configuration. When you're not using watch mode and tests fail, the plugin will provide a link to the story using this URL in the output. This is useful when [running tests in CI](#in-ci) or other environments where Storybook is not already running.

![Screenshot of test failure in the console, showing a failure with a link to the story](../_assets/writing-tests/vitest-plugin-test-failure.png)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same content as the previous debugging section that was immediately under Usage. I moved it to be under CLI because the page now presents the SB UI usage as primary and this section only pertains to CLI.

Copy link

nx-cloud bot commented Oct 9, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 15c9433. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Comment on lines 375 to 385
### What happens if Vitest itself has an error?

Sometimes tests can fail because of errors within Vitest itself. When this happens, the test module in the Storybook UI will alert you to the error, and you can click a link to see more details. The error will also be logged to the console.

{/* TODO: screenshot of test module with Vitest error */}

Vitest offers [troubleshooting help for common errors](https://vitest.dev/guide/common-errors.html).

### What happens when there are different test results in multiple environments?

When you run tests with this addon, they are run as Vitest tests with whatever configuration you have set up in your project. By default, they will run in browser mode, using Playwright's Chromium browser. Sometimes, tests will fail when run in the addon (or via CLI), but then pass when viewed in the Component tests addon panel (or vice-versa). This can happen because the tests are run in different environments, which can have different behaviors.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ghengeveld @valentinpalkovic @yannbf — Is there more help we can offer for either of these sections?

@kylegach kylegach added the ci:docs Run the CI jobs for documentation checks only. label Oct 18, 2024
@kylegach kylegach marked this pull request as ready for review October 18, 2024 16:19
@kylegach kylegach requested review from jonniebigodes and removed request for jonniebigodes October 18, 2024 16:19
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

@jonniebigodes jonniebigodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is shaping up nicely, I left some items to be looked into when possible so that we can get this one and published

docs/writing-tests/test-addon.mdx Outdated Show resolved Hide resolved
docs/writing-tests/test-addon.mdx Outdated Show resolved Hide resolved
Comment on lines +221 to +230
After running your tests, you will now see status indicators on stories and components for their pass, fail, or error state. You can press on these indicators to see more details and jump straight to the failure in the Component tests addon panel. That panel provides an interactive debugger for your component test, allowing you to step through each simulated behavior or assertion.

<Callout variant="info" icon="ℹ️">

The Component tests addon panel replaces the [Interactions addon panel](../essentials/interactions.mdx) when the Test addon is installed. While the testing mechanism is different, the functionality of the addon panel itself remains the same.

</Callout>

The test module will also show you the total number of tests run, the number of tests that passed, and the number of tests that failed or errored. You can press the failure number to filter the sidebar to only those stories that failed.

<Video src="../_assets/writing-tests/addon-test-filter-sidebar.mp4" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be reframed and included inside a section on previewing the test results to educate the user on how to do it. There's a lot of information for the user to digest, which can result in confusion. The bonus is that we can use said section in the future for other learning materials, blogs, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. The section first describes how to run tests and then how to review them. One must come after the other. Splitting that into two sub-sections would be overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to go ahead and merge this into the parent PR so that it goes out with the actual feature.

If you really feel strongly about this feedback (or anything else), please ping me in a comment over there.

@kylegach kylegach changed the base branch from next to unified-ui-testing October 23, 2024 04:45
@kylegach kylegach merged commit f3b479a into unified-ui-testing Oct 23, 2024
7 checks passed
@kylegach kylegach deleted the addon-test-docs branch October 23, 2024 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:docs Run the CI jobs for documentation checks only. documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants