@augment-vir/test
Version:
A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.
24 lines (23 loc) • 788 B
JavaScript
import { assertTestContext, TestEnv, } from '../augments/universal-testing-suite/universal-test-context.js';
/**
* Run the trigger and catch a new page _or_ a new download (sometimes Playwright inconsistently
* chooses on or the other).
*
* @category Internal
*/
export async function handleNewPageOrDownload(testContext, trigger) {
assertTestContext(testContext, TestEnv.Playwright);
const openOrDownload = Promise.race([
testContext.page
.context()
.waitForEvent('page')
.then((result) => {
return { newPage: result };
}),
testContext.page.waitForEvent('download').then((result) => {
return { download: result };
}),
]);
await trigger();
return await openOrDownload;
}