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

feat: throw explaining error when JSDOM HTML template render failed #586

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/small-rivers-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ima/testing-library": minor
---

Throw an error when JSDOM HTML template render failed. This can be potentially a **BREAKING CHANGE** if your tests are already using a broken HTML template in JSDOM. Until now, you might not have even noticed the problem until you had a test accessing specific context features that required a proper HTML template.
6 changes: 6 additions & 0 deletions packages/testing-library/src/jest-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const jestConfig: Promise<Config> = (async () => {
// Some async errors are swallowed by jest, so we need to log them manually and throw a safe error
console.error(error.stack ?? error);

if (error.cause) {
// eslint-disable-next-line no-console
console.log(); // Empty line to avoid stacking with the error above
console.error(error.cause.stack ?? error.cause);
}

throw new Error(
'Failed to get IMA response content. Check the error above.'
);
Expand Down
13 changes: 13 additions & 0 deletions packages/testing-library/src/server/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,18 @@ export async function getIMAResponseContent(): Promise<string> {
}
);

if (response.status !== 200) {
throw new Error(
`Failed to generate HTML content for JSDOM template (status: ${response.status}).`,
{
cause:
response.error ||
new Error(
`This should not happen, file an issue with @ima/testing-library if you are seeing this.`
),
}
);
}

return response.content;
}
Loading