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 updates for Storybook Test #30035

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open

Docs updates for Storybook Test #30035

wants to merge 1 commit into from

Conversation

kylegach
Copy link
Contributor

@kylegach kylegach commented Dec 12, 2024

Closes #29794

What I did

  • Focused tests
  • Coverage
  • A11y
  • Remove test.include & test.isolate from example Vitest configs
  • Streamline Test addon introduction
  • Address feedback from EAP

Checklist for Contributors

Testing

Manual testing

  1. Sync this branch with locally running docs

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-storybook/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

Based on the provided files and context, I'll create a concise summary of the documentation updates for the Storybook Test addon:

Documentation updates for Storybook Test addon v8.5, introducing focused testing capabilities, enhanced coverage reporting, and improved accessibility testing integration.

  • Added focused testing functionality at story/component/group levels in Test addon UI
  • Updated coverage reporting with HTML reports at localhost:6006/coverage/index.html and configurable watermarks
  • Removed deprecated test.include and test.isolate configurations from Vitest examples
  • Integrated accessibility testing with Test addon, replacing parameters.a11y.manual with globals.a11y.manual
  • Added framework-specific plugin configurations for React, Vue, and Svelte in Vitest setup

The summary focuses on the key technical changes while maintaining clarity and avoiding repetition. It highlights the major updates across documentation files and configuration examples.

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

- Focused tests
- Coverage
- A11y
- Remove `test.include` & `test.isolate` from example Vitest configs
- Streamline Test addon introduction
- Address feedback from EAP
@kylegach kylegach added documentation ci:docs Run the CI jobs for documentation checks only. labels Dec 12, 2024
@kylegach kylegach self-assigned this Dec 12, 2024
Copy link
Contributor

Fails
🚫 PR title must be in the format of "Area: Summary", With both Area and Summary starting with a capital letter Good examples: - "Docs: Describe Canvas Doc Block" - "Svelte: Support Svelte v4" Bad examples: - "add new api docs" - "fix: Svelte 4 support" - "Vue: improve docs"

Generated by 🚫 dangerJS against 6fb17c9

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.

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

