Skip to content
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
45 changes: 23 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@types/extract-zip": "^1.6.2",
"@types/mime": "^2.0.3",
"@types/minimatch": "^3.0.3",
"@types/node": "^10.17.28",
"@types/node": "^14.17.15",
"@types/pixelmatch": "^5.2.1",
"@types/pngjs": "^3.4.2",
"@types/progress": "^2.0.3",
Expand All @@ -116,7 +116,7 @@
"concurrently": "^6.2.1",
"cross-env": "^7.0.2",
"css-loader": "^5.2.6",
"electron": "^11.1.1",
"electron": "^12.2.1",
"eslint": "^7.31.0",
"eslint-plugin-notice": "^0.9.10",
"eslint-plugin-react-hooks": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/client/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function filePayloadToJson(payload: FilePayload): ServerFilePayload {
async function readStreamToJson(stream: fs.ReadStream): Promise<ServerFilePayload> {
const buffer = await new Promise<Buffer>((resolve, reject) => {
const chunks: Buffer[] = [];
stream.on('data', chunk => chunks.push(chunk));
stream.on('data', chunk => chunks.push(chunk as Buffer));
stream.on('end', () => resolve(Buffer.concat(chunks)));
stream.on('error', err => reject(err));
});
Expand Down
2 changes: 1 addition & 1 deletion src/client/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class StreamImpl extends Readable {
this.push(null);
}

override _destroy(error: Error | null, callback: (error: Error | null) => void): void {
override _destroy(error: Error | null, callback: (error: Error | null | undefined) => void): void {
// Stream might be destroyed after the connection was closed.
this._channel.close().catch(e => null);
super._destroy(error, callback);
Expand Down
8 changes: 4 additions & 4 deletions src/outofprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PlaywrightClient {
this._driverProcess.on('exit', this._onExit);

const connection = new Connection();
const transport = new Transport(this._driverProcess.stdin, this._driverProcess.stdout);
const transport = new Transport(this._driverProcess.stdin!, this._driverProcess.stdout!);
connection.onmessage = message => transport.send(JSON.stringify(message));
transport.onmessage = message => connection.dispatch(JSON.parse(message));
this._closePromise = new Promise(f => transport.onclose = f);
Expand All @@ -61,9 +61,9 @@ class PlaywrightClient {

async stop() {
this._driverProcess.removeListener('exit', this._onExit);
this._driverProcess.stdin.destroy();
this._driverProcess.stdout.destroy();
this._driverProcess.stderr.destroy();
this._driverProcess.stdin!.destroy();
this._driverProcess.stdout!.destroy();
this._driverProcess.stderr!.destroy();
await this._closePromise;
}
}
4 changes: 4 additions & 0 deletions src/remote/playwrightServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class PlaywrightServer {
const wsEndpoint = await new Promise<string>((resolve, reject) => {
server.listen(port, () => {
const address = server.address();
if (!address) {
reject(new Error('Could not bind server socket'));
return;
}
const wsEndpoint = typeof address === 'string' ? `${address}${path}` : `ws://127.0.0.1:${address.port}${path}`;
resolve(wsEndpoint);
}).on('error', reject);
Expand Down
8 changes: 4 additions & 4 deletions src/server/chromium/videoRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ export class VideoRecorder {
tempDirectories: [],
attemptToGracefullyClose: async () => {
progress.log('Closing stdin...');
launchedProcess.stdin.end();
launchedProcess.stdin!.end();
},
onExit: (exitCode, signal) => {
progress.log(`ffmpeg onkill exitCode=${exitCode} signal=${signal}`);
},
});
launchedProcess.stdin.on('finish', () => {
launchedProcess.stdin!.on('finish', () => {
progress.log('ffmpeg finished input.');
});
launchedProcess.stdin.on('error', () => {
launchedProcess.stdin!.on('error', () => {
progress.log('ffmpeg error.');
});
this._process = launchedProcess;
Expand Down Expand Up @@ -150,7 +150,7 @@ export class VideoRecorder {
}

private async _sendFrame(frame: Buffer) {
return new Promise(f => this._process!.stdin.write(frame, f)).then(error => {
return new Promise(f => this._process!.stdin!.write(frame, f)).then(error => {
if (error)
this._progress.log(`ffmpeg failed to write: ${error}`);
});
Expand Down
2 changes: 1 addition & 1 deletion src/server/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class Electron extends SdkObject {

function waitForLine(progress: Progress, process: childProcess.ChildProcess, regex: RegExp): Promise<RegExpMatchArray> {
return new Promise((resolve, reject) => {
const rl = readline.createInterface({ input: process.stderr });
const rl = readline.createInterface({ input: process.stderr! });
const failError = new Error('Process failed to launch!');
const listeners = [
eventsHelper.addEventListener(rl, 'line', onLine),
Expand Down
4 changes: 2 additions & 2 deletions src/test/webServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export class WebServer {
});
this._killProcess = kill;

launchedProcess.stderr.pipe(newProcessLogPrefixer()).pipe(process.stderr);
launchedProcess.stdout.on('data', () => {});
launchedProcess.stderr!.pipe(newProcessLogPrefixer()).pipe(process.stderr);
launchedProcess.stdout!.on('data', () => {});
}

private async _waitForProcess() {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/httpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import fs from 'fs';
import path from 'path';
import { Server as WebSocketServer } from 'ws';
import * as mime from 'mime';
import { assert } from './utils';

export type ServerRouteHandler = (request: http.IncomingMessage, response: http.ServerResponse) => boolean;

Expand Down Expand Up @@ -61,6 +62,7 @@ export class HttpServer {
if (typeof address === 'string') {
this._urlPrefix = address;
} else {
assert(address, 'Could not bind server socket');
this._port = address.port;
this._urlPrefix = `http://127.0.0.1:${address.port}`;
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/processLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun
shell: options.shell,
stdio,
};
const spawnedProcess = childProcess.spawn(options.command, options.args, spawnOptions);
const spawnedProcess = childProcess.spawn(options.command, options.args || [], spawnOptions);

const cleanup = async () => {
options.log(`[pid=${spawnedProcess.pid || 'N/A'}] starting temporary directories cleanup`);
Expand All @@ -98,12 +98,12 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun
}
options.log(`<launched> pid=${spawnedProcess.pid}`);

const stdout = readline.createInterface({ input: spawnedProcess.stdout });
const stdout = readline.createInterface({ input: spawnedProcess.stdout! });
stdout.on('line', (data: string) => {
options.log(`[pid=${spawnedProcess.pid}][out] ` + data);
});

const stderr = readline.createInterface({ input: spawnedProcess.stderr });
const stderr = readline.createInterface({ input: spawnedProcess.stderr! });
stderr.on('line', (data: string) => {
options.log(`[pid=${spawnedProcess.pid}][err] ` + data);
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function toMegabytes(bytes: number) {
return `${Math.round(mb * 10) / 10} Mb`;
}

export function spawnAsync(cmd: string, args: string[], options?: SpawnOptions): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
export function spawnAsync(cmd: string, args: string[], options: SpawnOptions = {}): Promise<{stdout: string, stderr: string, code: number | null, error?: Error}> {
const process = spawn(cmd, args, options);

return new Promise(resolve => {
Expand Down
2 changes: 1 addition & 1 deletion tests/config/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class TestProxy {

static async create(port: number): Promise<TestProxy> {
const proxy = new TestProxy(port);
await new Promise(f => proxy._server.listen(port, f));
await new Promise<void>(f => proxy._server.listen(port, f));
return proxy;
}

Expand Down
6 changes: 4 additions & 2 deletions tests/page/frame-evaluate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ function expectContexts(pageImpl, count, browserName) {
expect(pageImpl._delegate._contextIdToContext.size).toBe(count);
}

it('should dispose context on navigation', async ({ page, server, toImpl, browserName, mode }) => {
it('should dispose context on navigation', async ({ page, server, toImpl, browserName, mode, isElectron }) => {
it.skip(mode !== 'default');
it.skip(isElectron);

await page.goto(server.PREFIX + '/frames/one-frame.html');
expect(page.frames().length).toBe(2);
Expand All @@ -52,8 +53,9 @@ it('should dispose context on navigation', async ({ page, server, toImpl, browse
expectContexts(toImpl(page), 2, browserName);
});

it('should dispose context on cross-origin navigation', async ({ page, server, toImpl, browserName, mode }) => {
it('should dispose context on cross-origin navigation', async ({ page, server, toImpl, browserName, mode, isElectron }) => {
it.skip(mode !== 'default');
it.skip(isElectron);

await page.goto(server.PREFIX + '/frames/one-frame.html');
expect(page.frames().length).toBe(2);
Expand Down
3 changes: 2 additions & 1 deletion tests/page/interception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ it('should work with navigation', async ({ page, server }) => {
expect(requests.get('style.css').isNavigationRequest()).toBe(false);
});

it('should intercept after a service worker', async ({ page, server, isAndroid }) => {
it('should intercept after a service worker', async ({ page, server, isAndroid, isElectron }) => {
it.skip(isAndroid);
it.skip(isElectron);

await page.goto(server.PREFIX + '/serviceworkers/fetchdummy/sw.html');
await page.evaluate(() => window['activationPromise']);
Expand Down
3 changes: 2 additions & 1 deletion tests/page/page-event-request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ it('should fire for fetches', async ({ page, server }) => {
expect(requests.length).toBe(2);
});

it('should report requests and responses handled by service worker', async ({ page, server, isAndroid }) => {
it('should report requests and responses handled by service worker', async ({ page, server, isAndroid, isElectron }) => {
it.fixme(isAndroid);
it.fixme(isElectron);

await page.goto(server.PREFIX + '/serviceworkers/fetchdummy/sw.html');
await page.evaluate(() => window['activationPromise']);
Expand Down
3 changes: 2 additions & 1 deletion tests/page/page-goto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ it('should fail when navigating and show the url at the error message', async fu
expect(error.message).toContain(url);
});

it('should be able to navigate to a page controlled by service worker', async ({ page, server }) => {
it('should be able to navigate to a page controlled by service worker', async ({ page, server, isElectron }) => {
it.skip(isElectron);
await page.goto(server.PREFIX + '/serviceworkers/fetch/sw.html');
await page.evaluate(() => window['activationPromise']);
await page.goto(server.PREFIX + '/serviceworkers/fetch/sw.html');
Expand Down
3 changes: 2 additions & 1 deletion tests/page/page-screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ it.describe('page screenshot', () => {
expect(screenshot).toMatchSnapshot('screenshot-canvas.png', { threshold: 0.4 });
});

it('should capture canvas changes', async ({ page, browserName, isMac }) => {
it('should capture canvas changes', async ({ page, browserName, isMac, isElectron }) => {
it.fail(browserName === 'webkit' && isMac, 'https://github.com/microsoft/playwright/issues/8796');
it.skip(isElectron);
await page.goto('data:text/html,<canvas></canvas>');
await page.evaluate(() => {
const canvas = document.querySelector('canvas');
Expand Down
8 changes: 4 additions & 4 deletions tests/playwright-test/web-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ test('should be able to specify the baseURL without the server', async ({ runInl
const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
res.end('<html><body>hello</body></html>');
});
await new Promise(resolve => server.listen(port, resolve));
await new Promise<void>(resolve => server.listen(port, resolve));
const result = await runInlineTest({
'test.spec.ts': `
const { test } = pwt;
Expand Down Expand Up @@ -167,7 +167,7 @@ test('should be able to use an existing server when reuseExistingServer:true ',
const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
res.end('<html><body>hello</body></html>');
});
await new Promise(resolve => server.listen(port, resolve));
await new Promise<void>(resolve => server.listen(port, resolve));
const result = await runInlineTest({
'test.spec.ts': `
const { test } = pwt;
Expand Down Expand Up @@ -200,7 +200,7 @@ test('should throw when a server is already running on the given port and strict
const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
res.end('<html><body>hello</body></html>');
});
await new Promise(resolve => server.listen(port, resolve));
await new Promise<void>(resolve => server.listen(port, resolve));
const result = await runInlineTest({
'test.spec.ts': `
const { test } = pwt;
Expand Down Expand Up @@ -232,7 +232,7 @@ for (const host of ['localhost', '127.0.0.1', '0.0.0.0']) {
const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
res.end('<html><body>hello</body></html>');
});
await new Promise(resolve => server.listen(port, host, resolve));
await new Promise<void>(resolve => server.listen(port, host, resolve));
try {
const result = await runInlineTest({
'test.spec.ts': `
Expand Down
2 changes: 1 addition & 1 deletion tests/port-forwarding-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function startTestServer() {
const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
res.end('<html><body>from-retargeted-server</body></html>');
});
await new Promise(resolve => server.listen(0, resolve));
await new Promise<void>(resolve => server.listen(0, resolve));
return {
testServerPort: (server.address() as net.AddressInfo).port,
stopTestServer: () => server.close()
Expand Down
Loading