Skip to content

Commit 1f2d879

Browse files
authored
test: fix a few tests (#39840)
1 parent f6c656b commit 1f2d879

File tree

17 files changed

+81
-85
lines changed

17 files changed

+81
-85
lines changed

packages/playwright-core/src/server/firefox/ffPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ export class FFPage implements PageDelegate {
477477
}
478478

479479
async startScreencast(options: { width: number, height: number, quality: number }): Promise<void> {
480-
await this._session.send('Page.startScreencast', options);
480+
await this._session.send('Page.startScreencast', { width: options.width, height: options.height, quality: options.quality });
481481
}
482482

483483
async stopScreencast(): Promise<void> {

tests/config/commonFixtures.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type { ChildProcess } from 'child_process';
1919
import { execSync, spawn } from 'child_process';
2020
import net from 'net';
2121
import fs from 'fs';
22-
import { stripAnsi } from './utils';
22+
import { inheritAndCleanEnv, stripAnsi } from './utils';
2323

2424
type TestChildParams = {
2525
command: string[],
@@ -111,10 +111,7 @@ export class TestChildProcess {
111111
const command = params.shell ? params.command.join(' ') : params.command[0];
112112
const args = params.shell ? [] : params.command.slice(1);
113113
this.process = spawn(command, args, {
114-
env: {
115-
...process.env,
116-
...params.env,
117-
},
114+
env: inheritAndCleanEnv(params.env),
118115
cwd: params.cwd,
119116
shell: params.shell,
120117
// On non-windows platforms, `detached: true` makes child process a leader of a new

tests/config/remoteServer.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import path from 'path';
18+
import { inheritAndCleanEnv } from './utils';
1819
import type { BrowserType, Browser } from 'playwright-core';
1920
import type { CommonFixtures, TestChildProcess } from './commonFixtures';
2021

@@ -35,10 +36,7 @@ export class RunServer implements PlaywrightServer {
3536
command.push(`--artifacts-dir=${options.artifactsDir}`);
3637
this._process = childProcess({
3738
command,
38-
env: {
39-
...process.env,
40-
...options?.env,
41-
},
39+
env: inheritAndCleanEnv(options?.env),
4240
});
4341

4442
let wsEndpointCallback: (value: string) => void;

tests/config/utils.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,35 @@ const ansiRegex = new RegExp('[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(
229229
export function stripAnsi(str: string): string {
230230
return str.replace(ansiRegex, '');
231231
}
232+
233+
export function inheritAndCleanEnv(env: NodeJS.ProcessEnv | undefined): NodeJS.ProcessEnv {
234+
return {
235+
...process.env,
236+
// BEGIN: Reserved CI
237+
CI: undefined,
238+
BUILD_URL: undefined,
239+
CI_COMMIT_SHA: undefined,
240+
CI_JOB_URL: undefined,
241+
CI_PROJECT_URL: undefined,
242+
GITHUB_ACTIONS: undefined,
243+
GITHUB_REPOSITORY: undefined,
244+
GITHUB_RUN_ID: undefined,
245+
GITHUB_SERVER_URL: undefined,
246+
GITHUB_SHA: undefined,
247+
GITHUB_EVENT_PATH: undefined,
248+
// END: Reserved CI
249+
PW_TEST_HTML_REPORT_OPEN: undefined,
250+
PLAYWRIGHT_HTML_OPEN: undefined,
251+
PW_TEST_DEBUG_REPORTERS: undefined,
252+
PW_TEST_REPORTER: undefined,
253+
PW_TEST_REPORTER_WS_ENDPOINT: undefined,
254+
PW_TEST_SOURCE_TRANSFORM: undefined,
255+
PW_TEST_SOURCE_TRANSFORM_SCOPE: undefined,
256+
PWTEST_BOT_NAME: undefined,
257+
PWTEST_SHARD_WEIGHTS: undefined,
258+
TEST_WORKER_INDEX: undefined,
259+
TEST_PARALLEL_INDEX: undefined,
260+
NODE_OPTIONS: undefined,
261+
...env,
262+
};
263+
}

tests/electron/electronTest.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type { PageTestFixtures, PageWorkerFixtures } from '../page/pageTestApi';
2323
import type { TraceViewerFixtures } from '../config/traceViewerFixtures';
2424
import { traceViewerFixtures } from '../config/traceViewerFixtures';
2525
import { removeFolders } from '../../packages/playwright-core/lib/server/utils/fileUtils';
26+
import { inheritAndCleanEnv } from '../config/utils';
2627
export { expect } from '@playwright/test';
2728

2829
type ElectronTestFixtures = PageTestFixtures & {
@@ -63,10 +64,7 @@ export const electronTest = baseTest.extend<TraceViewerFixtures>(traceViewerFixt
6364
const app = await playwright._electron.launch({
6465
...options,
6566
args: [path.join(__dirname, appFile), ...args],
66-
env: {
67-
...process.env,
68-
PWTEST_ELECTRON_USER_DATA_DIR: userDataDir,
69-
}
67+
env: inheritAndCleanEnv({ PWTEST_ELECTRON_USER_DATA_DIR: userDataDir }),
7068
});
7169
apps.push(app);
7270
return app;

tests/library/browsercontext-locale.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ it('should propagate locale to workers', async ({ browser, browserName, server }
171171
const page = await context.newPage();
172172
await page.goto(server.EMPTY_PAGE);
173173
const [msg] = await Promise.all([
174-
page.waitForEvent('console'),
175-
page.evaluate(() => new Worker(URL.createObjectURL(new Blob(['console.log(Intl.NumberFormat().resolvedOptions().locale)'], { type: 'application/javascript' })))),
174+
page.waitForEvent('console', e => e.text().startsWith('locale:')),
175+
page.evaluate(() => new Worker(URL.createObjectURL(new Blob(['console.log("locale:" + Intl.NumberFormat().resolvedOptions().locale)'], { type: 'application/javascript' })))),
176176
]);
177177
if (browserName === 'webkit')
178-
expect(msg.text()).toContain('ru'); // Webkit on Ubuntu is "ru-RU", and on other platforms is "ru"
178+
expect(msg.text()).toContain('locale:ru'); // Webkit on Ubuntu is "ru-RU", and on other platforms is "ru"
179179
else
180-
expect(msg.text()).toBe('ru-RU');
180+
expect(msg.text()).toBe('locale:ru-RU');
181181
await context.close();
182182
});
183183

tests/library/browsercontext-reuse.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ for (const scenario of ['launch', 'connect'] as const) {
371371
});
372372
server.onMessage(message => ws.send(message));
373373
});
374-
await page.goto('about:blank');
374+
await page.goto(server.EMPTY_PAGE);
375375
await page.evaluate(host => {
376376
window.log = [];
377377
(window as any).ws1 = new WebSocket('ws://' + host + '/ws1');

tests/library/firefox/launcher.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import fs from 'fs';
1818
import { playwrightTest as it, expect } from '../../config/browserTest';
1919
import { TestServer } from '../../config/testserver';
20+
import { inheritAndCleanEnv } from '../../config/utils';
2021

2122
it('should pass firefox user preferences', async ({ browserType, mode }) => {
2223
it.skip(mode.startsWith('service'));
@@ -67,7 +68,7 @@ it('should support custom firefox policies', async ({ browserType, mode, asset,
6768
await server.waitUntilReady();
6869

6970
const browser = await browserType.launch({
70-
env: { ...process.env, 'PLAYWRIGHT_FIREFOX_POLICIES_JSON': policiesPath },
71+
env: inheritAndCleanEnv({ 'PLAYWRIGHT_FIREFOX_POLICIES_JSON': policiesPath }),
7172
});
7273

7374
const page = await browser.newPage();

tests/library/launcher.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { inheritAndCleanEnv } from '../config/utils';
1819
import { playwrightTest as it, expect } from '../config/browserTest';
1920

2021
it('should have an errors object', async ({ playwright }) => {
@@ -49,10 +50,7 @@ it('should throw a friendly error if its headed and there is no xserver on linux
4950

5051
const error: Error = await browserType.launch({
5152
headless: false,
52-
env: {
53-
...process.env,
54-
DISPLAY: undefined,
55-
},
53+
env: inheritAndCleanEnv({ DISPLAY: undefined }),
5654
}).catch(e => e);
5755
expect(error).toBeInstanceOf(Error);
5856
expect(error.message).toMatch(/Looks like you launched a headed browser without having a XServer running./);

tests/library/route-web-socket.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ test('should pattern match', async ({ page, server }) => {
258258

259259
const wsPromise = server.waitForWebSocket();
260260

261-
await page.goto('about:blank');
261+
await page.goto(server.EMPTY_PAGE);
262262
await page.evaluate(async ({ host }) => {
263263
window.log = [];
264264
(window as any).ws1 = new WebSocket('ws://' + host + '/ws');
@@ -475,7 +475,7 @@ test('should route on context', async ({ page, server }) => {
475475
});
476476
});
477477

478-
await page.goto('about:blank');
478+
await page.goto(server.EMPTY_PAGE);
479479
await page.evaluate(({ host }) => {
480480
window.log = [];
481481
(window as any).ws1 = new WebSocket('ws://' + host + '/ws1');
@@ -542,7 +542,7 @@ test('should work with no trailing slash', async ({ page, server }) => {
542542
});
543543
});
544544

545-
await page.goto('about:blank');
545+
await page.goto(server.EMPTY_PAGE);
546546
await page.evaluate(({ host }) => {
547547
window.log = [];
548548
// No trailing slash!

0 commit comments

Comments
 (0)