Skip to content

Commit

Permalink
fix: prevent flakiness due to errors promptly solved by auto-refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
fwouts committed Jun 11, 2023
1 parent f590ef3 commit d693c01
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 19 deletions.
15 changes: 12 additions & 3 deletions chromeless/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,31 @@ export async function startPreview({
};
let renderSucceeded = false;
let lastErrorLog: string | null = null;
let delay: NodeJS.Timeout;

function errorUnlessSoonSuccessful(message: string) {
delay = setTimeout(() => {
onRenderingError(new Error(message));
}, 1000);
}

const events = await setupPreviewEventListener(page, (event) => {
if (event.kind === "rendering-done") {
if (event.success) {
renderSucceeded = true;
clearTimeout(delay);
onRenderingDone();
} else {
if (lastErrorLog) {
onRenderingError(new Error(lastErrorLog));
errorUnlessSoonSuccessful(lastErrorLog);
} else {
// The error log should be coming straight after.
}
}
} else if (event.kind === "log-message" && event.level === "error") {
lastErrorLog = event.message;
if (!renderSucceeded && !event.message.startsWith("[Vue warn]")) {
onRenderingError(new Error(event.message));
if (!renderSucceeded) {
errorUnlessSoonSuccessful(event.message);
}
}
});
Expand Down
5 changes: 4 additions & 1 deletion framework-plugins/vue2/tests/error-handling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ test.describe.parallel("vue2/error handling", () => {
await preview.show("src/App.vue:App").catch(() => {
/* expected error */
});
await preview.expectLoggedMessages.toMatch(["App.vue:3:3: Unknown word"]);
await preview.expectLoggedMessages.toMatch([
"App.vue:3:3: Unknown word",
"App.vue:3:3: Unknown word",
]);
await preview.fileManager.update("src/App.vue", {
replace: " BROKEN",
with: "#app {",
Expand Down
5 changes: 4 additions & 1 deletion framework-plugins/vue3/tests/error-handling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ test.describe.parallel("vue3/error handling", () => {
await preview.show("src/App.vue:App").catch(() => {
/* expected error */
});
await preview.expectLoggedMessages.toMatch(["App.vue:3:3: Unknown word"]);
await preview.expectLoggedMessages.toMatch([
"App.vue:3:3: Unknown word",
"App.vue:3:3: Unknown word",
]);
await preview.fileManager.update("src/App.vue", {
replace: " BROKEN",
with: "#app {",
Expand Down
Loading

0 comments on commit d693c01

Please sign in to comment.