test: modify remote specs to allow skip or only (#41620)

This commit is contained in:
Shelley Vohr 2024-03-19 10:49:24 +01:00 committed by GitHub
parent 193e162ec6
commit daecbb90fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -176,8 +176,8 @@ export function useRemoteContext (opts?: any) {
}); });
} }
export async function itremote (name: string, fn: Function, args?: any[]) { async function runRemote (type: 'skip' | 'none' | 'only', name: string, fn: Function, args?: any[]) {
it(name, async () => { const wrapped = async () => {
const w = await getRemoteContext(); const w = await getRemoteContext();
const { ok, message } = await w.webContents.executeJavaScript(`(async () => { const { ok, message } = await w.webContents.executeJavaScript(`(async () => {
try { try {
@ -192,9 +192,30 @@ export async function itremote (name: string, fn: Function, args?: any[]) {
} }
})()`); })()`);
if (!ok) { throw new AssertionError(message); } if (!ok) { throw new AssertionError(message); }
}); };
let runFn: any = it;
if (type === 'only') {
runFn = it.only;
} else if (type === 'skip') {
runFn = it.skip;
}
runFn(name, wrapped);
} }
export const itremote = Object.assign(
(name: string, fn: Function, args?: any[]) => {
runRemote('none', name, fn, args);
}, {
only: (name: string, fn: Function, args?: any[]) => {
runRemote('only', name, fn, args);
},
skip: (name: string, fn: Function, args?: any[]) => {
runRemote('skip', name, fn, args);
}
});
export async function listen (server: http.Server | https.Server | http2.Http2SecureServer) { export async function listen (server: http.Server | https.Server | http2.Http2SecureServer) {
const hostname = '127.0.0.1'; const hostname = '127.0.0.1';
await new Promise<void>(resolve => server.listen(0, hostname, () => resolve())); await new Promise<void>(resolve => server.listen(0, hostname, () => resolve()));