Skip to content

Commit

Permalink
Merge pull request #29763 from storybookjs/norbert/improve-coverage-d…
Browse files Browse the repository at this point in the history
…ep-missing-error

Addon Test: Clarify message when `vitest` detects missing deps
  • Loading branch information
ndelangen authored Dec 5, 2024
2 parents 019be35 + 07cdd5b commit 4863529
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions code/addons/test/src/node/test-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export class TestManager {
this.coverage = payload.config.coverage;
await this.restartVitest({ watchMode: this.watchMode, coverage: this.coverage });
} catch (e) {
const isV8 = e.message?.includes('@vitest/coverage-v8');
const isIstanbul = e.message?.includes('@vitest/coverage-istanbul');

if (e.message?.includes('Error: Failed to load url') && (isIstanbul || isV8)) {
const coveragePackage = isIstanbul ? 'coverage-istanbul' : 'coverage-v8';
e.message = `Please install the @vitest/${coveragePackage} package to run with coverage`;
}
this.reportFatalError('Failed to change coverage mode', e);
}
}
Expand Down
8 changes: 8 additions & 0 deletions code/addons/test/src/node/vitest-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ export class VitestManager {
try {
await this.vitest.init();
} catch (e) {
const isV8 = e.message?.includes('@vitest/coverage-v8');
const isIstanbul = e.message?.includes('@vitest/coverage-istanbul');

if (e.message?.includes('Error: Failed to load url') && (isIstanbul || isV8)) {
const coveragePackage = isIstanbul ? 'coverage-istanbul' : 'coverage-v8';
e.message = `Please install the @vitest/${coveragePackage} package to run with coverage`;
}

this.testManager.reportFatalError('Failed to init Vitest', e);
}

Expand Down

0 comments on commit 4863529

Please sign in to comment.