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

Addon Test: Improve error message on missing coverage package #30088

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 1 addition & 8 deletions code/addons/test/src/node/test-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ export class TestManager {
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);
this.reportFatalError('Failed to change coverage configuration', e);
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 case would already be handled within the Vitest Manager, so it doesn't make sense to try and handle it here too.

}
}
}
Expand Down
14 changes: 10 additions & 4 deletions code/addons/test/src/node/vitest-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,21 @@ export class VitestManager {
try {
await this.vitest.init();
} catch (e) {
let message = 'Failed to initialize Vitest';
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)) {
if (
(e.message?.includes('Failed to load url') && (isIstanbul || isV8)) ||
// Vitest will sometimes not throw the correct missing-package-detection error, so we have to check for this as well
(e instanceof TypeError &&
e?.message === "Cannot read properties of undefined (reading 'name')")
) {
const coveragePackage = isIstanbul ? 'coverage-istanbul' : 'coverage-v8';
e.message = `Please install the @vitest/${coveragePackage} package to run with coverage`;
message += `\n\nPlease install the @vitest/${coveragePackage} package to run with coverage\n`;
JReinhold marked this conversation as resolved.
Show resolved Hide resolved
}

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

await this.setupWatchers();
Expand Down
Loading