Skip to content

Commit

Permalink
run postVisit on failures as well
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jul 16, 2024
1 parent 5d012d8 commit 7268a7d
Show file tree
Hide file tree
Showing 5 changed files with 566 additions and 177 deletions.
75 changes: 57 additions & 18 deletions src/csf/__snapshots__/transformCsf.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,25 @@ if (!require.main) {
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
const result = await page.evaluate(({
id,
hasPlayFn
}) => __test(id, hasPlayFn), {
id: "button--primary"
});
let result;
try {
result = await page.evaluate(({
id,
hasPlayFn
}) => __test(id, hasPlayFn), {
id: "button--primary"
});
} catch (err) {
if (err.toString().includes('Execution context was destroyed')) {
throw err;
} else {
await globalThis.__sbPostVisit(page, {
...context,
hasFailure: true
});
throw err;
}
}
if (globalThis.__sbPostVisit) {
await globalThis.__sbPostVisit(page, context);
}
Expand Down Expand Up @@ -96,12 +109,25 @@ if (!require.main) {
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
const result = await page.evaluate(({
id,
hasPlayFn
}) => __test(id, hasPlayFn), {
id: "button--primary"
});
let result;
try {
result = await page.evaluate(({
id,
hasPlayFn
}) => __test(id, hasPlayFn), {
id: "button--primary"
});
} catch (err) {
if (err.toString().includes('Execution context was destroyed')) {
throw err;
} else {
await globalThis.__sbPostVisit(page, {
...context,
hasFailure: true
});
throw err;
}
}
if (globalThis.__sbPostVisit) {
await globalThis.__sbPostVisit(page, context);
}
Expand Down Expand Up @@ -149,12 +175,25 @@ if (!require.main) {
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
const result = await page.evaluate(({
id,
hasPlayFn
}) => __test(id, hasPlayFn), {
id: "button--primary"
});
let result;
try {
result = await page.evaluate(({
id,
hasPlayFn
}) => __test(id, hasPlayFn), {
id: "button--primary"
});
} catch (err) {
if (err.toString().includes('Execution context was destroyed')) {
throw err;
} else {
await globalThis.__sbPostVisit(page, {
...context,
hasFailure: true
});
throw err;
}
}
if (globalThis.__sbPostVisit) {
await globalThis.__sbPostVisit(page, context);
}
Expand Down
1 change: 1 addition & 0 deletions src/playwright/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type TestContext = {
id: string;
title: string;
name: string;
hasFailure?: boolean;
};

export type PrepareContext = {
Expand Down
Loading

0 comments on commit 7268a7d

Please sign in to comment.