Skip to content

Commit

Permalink
Merge pull request #494 from storybookjs/post-visit-on-failures
Browse files Browse the repository at this point in the history
Feature: Run postVisit on failures
  • Loading branch information
yannbf authored Nov 28, 2024
2 parents 3a2a920 + 3f8071b commit 322bd62
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 322bd62

Please sign in to comment.