Skip to content

Commit

Permalink
cherrypick(release-1.4): fix compatibility to the domain module (#3878)
Browse files Browse the repository at this point in the history
Cherry-picking #3851

References #3848
  • Loading branch information
aslushnikov authored Sep 14, 2020
1 parent 014096a commit 64947f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/client/channelOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});
Expand Down
21 changes: 21 additions & 0 deletions test/channels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@
* limitations under the License.
*/

import domain from 'domain';
import { registerWorkerFixture } from '@playwright/test-runner';
import { it, expect, options } from './playwright.fixtures';
import type { ChromiumBrowser } from '..';

registerWorkerFixture('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();
});
Expand Down Expand Up @@ -144,6 +157,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());
Expand Down
1 change: 1 addition & 0 deletions test/playwright.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ declare global {
browserType: BrowserType<Browser>;
browser: Browser;
httpService: {server: TestServer, httpsServer: TestServer}
domain: void;
toImpl: (rpcObject: any) => any;
}
interface TestState {
Expand Down

0 comments on commit 64947f1

Please sign in to comment.