test: convert functions to async & eliminate duplicates (#37316)

test: convert functions to async

Co-authored-by: Milan Burda <miburda@microsoft.com>
This commit is contained in:
Milan Burda 2023-02-20 12:30:57 +01:00 committed by GitHub
parent 969665eaa2
commit f97d68c4bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 225 additions and 343 deletions

View file

@ -1,7 +1,10 @@
import * as childProcess from 'child_process';
import * as path from 'path';
import * as http from 'http';
import * as https from 'https';
import * as net from 'net';
import * as v8 from 'v8';
import * as url from 'url';
import { SuiteFunction, TestFunction } from 'mocha';
import { BrowserWindow } from 'electron/main';
import { AssertionError } from 'chai';
@ -191,3 +194,11 @@ export async function itremote (name: string, fn: Function, args?: any[]) {
if (!ok) { throw new AssertionError(message); }
});
}
export async function listen (server: http.Server | https.Server) {
const hostname = '127.0.0.1';
await new Promise<void>(resolve => server.listen(0, hostname, () => resolve()));
const { port } = server.address() as net.AddressInfo;
const protocol = (server instanceof https.Server) ? 'https' : 'http';
return { port, url: url.format({ protocol, hostname, port }) };
}