Skip to content

Commit 9e45b45

Browse files
authored
test: move PW_CLOCK handling into test harness (#41214)
1 parent f95684a commit 9e45b45

23 files changed

Lines changed: 37 additions & 78 deletions

packages/playwright/src/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -418,17 +418,6 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures, UtilityTestFixt
418418
} : {};
419419
const context = await browser.newContext({ ...videoOptions, ...options }) as BrowserContextImpl;
420420

421-
if (process.env.PW_CLOCK === 'frozen') {
422-
await context._wrapApiCall(async () => {
423-
await context.clock.install({ time: 0 });
424-
await context.clock.pauseAt(1000);
425-
}, { internal: true });
426-
} else if (process.env.PW_CLOCK === 'realtime') {
427-
await context._wrapApiCall(async () => {
428-
await context.clock.install({ time: 0 });
429-
}, { internal: true });
430-
}
431-
432421
let closed = false;
433422
const close = async () => {
434423
if (closed)

tests/config/browserTest.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ type BrowserTestTestFixtures = PageTestFixtures & {
5959
autoSkipBidiTest: void;
6060
};
6161

62-
const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>({
62+
type ContextFactory = (options?: BrowserContextOptions) => Promise<{ context: BrowserContext, close: () => Promise<void> }>;
63+
64+
const test = baseTest.extend<BrowserTestTestFixtures & { _contextFactory: ContextFactory }, BrowserTestWorkerFixtures>({
6365
browserVersion: [async ({ browser }, run) => {
6466
await run(browser.version());
6567
}, { scope: 'worker' }],
@@ -115,15 +117,32 @@ const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>
115117
await use(browserName === 'webkit' && (hostPlatform.startsWith('debian11') || hostPlatform.startsWith('ubuntu20.04') || (isMac && macVersion < 15)));
116118
}, { scope: 'worker' }],
117119

118-
contextFactory: async ({ _contextFactory }: any, run) => {
120+
_contextFactory: async ({ _contextFactory }, use) => {
121+
await use(async options => {
122+
const result = await _contextFactory(options);
123+
const { context } = result;
124+
if (process.env.PW_CLOCK === 'frozen') {
125+
await (context as any)._wrapApiCall(async () => {
126+
await context.clock.install({ time: 0 });
127+
await context.clock.pauseAt(1000);
128+
}, { internal: true });
129+
} else if (process.env.PW_CLOCK === 'realtime') {
130+
await (context as any)._wrapApiCall(async () => {
131+
await context.clock.install({ time: 0 });
132+
}, { internal: true });
133+
}
134+
return result;
135+
});
136+
},
137+
138+
contextFactory: async ({ _contextFactory }, run) => {
119139
await run(async options => {
120140
const { context } = await _contextFactory(options);
121141
return context;
122142
});
123143
},
124144

125145
createUserDataDir: async ({ mode }, run) => {
126-
test.skip(mode.startsWith('service'));
127146
const dirs: string[] = [];
128147
// We do not put user data dir in testOutputPath,
129148
// because we do not want to upload them as test result artifacts.

tests/library/browsercontext-proxy.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import { browserTest as it, expect } from '../config/browserTest';
1818

19-
it.skip(({ mode }) => mode.startsWith('service'));
20-
2119
it.beforeEach(({ server }) => {
2220
server.setRoute('/target.html', async (req, res) => {
2321
res.end('<html><title>Served by the proxy</title></html>');

tests/library/browsercontext-webauthn.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import { browserTest as it, expect } from '../config/browserTest';
1818

19-
it.skip(({ mode }) => mode.startsWith('service'));
20-
2119
it('should not intercept navigator.credentials without install()', async ({ contextFactory, server }) => {
2220
const context = await contextFactory();
2321
// Seed a credential, but do not install the interceptor.

tests/library/browsertype-basic.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { playwrightTest as test, expect } from '../config/browserTest';
2020

2121
test('browserType.executablePath should work', async ({ browserType, channel, mode }) => {
2222
test.skip(!!channel, 'We skip browser download when testing a channel');
23-
test.skip(mode.startsWith('service'));
2423
test.skip(!!(browserType as any)._playwright._defaultLaunchOptions.executablePath, 'Skip with custom executable path');
2524

2625
const executablePath = browserType.executablePath();

tests/library/browsertype-launch.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ it('should throw if page argument is passed', async ({ browserType, browserName,
6262
});
6363

6464
it('should reject if launched browser fails immediately', async ({ mode, browserType, asset, channel }) => {
65-
it.skip(mode.startsWith('service'));
66-
6765
const error = await browserType.launch({ executablePath: asset('dummy_bad_browser_executable.js') }).catch(e => e);
6866
if (channel === 'webkit-wsl')
6967
expect(error.message).toContain('Cannot specify executablePath when using the \"webkit-wsl\" channel.');
@@ -72,7 +70,6 @@ it('should reject if launched browser fails immediately', async ({ mode, browser
7270
});
7371

7472
it('should reject if executable path is invalid', async ({ browserType, mode, channel }) => {
75-
it.skip(mode.startsWith('service'), 'on service mode we dont allow passing custom executable path');
7673
let waitError: Error | undefined;
7774
await browserType.launch({ executablePath: 'random-invalid-path' }).catch(e => waitError = e);
7875
if (channel === 'webkit-wsl')
@@ -102,8 +99,6 @@ it('should handle exception and report launch log', async ({ browserType, mode }
10299
});
103100

104101
it('should accept objects as options', async ({ mode, browserType }) => {
105-
it.skip(mode.startsWith('service'));
106-
107102
// @ts-expect-error process is not a real option.
108103
const browser = await browserType.launch({ process });
109104
await browser.close();

tests/library/capabilities.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ it('should respect CSP @smoke', async ({ page, server }) => {
6868

6969
it('should play video @smoke', async ({ page, asset, browserName, isWindows, isLinux, mode }) => {
7070
it.skip(browserName === 'webkit' && isWindows, 'passes locally but fails on GitHub Action bot, apparently due to a Media Pack issue in the Windows Server');
71-
it.skip(mode.startsWith('service'));
7271

7372
// Safari only plays mp4 so we test WebKit with an .mp4 clip.
7473
const fileName = browserName === 'webkit' ? 'video_mp4.html' : 'video.html';
@@ -82,7 +81,6 @@ it('should play video @smoke', async ({ page, asset, browserName, isWindows, isL
8281

8382
it('should play webm video @smoke', async ({ page, asset, browserName, platform, macVersion, mode }) => {
8483
it.skip(browserName === 'webkit' && platform === 'win32', 'not supported');
85-
it.skip(mode.startsWith('service'));
8684

8785
const absolutePath = asset('video_webm.html');
8886
// Our test server doesn't support range requests required to play on Mac,

tests/library/debug-controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const test = baseTest.extend<Fixtures>({
7676
});
7777

7878
test.slow(true, 'All controller tests are slow');
79-
test.skip(({ mode }) => mode.startsWith('service') || mode === 'driver');
79+
test.skip(({ mode }) => mode === 'driver');
8080

8181
// Force a separate worker to avoid registered selector engines from other tests.
8282
// See https://github.com/microsoft/playwright/pull/37103.

tests/library/download.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,6 @@ it('should save to user-specified path', async ({ browser, server, mode }, testI
672672
page.waitForEvent('download'),
673673
page.click('a')
674674
]);
675-
if (mode.startsWith('service')) {
676-
const error = await download.path().catch(e => e);
677-
expect(error.message).toContain('Path is not available when connecting remotely. Use saveAs() to save a local copy.');
678-
}
679675
const userPath = testInfo.outputPath('download.txt');
680676
await download.saveAs(userPath);
681677
expect(fs.existsSync(userPath)).toBeTruthy();

tests/library/firefox/launcher.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { TestServer } from '../../config/testserver';
2020
import { inheritAndCleanEnv } from '../../config/utils';
2121

2222
it('should pass firefox user preferences', async ({ browserType, mode }) => {
23-
it.skip(mode.startsWith('service'));
2423
const browser = await browserType.launch({
2524
firefoxUserPrefs: {
2625
'network.proxy.type': 1,
@@ -35,7 +34,6 @@ it('should pass firefox user preferences', async ({ browserType, mode }) => {
3534
});
3635

3736
it('should pass firefox user preferences in persistent', async ({ mode, launchPersistent }) => {
38-
it.skip(mode.startsWith('service'));
3937
const { page } = await launchPersistent({
4038
firefoxUserPrefs: {
4139
'network.proxy.type': 1,
@@ -48,8 +46,6 @@ it('should pass firefox user preferences in persistent', async ({ mode, launchPe
4846
});
4947

5048
it('should support custom firefox policies', async ({ browserType, mode, asset, loopback }, testInfo) => {
51-
it.skip(mode.startsWith('service'));
52-
5349
const policies = {
5450
'policies': {
5551
'Certificates': {

0 commit comments

Comments
 (0)