Skip to content

Commit

Permalink
test: fix flakiness of certain extension tests (puppeteer#3011)
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov authored Aug 1, 2018
1 parent 95d867a commit 9c96a92
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions test/headful.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 9c96a92

Please sign in to comment.