Skip to content

Commit

Permalink
Merge pull request #586 from seznam/cnsqa-1658
Browse files Browse the repository at this point in the history
feat: throw explaining error when JSDOM HTML template render failed
  • Loading branch information
Filipoliko authored Oct 16, 2024
2 parents d6e0b36 + cd24e83 commit e12e43e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
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;
}

0 comments on commit e12e43e

Please sign in to comment.