test: fix flakiness of certain extension tests (#3011)
This commit is contained in:
parent
95d867aaac
commit
9c96a9283f
@ -19,6 +19,20 @@ const os = require('os');
|
||||
|
||||
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||
|
||||
function waitForBackgroundPageTarget(browser) {
|
||||
const target = browser.targets().find(target => target.type() === 'background_page');
|
||||
if (target)
|
||||
return Promise.resolve(target);
|
||||
return new Promise(resolve => {
|
||||
browser.on('targetcreated', function listener(target) {
|
||||
if (target.type() !== 'background_page')
|
||||
return;
|
||||
browser.removeListener(listener);
|
||||
resolve(target);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBrowserOptions}) {
|
||||
const {describe, xdescribe, fdescribe} = testRunner;
|
||||
const {it, fit, xit} = testRunner;
|
||||
@ -42,19 +56,17 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro
|
||||
});
|
||||
|
||||
describe('HEADFUL', function() {
|
||||
it('background_page target type should be available', async({browser}) => {
|
||||
it('background_page target type should be available', async() => {
|
||||
const browserWithExtension = await puppeteer.launch(extensionOptions);
|
||||
const page = await browserWithExtension.newPage();
|
||||
const targets = await browserWithExtension.targets();
|
||||
const backgroundPageTarget = targets.find(target => target.type() === 'background_page');
|
||||
const backgroundPageTarget = await waitForBackgroundPageTarget(browserWithExtension);
|
||||
await page.close();
|
||||
await browserWithExtension.close();
|
||||
expect(backgroundPageTarget).toBeTruthy();
|
||||
});
|
||||
it('target.page() should return a background_page', async({browser}) => {
|
||||
it('target.page() should return a background_page', async({}) => {
|
||||
const browserWithExtension = await puppeteer.launch(extensionOptions);
|
||||
const targets = await browserWithExtension.targets();
|
||||
const backgroundPageTarget = targets.find(target => target.type() === 'background_page');
|
||||
const backgroundPageTarget = await waitForBackgroundPageTarget(browserWithExtension);
|
||||
const page = await backgroundPageTarget.page();
|
||||
expect(await page.evaluate(() => 2 * 3)).toBe(6);
|
||||
await browserWithExtension.close();
|
||||
|
Loading…
Reference in New Issue
Block a user