Skip to content

Addon-vitest: Fix coverage when restarting Vitest due to config change #31069

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

Merged
merged 1 commit into from
Apr 4, 2025
Merged
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
7 changes: 3 additions & 4 deletions code/addons/vitest/src/node/vitest-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class VitestManager {

constructor(private testManager: TestManager) {}

async startVitest({ coverage = false } = {}) {
async startVitest({ coverage }: { coverage: boolean }) {
const { createVitest } = await import('vitest/node');

const storybookCoverageReporter: [string, StorybookCoverageReporterOptions] = [
Expand Down Expand Up @@ -206,7 +206,6 @@ export class VitestManager {
if (!this.vitest) {
await this.startVitest({ coverage: coverageShouldBeEnabled });
} else if (currentCoverage !== coverageShouldBeEnabled) {
await this.vitestRestartPromise;
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 was already called within this.restartVitest

await this.restartVitest({ coverage: coverageShouldBeEnabled });
} else {
await this.vitestRestartPromise;
Expand Down Expand Up @@ -391,8 +390,8 @@ export class VitestManager {
const isConfig = file === this.vitest?.vite?.config.configFile;
if (isConfig) {
log('Restarting Vitest due to config change');
await this.closeVitest();
await this.startVitest();
const { watching, config } = this.testManager.store.getState();
await this.restartVitest({ coverage: config.coverage && !watching });
}
});
}
Expand Down
Loading