Skip to content

Commit 7a60746

Browse files
JoelEinbinderaslushnikov
authored andcommitted
fix(tests): background page tests should wait for the page (#4769)
1 parent 62f5dc7 commit 7a60746

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

test/headful.spec.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@ const mkdtempAsync = helper.promisify(fs.mkdtemp);
2525

2626
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
2727

28-
function waitForBackgroundPageTarget(browser) {
29-
const target = browser.targets().find(target => target.type() === 'background_page');
30-
if (target)
31-
return Promise.resolve(target);
32-
return new Promise(resolve => {
33-
browser.on('targetcreated', function listener(target) {
34-
if (target.type() !== 'background_page')
35-
return;
36-
browser.removeListener(listener);
37-
resolve(target);
38-
});
39-
});
40-
}
41-
4228
module.exports.addTests = function({testRunner, expect, puppeteer, defaultBrowserOptions}) {
4329
const {describe, xdescribe, fdescribe} = testRunner;
4430
const {it, fit, xit} = testRunner;
@@ -63,14 +49,14 @@ module.exports.addTests = function({testRunner, expect, puppeteer, defaultBrowse
6349
it('background_page target type should be available', async() => {
6450
const browserWithExtension = await puppeteer.launch(extensionOptions);
6551
const page = await browserWithExtension.newPage();
66-
const backgroundPageTarget = await waitForBackgroundPageTarget(browserWithExtension);
52+
const backgroundPageTarget = await browserWithExtension.waitForTarget(target => target.type() === 'background_page');
6753
await page.close();
6854
await browserWithExtension.close();
6955
expect(backgroundPageTarget).toBeTruthy();
7056
});
7157
it('target.page() should return a background_page', async({}) => {
7258
const browserWithExtension = await puppeteer.launch(extensionOptions);
73-
const backgroundPageTarget = await waitForBackgroundPageTarget(browserWithExtension);
59+
const backgroundPageTarget = await browserWithExtension.waitForTarget(target => target.type() === 'background_page');
7460
const page = await backgroundPageTarget.page();
7561
expect(await page.evaluate(() => 2 * 3)).toBe(6);
7662
expect(await page.evaluate(() => window.MAGIC)).toBe(42);

0 commit comments

Comments
 (0)