fix: use LazyArg for puppeteer utilities (#9575)

This PR fixes the following edge case:

 - `const oldPromise = world.puppeteerUtil`. 
- setContext occurs but context is immediately destroyed, i.e.
`world.#puppeteerUtil === oldPromise` is not resolved.
- clearContext occurs due to destruction, i.e. `world.#puppeteerUtil` is
replaced (`world.#puppeteerUtil !== oldPromise`).
 - `oldPromise` never resolves.
This commit is contained in:
jrandolf
2023-01-25 23:56:33 -08:00
committed by GitHub
parent 0b717000ac
commit 496658f029
7 changed files with 52 additions and 36 deletions

View File

@@ -16,6 +16,7 @@
import expect from 'expect';
import {PUPPETEER_WORLD} from 'puppeteer-core/internal/common/IsolatedWorlds.js';
import {LazyArg} from 'puppeteer-core/internal/common/LazyArg.js';
import {
getTestState,
setupTestBrowserHooks,
@@ -45,7 +46,9 @@ describe('PuppeteerUtil tests', function () {
({createFunction}, fnString) => {
return createFunction(fnString)(4);
},
await world.puppeteerUtil,
LazyArg.create(() => {
return world.puppeteerUtil;
}),
(() => {
return 4;
}).toString()