Skip to content

Commit c175dad

Browse files
authored
chore: fix compatibility to the domain module (#3851)
1 parent b8e90a5 commit c175dad

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/client/channelOwner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
6262
return obj.addListener;
6363
if (prop === 'removeEventListener')
6464
return obj.removeListener;
65+
if (prop === 'domain') // https://github.com/microsoft/playwright/issues/3848
66+
return obj.domain;
6567
return (params: any) => this._connection.sendMessageToServer(this._type, guid, String(prop), params);
6668
},
6769
});

test/channels.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { it, expect, options } from './playwright.fixtures';
18+
import domain from 'domain';
19+
import { it, expect, options, playwrightFixtures } from './playwright.fixtures';
1920
import type { ChromiumBrowser } from '..';
2021

22+
playwrightFixtures.defineWorkerFixture('domain', async ({ }, test) => {
23+
const local = domain.create();
24+
local.run(() => { });
25+
let err;
26+
local.on('error', e => err = e);
27+
local.enter();
28+
await test(null);
29+
if (err)
30+
throw err;
31+
});
32+
2133
it('should work', async ({browser}) => {
2234
expect(!!browser['_connection']).toBeTruthy();
2335
});
@@ -144,6 +156,14 @@ it('should scope browser handles', async ({browserType, defaultBrowserOptions})
144156
await expectScopeState(browserType, GOLDEN_PRECONDITION);
145157
});
146158

159+
it('should work with the domain module', async ({ domain, browserType }) => {
160+
const browser = await browserType.launch();
161+
const page = await browser.newPage();
162+
const result = await page.evaluate(() => 1 + 1);
163+
expect(result).toBe(2);
164+
await browser.close();
165+
});
166+
147167
async function expectScopeState(object, golden) {
148168
golden = trimGuids(golden);
149169
const remoteState = trimGuids(await object._channel.debugScopeState());

test/playwright.fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type PlaywrightWorkerFixtures = {
3838
browserType: BrowserType<Browser>;
3939
browser: Browser;
4040
httpService: {server: TestServer, httpsServer: TestServer}
41+
domain: void;
4142
toImpl: (rpcObject: any) => any;
4243
isChromium: boolean;
4344
isFirefox: boolean;

0 commit comments

Comments
 (0)