Skip to content

Commit a55ab7c

Browse files
committed
test: fix flaky page.pause() tests affect unrelated tests and stall
1 parent 5a8b499 commit a55ab7c

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

packages/playwright/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
288288
step?.complete({ error });
289289
},
290290
onWillPause: () => {
291-
currentTestInfo()?._setDebugMode();
291+
if (!process.env.PLAYWRIGHT_INTERNAL_DISABLE_PAGE_PAUSE_TEST_RUNNER_TIMEOUT)
292+
currentTestInfo()?._setDebugMode();
292293
},
293294
runAfterCreateBrowserContext: async (context: BrowserContext) => {
294295
await artifactsRecorder?.didCreateBrowserContext(context);

tests/library/browsertype-connect.spec.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,21 @@ for (const kind of ['launchServer', 'run-server'] as const) {
170170
});
171171

172172
test('should ignore page.pause when headed', async ({ connect, startRemoteServer, browserType, channel }) => {
173-
const headless = (browserType as any)._defaultLaunchOptions.headless;
174-
(browserType as any)._defaultLaunchOptions.headless = false;
175-
const remoteServer = await startRemoteServer(kind);
176-
const browser = await connect(remoteServer.wsEndpoint());
177-
const browserContext = await browser.newContext();
178-
const page = await browserContext.newPage();
179-
await page.pause();
180-
await browser.close();
181-
(browserType as any)._defaultLaunchOptions.headless = headless;
173+
// await page.pause() disables the test-runner timeout, so we opt-out of it.
174+
process.env.PLAYWRIGHT_INTERNAL_DISABLE_PAGE_PAUSE_TEST_RUNNER_TIMEOUT = '1';
175+
try {
176+
const headless = (browserType as any)._defaultLaunchOptions.headless;
177+
(browserType as any)._defaultLaunchOptions.headless = false;
178+
const remoteServer = await startRemoteServer(kind);
179+
const browser = await connect(remoteServer.wsEndpoint());
180+
const browserContext = await browser.newContext();
181+
const page = await browserContext.newPage();
182+
await page.pause();
183+
await browser.close();
184+
(browserType as any)._defaultLaunchOptions.headless = headless;
185+
} finally {
186+
delete process.env.PLAYWRIGHT_INTERNAL_DISABLE_PAGE_PAUSE_TEST_RUNNER_TIMEOUT;
187+
}
182188
});
183189

184190
test('should be able to visit ipv6 through localhost', async ({ connect, startRemoteServer, ipV6ServerPort }) => {

tests/library/inspector/console-api.spec.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { test as it, expect } from './inspectorTest';
17+
import { test as base, expect } from './inspectorTest';
1818

19-
it.skip(({ mode }) => mode !== 'default');
20-
21-
let scriptPromise: Promise<void>;
22-
23-
it.beforeEach(async ({ page, recorderPageGetter }) => {
24-
scriptPromise = (async () => {
25-
await page.pause();
26-
})();
27-
await recorderPageGetter();
19+
const it = base.extend<{scriptPromise: Promise<void>}>({
20+
scriptPromise: [async ({ page, recorderPageGetter }, use) => {
21+
// await page.pause() disables the test-runner timeout, so we opt-out of it.
22+
process.env.PLAYWRIGHT_INTERNAL_DISABLE_PAGE_PAUSE_TEST_RUNNER_TIMEOUT = '1';
23+
const scriptPromise = (async () => {
24+
await page.pause();
25+
})();
26+
await recorderPageGetter();
27+
await use(scriptPromise);
28+
delete process.env.PLAYWRIGHT_INTERNAL_DISABLE_PAGE_PAUSE_TEST_RUNNER_TIMEOUT;
29+
}, { scope: 'test', auto: true }],
2830
});
2931

30-
it.afterEach(async ({ recorderPageGetter }) => {
32+
it.skip(({ mode }) => mode !== 'default');
33+
34+
it.afterEach(async ({ recorderPageGetter, scriptPromise }) => {
3135
const recorderPage = await recorderPageGetter();
3236
recorderPage.click('[title="Resume (F8)"]').catch(() => {});
3337
await scriptPromise;

tests/library/inspector/pause.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@
1515
*/
1616

1717
import type { Page } from 'playwright-core';
18-
import { test as it, expect, Recorder } from './inspectorTest';
18+
import { test as base, expect, Recorder } from './inspectorTest';
1919
import { waitForTestLog } from '../../config/utils';
2020
import { roundBox } from '../../page/pageTest';
2121
import type { BoundingBox } from '../../page/pageTest';
2222

23+
const it = base.extend<{testSetup: void}>({
24+
testSetup: [async ({}, use) => {
25+
// await page.pause() disables the test-runner timeout, so we opt-out of it.
26+
process.env.PLAYWRIGHT_INTERNAL_DISABLE_PAGE_PAUSE_TEST_RUNNER_TIMEOUT = '1';
27+
await use();
28+
delete process.env.PLAYWRIGHT_INTERNAL_DISABLE_PAGE_PAUSE_TEST_RUNNER_TIMEOUT;
29+
}, { scope: 'test', auto: true }],
30+
});
31+
2332
it('should resume when closing inspector', async ({ page, recorderPageGetter, closeRecorder, mode }) => {
2433
it.skip(mode !== 'default');
2534

0 commit comments

Comments
 (0)