Skip to content

Commit

Permalink
fix(connect): annotate internal api calls correctly (#31715)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Jul 17, 2024
1 parent 3694c14 commit e11c0c0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/playwright-core/src/client/browserType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
connection.close(reason || closeError);
};
pipe.on('closed', params => onPipeClosed(params.reason));
connection.onmessage = message => pipe.send({ message }).catch(() => onPipeClosed());
connection.onmessage = message => this._wrapApiCall(() => pipe.send({ message }).catch(() => onPipeClosed()), /* isInternal */ true);

pipe.on('message', ({ message }) => {
try {
Expand All @@ -181,7 +181,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
this._didLaunchBrowser(browser, {}, logger);
browser._shouldCloseConnectionOnClose = true;
browser._connectHeaders = connectHeaders;
browser.on(Events.Browser.Disconnected, closePipe);
browser.on(Events.Browser.Disconnected, () => this._wrapApiCall(() => closePipe(), /* isInternal */ true));
return browser;
}, deadline);
if (!result.timedOut) {
Expand Down
2 changes: 2 additions & 0 deletions packages/playwright-core/src/client/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ export class Connection extends EventEmitter {
}

close(cause?: string) {
if (this._closedError)
return;
this._closedError = new TargetClosedError(cause);
for (const callback of this._callbacks.values())
callback.reject(this._closedError);
Expand Down
51 changes: 51 additions & 0 deletions tests/playwright-test/playwright.reuse.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,54 @@ test('should reuse browser with special characters in the launch options', async
expect(guid2).toBe(guid1);
expect(workerIndex2).not.toBe(workerIndex1);
});

test('should produce correct test steps', async ({ runInlineTest, runServer }) => {
const server = await runServer();
const result = await runInlineTest({
'reporter.ts': `
class Reporter {
onStepBegin(test, result, step) {
console.log('%% onStepBegin ' + step.title);
}
onStepEnd(test, result, step) {
console.log('%% onStepEnd ' + step.title);
}
}
module.exports = Reporter;
`,
'src/a.test.ts': `
import { test, expect } from '@playwright/test';
test('a', async ({ page }) => {
await page.goto('about:blank');
await page.evaluate(() => console.log('hello'));
});
`,
}, { reporter: './reporter.ts,list' }, { PW_TEST_REUSE_CONTEXT: '1', PW_TEST_CONNECT_WS_ENDPOINT: server.wsEndpoint() });

expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
expect(result.outputLines).toEqual([
'onStepBegin Before Hooks',
'onStepBegin fixture: browser',
'onStepBegin browserType.connect',
'onStepEnd browserType.connect',
'onStepEnd fixture: browser',
'onStepBegin fixture: context',
'onStepEnd fixture: context',
'onStepBegin fixture: page',
'onStepBegin browserContext.newPage',
'onStepEnd browserContext.newPage',
'onStepEnd fixture: page',
'onStepEnd Before Hooks',
'onStepBegin page.goto(about:blank)',
'onStepEnd page.goto(about:blank)',
'onStepBegin page.evaluate',
'onStepEnd page.evaluate',
'onStepBegin After Hooks',
'onStepBegin fixture: page',
'onStepEnd fixture: page',
'onStepBegin fixture: context',
'onStepEnd fixture: context',
'onStepEnd After Hooks'
]);
});

0 comments on commit e11c0c0

Please sign in to comment.