From 28e236f1a643c8409191acc620aa4f4c10607482 Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Tue, 5 Jul 2022 14:42:55 +0200 Subject: [PATCH] chore: use --parallel (#8612) --- test/src/cookies.spec.ts | 3 --- test/src/coverage.spec.ts | 4 +-- test/src/defaultbrowsercontext.spec.ts | 1 - test/src/golden-utils.ts | 4 +-- test/src/mocha-utils.ts | 21 ++++++++++------ test/src/utils.ts | 2 +- utils/testserver/src/index.ts | 34 +++++++++++++++++--------- 7 files changed, 41 insertions(+), 28 deletions(-) diff --git a/test/src/cookies.spec.ts b/test/src/cookies.spec.ts index 428b54deec2..cd06ba7ad2c 100644 --- a/test/src/cookies.spec.ts +++ b/test/src/cookies.spec.ts @@ -51,7 +51,6 @@ describe('Cookie specs', () => { httpOnly: false, secure: false, session: true, - sourcePort: 8907, sourceScheme: 'NonSecure', }, ]); @@ -112,7 +111,6 @@ describe('Cookie specs', () => { httpOnly: false, secure: false, session: true, - sourcePort: 8907, sourceScheme: 'NonSecure', }, { @@ -126,7 +124,6 @@ describe('Cookie specs', () => { httpOnly: false, secure: false, session: true, - sourcePort: 8907, sourceScheme: 'NonSecure', }, ]); diff --git a/test/src/coverage.spec.ts b/test/src/coverage.spec.ts index 9da30fb730e..e72789b1cff 100644 --- a/test/src/coverage.spec.ts +++ b/test/src/coverage.spec.ts @@ -128,7 +128,7 @@ describe('Coverage specs', function () { await page.goto(server.PREFIX + '/jscoverage/involved.html'); const coverage = await page.coverage.stopJSCoverage(); expect( - JSON.stringify(coverage, null, 2).replace(/:\d{4}\//g, ':/') + JSON.stringify(coverage, null, 2).replace(/:\d{4,5}\//g, ':/') ).toBeGolden('jscoverage-involved.txt'); }); // @see https://crbug.com/990945 @@ -267,7 +267,7 @@ describe('Coverage specs', function () { await page.goto(server.PREFIX + '/csscoverage/involved.html'); const coverage = await page.coverage.stopCSSCoverage(); expect( - JSON.stringify(coverage, null, 2).replace(/:\d{4}\//g, ':/') + JSON.stringify(coverage, null, 2).replace(/:\d{4,5}\//g, ':/') ).toBeGolden('csscoverage-involved.txt'); }); it('should work with empty stylesheets', async () => { diff --git a/test/src/defaultbrowsercontext.spec.ts b/test/src/defaultbrowsercontext.spec.ts index 84d5729d341..fea692932ea 100644 --- a/test/src/defaultbrowsercontext.spec.ts +++ b/test/src/defaultbrowsercontext.spec.ts @@ -44,7 +44,6 @@ describe('DefaultBrowserContext', function () { httpOnly: false, secure: false, session: true, - sourcePort: 8907, sourceScheme: 'NonSecure', }, ]); diff --git a/test/src/golden-utils.ts b/test/src/golden-utils.ts index 182b434d4ff..bb393c69fbb 100644 --- a/test/src/golden-utils.ts +++ b/test/src/golden-utils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import assert from 'assert'; -import diff from 'diff'; +import {diffLines} from 'diff'; import fs from 'fs'; import jpeg from 'jpeg-js'; import mime from 'mime'; @@ -90,7 +90,7 @@ const compareText = ( if (expected === actual) { return; } - const result = diff.diffLines(expected, actual); + const result = diffLines(expected, actual); const html = result.reduce((text, change) => { text += change.added ? `${change.value}` diff --git a/test/src/mocha-utils.ts b/test/src/mocha-utils.ts index ef915199e86..473cd989e0d 100644 --- a/test/src/mocha-utils.ts +++ b/test/src/mocha-utils.ts @@ -39,16 +39,16 @@ const setupServer = async () => { const assetsPath = path.join(__dirname, '../assets'); const cachedPath = path.join(__dirname, '../assets', 'cached'); - const port = 8907; - const server = await TestServer.create(assetsPath, port); + const server = await TestServer.create(assetsPath); + const port = server.port; server.enableHTTPCache(cachedPath); server.PORT = port; server.PREFIX = `http://localhost:${port}`; server.CROSS_PROCESS_PREFIX = `http://127.0.0.1:${port}`; server.EMPTY_PAGE = `http://localhost:${port}/empty.html`; - const httpsPort = port + 1; - const httpsServer = await TestServer.createHTTPS(assetsPath, httpsPort); + const httpsServer = await TestServer.createHTTPS(assetsPath); + const httpsPort = httpsServer.port; httpsServer.enableHTTPCache(cachedPath); httpsServer.PORT = httpsPort; httpsServer.PREFIX = `https://localhost:${httpsPort}`; @@ -261,14 +261,16 @@ export const describeChromeOnly = ( } }; -console.log( - `Running unit tests with: +if (process.env['MOCHA_WORKER_ID'] === '0') { + console.log( + `Running unit tests with: -> product: ${product} -> binary: ${ defaultBrowserOptions.executablePath || path.relative(process.cwd(), puppeteer.executablePath()) }` -); + ); +} process.on('unhandledRejection', reason => { throw reason; @@ -357,7 +359,10 @@ export const expectCookieEquals = ( }); } - expect(cookies).toEqual(expectedCookies); + expect(cookies.length).toBe(expectedCookies.length); + for (let i = 0; i < cookies.length; i++) { + expect(cookies[i]).toMatchObject(expectedCookies[i]!); + } }; export const shortWaitForArrayToHaveAtLeastNElements = async ( diff --git a/test/src/utils.ts b/test/src/utils.ts index 30333aa7c26..9c49099ab0e 100644 --- a/test/src/utils.ts +++ b/test/src/utils.ts @@ -116,7 +116,7 @@ export const dumpFrames = ( indentation?: string ): Array => { indentation = indentation || ''; - let description = frame.url().replace(/:\d{4}\//, ':/'); + let description = frame.url().replace(/:\d{4,5}\//, ':/'); if (frame.name()) { description += ' (' + frame.name() + ')'; } diff --git a/utils/testserver/src/index.ts b/utils/testserver/src/index.ts index 7d1ed63313d..c98ed9b4d01 100644 --- a/utils/testserver/src/index.ts +++ b/utils/testserver/src/index.ts @@ -29,6 +29,7 @@ import { ServerOptions as HttpsServerOptions, } from 'https'; import {getType as getMimeType} from 'mime'; +import {AddressInfo} from 'net'; import {join} from 'path'; import {Duplex} from 'stream'; import {Server as WebSocketServer, WebSocket} from 'ws'; @@ -65,27 +66,35 @@ export class TestServer { #gzipRoutes = new Set(); #requestSubscribers = new Map(); - static async create(dirPath: string, port: number): Promise { - const server = new TestServer(dirPath, port); - await new Promise(x => { - return server.#server.once('listening', x); + static async create(dirPath: string): Promise { + let res!: (value: unknown) => void; + const promise = new Promise(resolve => { + res = resolve; }); + const server = new TestServer(dirPath); + server.#server.once('listening', res); + server.#server.listen(0); + await promise; return server; } - static async createHTTPS(dirPath: string, port: number): Promise { - const server = new TestServer(dirPath, port, { + static async createHTTPS(dirPath: string): Promise { + let res!: (value: unknown) => void; + const promise = new Promise(resolve => { + res = resolve; + }); + const server = new TestServer(dirPath, { key: readFileSync(join(__dirname, '..', 'key.pem')), cert: readFileSync(join(__dirname, '..', 'cert.pem')), passphrase: 'aaaa', }); - await new Promise(x => { - return server.#server.once('listening', x); - }); + server.#server.once('listening', res); + server.#server.listen(0); + await promise; return server; } - constructor(dirPath: string, port: number, sslOptions?: HttpsServerOptions) { + constructor(dirPath: string, sslOptions?: HttpsServerOptions) { this.#dirPath = dirPath; if (sslOptions) { @@ -96,7 +105,6 @@ export class TestServer { this.#server.on('connection', this.#onServerConnection); this.#wsServer = new WebSocketServer({server: this.#server}); this.#wsServer.on('connection', this.#onWebSocketConnection); - this.#server.listen(port); } #onServerConnection = (connection: Duplex): void => { @@ -113,6 +121,10 @@ export class TestServer { }); }; + get port(): number { + return (this.#server.address() as AddressInfo).port; + } + enableHTTPCache(pathPrefix: string): void { this.#cachedPathPrefix = pathPrefix; }