Comment on lines +38 to +39
- Storybook ≥ 8.5
- A Storybook framework that uses Vite (e.g. [`vue3-vite`](../get-started/frameworks/vue3-vite.mdx), [`react-vite`](../get-started/frameworks/react-vite.mdx), ['sveltekit`](../get-started/frameworks/sveltekit.mdx), etc.), or the [Storybook Next.js framework with Vite](../get-started/frameworks/nextjs.mdx#with-vite)
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Incorrect backtick in 'sveltekit` link syntax

Comment on lines +226 to +227
[TK: Screenshot of story sidebar item with open menu]
![Screenshot of story sidebar item with open menu](../_assets/writing-tests/addon-test-sidebar-item-menu.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Placeholder [TK] text should be removed before merging

Comment on lines +351 to +352
[TK - Test module edit mode with only coverage]
![Screenshot of test module, expanded, edit mode, coverage is checked](../_assets/writing-tests/addon-test-module-expanded-edit-coverage.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Placeholder [TK] text should be removed before merging

Comment on lines +361 to +362
[TK - Sidebar item menu with edit mode]
![Screenshot of story sidebar item with open menu, edit mode](../_assets/writing-tests/addon-test-sidebar-item-menu-edit.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Placeholder [TK] text should be removed before merging

// ...
coverage: {
// ...
provider: 'instanbul', // 'v8' is the default
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: 'instanbul' is misspelled, should be 'istanbul'

Comment on lines +158 to +159
[TK - Coverage result]
![Screenshot of test module, expanded, showing coverage result](../_assets/writing-tests/addon-test-coverage-result.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: This image is duplicated from line 20-21 and should be removed or replaced with a different screenshot

tags: ['a11ytest'],
};

export default preview;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: export default meta instead of preview here

Copy link

nx-cloud bot commented Dec 12, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 6fb17c9. 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.

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.

7 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -120,43 +120,69 @@ Customize the a11y ruleset at the story level by updating your story to include

## Test addon integration

The accessibility addon provides seamless integration with Storybook's [test addon](./test-addon.mdx), enabling you to run automated accessibility checks for all your tests in the background while you run component tests. If there are any violations, the test will fail, and you will see the results in the sidebar without any additional setup.
The accessibility addon provides seamless integration with the [Test addon](./test-addon.mdx), enabling you to run automated accessibility checks for all your tests in the background while you run component tests. If there are any violations, the test will fail, and you will see the results in the sidebar without any additional setup.

{/* TODO: add asset of the changed UI here */}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: TODO comment should be removed before merging

Comment on lines 229 to +231
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.

{/* TODO: 👆 Revise this to not be limited to Component tests */}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: This paragraph references Component tests specifically but should be generalized since it applies to all test types

Comment on lines +335 to +341
## How it works

The Test addon works by using a Vitest plugin to transform your stories into [Vitest](https://vitest.dev) tests using [portable stories](../api/portable-stories/portable-stories-vitest.mdx). It also configures Vitest to run those tests in [browser mode](https://vitest.dev/guide/browser/), using Playwright's Chromium browser. Because it is built on top of Vitest, the addon requires a Vite-based Storybook framework.

Stories are tested in two ways: a smoke test to ensure it renders and, if a [play function](../writing-tests/component-testing#write-a-component-test) is defined, that function is run and any [assertions made](../writing-tests/component-testing.mdx#assert-tests-with-vitests-apis) within it are validated.

When you run tests in the [Storybook UI](#storybook-ui), the addon runs Vitest in the background and reports the results in the sidebar.
Copy link
Contributor

Choose a reason for hiding this comment

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

style: This 'How it works' section duplicates information from the introduction. Consider consolidating to avoid repetition

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.

Thanks for taking the time to put together this pull request and make the required adjustments. I left some items for you to look into when you can. Nothing major.

Also, just as a reminder, we still have some "TK" and missing images and if we don't get to them, let's comment those out.

I'm approving it to unblock you.

Comment on lines +158 to +170
```ts title="Button.stories.ts"
// Replace your-renderer with the renderer you are using (e.g., react, vue3)
import { Meta } from '@storybook/your-renderer';

import { Button } from './Button';

const meta = {
component: Button,
// 👇 Re-apply the a11ytest tag for this component's stories
tags: ['a11ytest'],
};

export default preview;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a bit of a sanity check here: don't forget to convert the example into a full-fledged snippet file with the supported renderers and frameworks (including Svelte CSF, if possible).


If a test fails, it will be marked as such in the sidebar and you can click on the story to see the failure. You can also run tests in watch mode, which will automatically re-run tests when you make changes to your components or stories.
When tests are run for a story, the status is shown in the sidebar. You can filter it down to only show failures and failing status indicators open a menu to debug the failure. You can also run tests in watch mode, which will automatically re-run tests when you make changes to your components or stories.
Copy link
Contributor

Choose a reason for hiding this comment

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

The words are not precious, but we could go with something like:

Suggested change
When tests are run for a story, the status is shown in the sidebar. You can filter it down to only show failures and failing status indicators open a menu to debug the failure. You can also run tests in watch mode, which will automatically re-run tests when you make changes to your components or stories.
When tests are run for a story, the status is shown in the sidebar. You can filter it to show only failures and failing status. You can also run tests in watch mode, which will automatically re-run tests when you make changes to your components or stories. To do so, expand the test UI in the sidebar and adjust the settings as needed.

## Configuring tests

Most of the configuration for the Vitest plugin's behavior is done in the Vitest configuration and setup files. However, you can also define configuration in your stories themselves, using [tags](../writing-stories/tags.mdx), to control how they are tested.
The tests run by the addon can be configured in two ways. You can toggle which test types are run, and you can include, exclude, or skip stories from being tested.
Copy link
Contributor

Choose a reason for hiding this comment

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

The wording is not precious but we can probably simplify it a bit

Suggested change
The tests run by the addon can be configured in two ways. You can toggle which test types are run, and you can include, exclude, or skip stories from being tested.
The tests run by the addon can be configured in two ways. You can toggle which test types are run and include, exclude, or skip stories from being tested.


### Toggling test types

You can toggle different testing types on or off in the test module. Press the edit icon to enter edit mode, then toggle the test types you want to run. You may only see a checkbox for coverage:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a bit of a reminder: this page is referred to as the Test addon, and we're mentioning it across our documentation. However, we still have some instances where we say "module", we should standardize the wording to avoid confusion

@@ -436,12 +478,29 @@ We recommend using Chromium, because it is most likely to best match the experie

By default, the export name of a story is mapped to the test name. To create a more descriptive test description, you can provide a `name` property for the story. This allows you to include spaces, brackets, or other special characters.

```js
```js title="Example.stories.ts"
Copy link
Contributor

Choose a reason for hiding this comment

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

When you can, adjust the title to be title="Example.stories.js|ts. as the way it's currently referenced, it's not a TypeScript story per se. We can revisit this and add a full-fledged example later on

It's important to understand that the coverage reported in the Storybook UI has three important limitations:

1. Coverage is calculated using the stories you've written, not the entire codebase. In other words, it will not include any other Vitest tests.
2. Coverage can only be calculated for all stories in your project, not an individual story or a group of stories.
Copy link
Contributor

Choose a reason for hiding this comment

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

Small typo here I assume:

Suggested change
2. Coverage can only be calculated for all stories in your project, not an individual story or a group of stories.
2. Coverage can only be calculated for all stories in your project, not for an individual story or a group of stories.

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a minor item to be looked into we can probably go with Node 20 and start standardizing the versions.


### Troubleshooting

#### Excluding stories from coverage report
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a small typo here, I'd assume.

Suggested change
#### Excluding stories from coverage report
#### Excluding stories from the coverage report

Comment on lines +200 to +216
```ts title="vitest.config.ts"
import { coverageConfigDefaults, defineConfig } from 'vitest/config';

export default defineConfig({
// ... rest of your config
test: {
coverage: {
// 👇 Add this
exclude: [
...coverageConfigDefaults.exclude,
// This pattern must align with the `stories` property of your `.storybook/main.js` config
'**/*.stories.*', '**/*.story.*', '**/stories.*', '**/story.*'
],
}
}
})
```
Copy link
Contributor

Choose a reason for hiding this comment

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

When you can, remove the "rest of your config commentary" and adjust the Storybook config reference (i.e., .storybook/main.js in what's a TypeScript file) for consistency.

</details>

<details>
<summary>Webpack 5 options</summary>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just an idea. We should simplify this and conditionally render the tables based on the framework.

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.

LGTM

7 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

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.

Document Component Testing changes in 8.5
2 participants