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

Fix sync issues between tests #404

Merged
merged 2 commits into from
Nov 24, 2023
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
9 changes: 1 addition & 8 deletions playwright/jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
const {
getTestRunnerConfig,
setPreVisit,
setPostVisit,
setupPage,
throwUncaughtPageError,
} = require('../dist');
const { getTestRunnerConfig, setPreVisit, setPostVisit, setupPage } = require('../dist');

const testRunnerConfig = getTestRunnerConfig(process.env.STORYBOOK_CONFIG_DIR);
if (testRunnerConfig) {
Expand All @@ -27,5 +21,4 @@ if (testRunnerConfig) {
// If the transformed tests need a dependency, it has to be globally available
// in order to work both in default (file transformation) and stories/index.json mode.
globalThis.__sbSetupPage = setupPage;
globalThis.__sbThrowUncaughtPageError = throwUncaughtPageError;
globalThis.__sbCollectCoverage = process.env.STORYBOOK_COLLECT_COVERAGE === 'true';
15 changes: 0 additions & 15 deletions src/csf/__snapshots__/transformCsf.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ if (!require.main) {
title: "Button",
name: "Primary"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -51,7 +47,6 @@ if (!require.main) {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down Expand Up @@ -98,10 +93,6 @@ if (!require.main) {
title: "Button",
name: "Primary"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -123,7 +114,6 @@ if (!require.main) {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down Expand Up @@ -156,10 +146,6 @@ if (!require.main) {
title: "Button",
name: "Primary"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -181,7 +167,6 @@ if (!require.main) {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down
16 changes: 0 additions & 16 deletions src/playwright/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { BrowserContext, Page } from 'playwright';
import type { StoryContext } from '@storybook/csf';
import dedent from 'ts-dedent';

export type TestContext = {
id: string;
Expand Down Expand Up @@ -81,18 +80,3 @@ export const waitForPageReady = async (page: Page) => {
await page.waitForLoadState('networkidle');
await page.evaluate(() => document.fonts.ready);
};

export const throwUncaughtPageError = (err: Error, context: TestContext) => {
const storybookUrl = process.env.REFERENCE_URL || process.env.TARGET_URL;
const storyUrl = `${storybookUrl}?path=/story/${context.id}`;

const errorMessage = dedent`
An uncaught error occurred when visiting the following story.
Please access the link and check the logs in the browser:
${storyUrl}

Message:
${err.stack || err.message}\n`;

throw new Error(errorMessage);
};
50 changes: 0 additions & 50 deletions src/playwright/transformPlaywright.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ describe('Playwright', () => {
title: "Example/foo/bar",
name: "A"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -91,7 +87,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand All @@ -116,10 +111,6 @@ describe('Playwright', () => {
title: "Example/foo/bar",
name: "B"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -141,7 +132,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down Expand Up @@ -184,10 +174,6 @@ describe('Playwright', () => {
title: "Example/foo/bar",
name: "B"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -209,7 +195,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down Expand Up @@ -252,10 +237,6 @@ describe('Playwright', () => {
title: "Example/foo/bar",
name: "A"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -277,7 +258,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand All @@ -302,10 +282,6 @@ describe('Playwright', () => {
title: "Example/foo/bar",
name: "B"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -327,7 +303,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down Expand Up @@ -379,10 +354,6 @@ describe('Playwright', () => {
title: "Example/foo/bar",
name: "B"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -404,7 +375,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand All @@ -429,10 +399,6 @@ describe('Playwright', () => {
title: "Example/foo/bar",
name: "C"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -454,7 +420,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down Expand Up @@ -511,10 +476,6 @@ describe('Playwright', () => {
title: "Example/foo/bar",
name: "A"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -536,7 +497,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down Expand Up @@ -577,10 +537,6 @@ describe('Playwright', () => {
title: "Example/foo/bar",
name: "A"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -602,7 +558,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down Expand Up @@ -643,10 +598,6 @@ describe('Playwright', () => {
title: "Example/Header",
name: "A"
};
const onPageError = err => {
globalThis.__sbThrowUncaughtPageError(err, context);
};
page.on('pageerror', onPageError);
if (globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
}
Expand All @@ -668,7 +619,6 @@ describe('Playwright', () => {
}
await jestPlaywright.saveCoverage(page);
}
page.off('pageerror', onPageError);
return result;
};
try {
Expand Down
7 changes: 0 additions & 7 deletions src/playwright/transformPlaywright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export const testPrefixer: TestPrefixer = (context) => {
async () => {
const testFn = async() => {
const context = { id: %%id%%, title: %%title%%, name: %%name%% };

const onPageError = (err) => {
globalThis.__sbThrowUncaughtPageError(err, context);
}

page.on('pageerror', onPageError);

if(globalThis.__sbPreVisit) {
await globalThis.__sbPreVisit(page, context);
Expand All @@ -48,7 +42,6 @@ export const testPrefixer: TestPrefixer = (context) => {
await jestPlaywright.saveCoverage(page);
}

page.off('pageerror', onPageError);

return result;
};
Expand Down
Loading
Loading