chore: fix compatibility to the domain module (#3851)
This commit is contained in:
parent
b8e90a5582
commit
c175dad290
|
|
@ -62,6 +62,8 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
|
|||
return obj.addListener;
|
||||
if (prop === 'removeEventListener')
|
||||
return obj.removeListener;
|
||||
if (prop === 'domain') // https://github.com/microsoft/playwright/issues/3848
|
||||
return obj.domain;
|
||||
return (params: any) => this._connection.sendMessageToServer(this._type, guid, String(prop), params);
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -15,9 +15,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { it, expect, options } from './playwright.fixtures';
|
||||
import domain from 'domain';
|
||||
import { it, expect, options, playwrightFixtures } from './playwright.fixtures';
|
||||
import type { ChromiumBrowser } from '..';
|
||||
|
||||
playwrightFixtures.defineWorkerFixture('domain', async ({ }, test) => {
|
||||
const local = domain.create();
|
||||
local.run(() => { });
|
||||
let err;
|
||||
local.on('error', e => err = e);
|
||||
local.enter();
|
||||
await test(null);
|
||||
if (err)
|
||||
throw err;
|
||||
});
|
||||
|
||||
it('should work', async ({browser}) => {
|
||||
expect(!!browser['_connection']).toBeTruthy();
|
||||
});
|
||||
|
|
@ -144,6 +156,14 @@ it('should scope browser handles', async ({browserType, defaultBrowserOptions})
|
|||
await expectScopeState(browserType, GOLDEN_PRECONDITION);
|
||||
});
|
||||
|
||||
it('should work with the domain module', async ({ domain, browserType }) => {
|
||||
const browser = await browserType.launch();
|
||||
const page = await browser.newPage();
|
||||
const result = await page.evaluate(() => 1 + 1);
|
||||
expect(result).toBe(2);
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
async function expectScopeState(object, golden) {
|
||||
golden = trimGuids(golden);
|
||||
const remoteState = trimGuids(await object._channel.debugScopeState());
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ type PlaywrightWorkerFixtures = {
|
|||
browserType: BrowserType<Browser>;
|
||||
browser: Browser;
|
||||
httpService: {server: TestServer, httpsServer: TestServer}
|
||||
domain: void;
|
||||
toImpl: (rpcObject: any) => any;
|
||||
isChromium: boolean;
|
||||
isFirefox: boolean;
|
||||
|
|
|
|||
Loading…
Reference in a new issue