storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
83.93k stars 9.21k forks source link

Scaffold `@storybook/addon-vitest` with basic mocked test results [gert] #28687

Closed yannbf closed 3 weeks ago

greptile-apps[bot] commented 1 month ago

Disclaimer This information might be inaccurate, due to it being generated automatically

  1. Create a new directory addons/vitest.
  2. Add a new file addons/vitest/preset.js with the following content:
    module.exports = {
    async viteFinal(config, { configType }) {
    // Customize the Vite config here
    return config;
    },
    };
  3. Add a new file addons/vitest/register.js with the following content:
    
    import { addDecorator } from '@storybook/client-api';
    import { withVitest } from './withVitest';

addDecorator(withVitest);

4. Add a new file `addons/vitest/withVitest.js` with the following content:
```javascript
export const withVitest = (StoryFn, context) => {
  // Mock test results here
  const testResults = { /* mocked test results */ };
  context.parameters.testResults = testResults;
  return StoryFn();
};
  1. Update main.js to include the new addon:
    module.exports = {
    addons: ['@storybook/addon-vitest'],
    };

References

/.github/DISCUSSION_TEMPLATE/help.yml /.github/DISCUSSION_TEMPLATE/ideas.yml /.github/DISCUSSION_TEMPLATE/rfc.yml /.github/comments/invalid-link.md /.github/comments /test-storybooks/ember-cli/ember-output/storybook-docgen /docs/_snippets/test-runner-with-index-json.md /test-storybooks/portable-stories-kitchen-sink/svelte/cypress/fixtures /docs/contribute/how-to-reproduce.mdx /code/lib/test/template/stories/module-mocking.stories.ts /code/renderers/vue3/src/docs/extractArgTypes.test.ts /code/lib/source-loader/src/abstract-syntax-tree/inject-decorator.test.js /code/lib/cli/src/automigrate/fixes/new-frameworks.ts /docs/_snippets/test-runner-no-index-json.md /code/lib/cli/src/automigrate/index.test.ts /CONTRIBUTING.md /code/core/src/preview-errors.ts /code/lib/cli/src/automigrate/fixes/vta.ts /code/core/src/core-server/utils/mockdata/errors/NoMeta.stories.ts /code/renderers/server/template/cli/button.stories.json /docs/_snippets/custom-build-script-production.md /code/core/src/server-errors.ts /code/addons/docs/ember /code/core/src/common/js-package-manager/NPMProxy.test.ts /code/lib/cli/src/automigrate/fixes/wrap-require.ts

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/storybookjs/storybook/next) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)