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

TestAddon: Exclude *.stories.* from coverage #29810

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/addons/test/src/node/vitest-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class VitestManager {
clean: false,
cleanOnRerun: !watchMode,
reportOnFailure: true,
exclude: [...(this.vitest?.config?.coverage?.exclude || []), '**/*.stories.*'],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
exclude: [...(this.vitest?.config?.coverage?.exclude || []), '**/*.stories.*'],
exclude: [...(this.vitest?.config?.coverage?.exclude || []), '**/*.stories.*', 'storybook-static'],

Copy link
Contributor

@JReinhold JReinhold Dec 4, 2024

Choose a reason for hiding this comment

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

this.vitest is always going to be undefined at this point, either because this is the first time starting it, or becase a restart always closes vitest first.

So I don't think this is adequate to combine with the user's and/or Vitest's default exclude list.

We need to first resolve the Vitest config, and then we can read from it. The Vitest maintainers have given me a code snippet like this, that should work (maybe with slight modifications):

import { resolveConfig as viteResolveConfig } from 'vite';
import { VitestPlugin, resolveConfig as vitestResolveConfig } from 'vitest/node';

const resolveConfig = async () => {
  const viteConfig = await viteResolveConfig({
    plugins: [VitestPlugin()]
  });
  return vitestResolveConfig(viteConfig);
}

image
image

reporter: [['html', {}], storybookCoverageReporter],
reportsDirectory: resolvePathInStorybookCache(COVERAGE_DIRECTORY),
}
Expand Down
Loading