chore: use --parallel (#8612)

This commit is contained in:
jrandolf 2022-07-05 14:42:55 +02:00 committed by GitHub
parent 45eb2c607f
commit 28e236f1a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 28 deletions

View File

@ -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',
},
]);

View File

@ -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, ':<PORT>/')
JSON.stringify(coverage, null, 2).replace(/:\d{4,5}\//g, ':<PORT>/')
).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, ':<PORT>/')
JSON.stringify(coverage, null, 2).replace(/:\d{4,5}\//g, ':<PORT>/')
).toBeGolden('csscoverage-involved.txt');
});
it('should work with empty stylesheets', async () => {

View File

@ -44,7 +44,6 @@ describe('DefaultBrowserContext', function () {
httpOnly: false,
secure: false,
session: true,
sourcePort: 8907,
sourceScheme: 'NonSecure',
},
]);

View File

@ -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
? `<span class='ins'>${change.value}</span>`

View File

@ -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 (

View File

@ -116,7 +116,7 @@ export const dumpFrames = (
indentation?: string
): Array<string> => {
indentation = indentation || '';
let description = frame.url().replace(/:\d{4}\//, ':<PORT>/');
let description = frame.url().replace(/:\d{4,5}\//, ':<PORT>/');
if (frame.name()) {
description += ' (' + frame.name() + ')';
}

View File

@ -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<string>();
#requestSubscribers = new Map<string, Subscriber>();
static async create(dirPath: string, port: number): Promise<TestServer> {
const server = new TestServer(dirPath, port);
await new Promise(x => {
return server.#server.once('listening', x);
static async create(dirPath: string): Promise<TestServer> {
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<TestServer> {
const server = new TestServer(dirPath, port, {
static async createHTTPS(dirPath: string): Promise<TestServer> {
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;
}