Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class Connection extends EventEmitter {
if (!callback)
throw new Error(`Cannot find command to respond: ${id}`);
this._callbacks.delete(id);
if (error)
if (error && !result)
callback.reject(parseError(error));
else
callback.resolve(this._replaceGuidsWithChannels(result));
Expand Down
11 changes: 6 additions & 5 deletions src/dispatchers/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,12 @@ export class DispatcherConnection {
await sdkObject?.instrumentation.onAfterCall(sdkObject, callMetadata);
}

const log = validMetadata.collectLogs ? callMetadata.log : undefined;
if (callMetadata.error)
this.onmessage({ id, error: error, log });
else
this.onmessage({ id, result: callMetadata.result, log });
const response: any = { id };
if (callMetadata.result)
response.result = callMetadata.result;
if (error)
response.error = error;
this.onmessage(response);
}

private _replaceDispatchersWithGuids(payload: any): any {
Expand Down
2 changes: 2 additions & 0 deletions src/dispatchers/frameDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameInitializer
const result = await this._frame.expect(metadata, params.selector, { ...params, expectedValue });
if (result.received !== undefined)
result.received = serializeResult(result.received);
if (result.pass === !!params.isNot)
metadata.error = { error: { name: 'Expect', message: 'Expect failed' } };
return result;
}
}
1 change: 0 additions & 1 deletion src/protocol/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export type StackFrame = {
export type Metadata = {
stack?: StackFrame[],
apiName?: string,
collectLogs?: boolean,
};

export type Point = {
Expand Down
1 change: 0 additions & 1 deletion src/protocol/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Metadata:
type: array?
items: StackFrame
apiName: string?
collectLogs: boolean?


Point:
Expand Down
1 change: 0 additions & 1 deletion src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
scheme.Metadata = tObject({
stack: tOptional(tArray(tType('StackFrame'))),
apiName: tOptional(tString),
collectLogs: tOptional(tBoolean),
});
scheme.Point = tObject({
x: tNumber,
Expand Down
1 change: 0 additions & 1 deletion src/test/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ function wrap(matcherName: string, matcher: any) {
reportStepError(e);
}
};
result.displayName = 'expect.' + matcherName;
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ export const test = _baseTest.extend<TestFixtures, WorkerAndFileFixtures>({
}
(context as any)._csi = {
onApiCallBegin: (apiCall: string) => {
if (apiCall.startsWith('expect.'))
return { userObject: null };
const step = (testInfo as any)._addStep({
category: 'pw:api',
title: apiCall,
Expand Down
15 changes: 11 additions & 4 deletions src/utils/stackTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ export function captureStackTrace(): ParsedStackTrace {
return null;
if (frame.file.startsWith('internal'))
return null;
if (frame.file.includes(path.join('node_modules', 'expect')))
return null;
const fileName = path.resolve(process.cwd(), frame.file);
if (isTesting && fileName.includes(path.join('playwright', 'tests', 'config', 'coverage.js')))
return null;
const inClient =
// Allow fixtures in the reported stacks.
(!fileName.includes('test/index') && !fileName.includes('test\\index')) && (
fileName.startsWith(CLIENT_LIB)
frame.file.includes(path.join('node_modules', 'expect'))
|| fileName.startsWith(CLIENT_LIB)
|| fileName.startsWith(CLIENT_SRC)
|| fileName.startsWith(TEST_LIB)
|| fileName.startsWith(TEST_SRC));
Expand All @@ -94,7 +93,15 @@ export function captureStackTrace(): ParsedStackTrace {
for (let i = 0; i < parsedFrames.length - 1; i++) {
if (parsedFrames[i].inClient && !parsedFrames[i + 1].inClient) {
const frame = parsedFrames[i].frame;
apiName = frame.function ? frame.function[0].toLowerCase() + frame.function.slice(1) : '';
const text = parsedFrames[i].frameText;
// expect matchers have the following stack structure:
// at __EXTERNAL_MATCHER_TRAP__ (.../index.js:342:30)
// at Object.throwingMatcher [as toBeChecked] (.../index.js:343:15)
const aliasIndex = text.indexOf('[as ');
if (aliasIndex !== -1)
apiName = 'expect.' + text.substring(aliasIndex + 4, text.indexOf(']'));
else
apiName = frame.function ? frame.function[0].toLowerCase() + frame.function.slice(1) : '';
parsedFrames = parsedFrames.slice(i + 1);
break;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/config/browserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export const playwrightFixtures: Fixtures<PlaywrightTestOptions & PlaywrightTest
await context.tracing.start({ screenshots: true, snapshots: true });
(context as any)._csi = {
onApiCallBegin: (apiCall: string) => {
if (apiCall.startsWith('expect.'))
return { userObject: null };
const testInfoImpl = testInfo as any;
const step = testInfoImpl._addStep({
category: 'pw:api',
Expand Down
4 changes: 1 addition & 3 deletions tests/playwright-test/reporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ test('should report expect steps', async ({ runInlineTest }) => {
`%% end {\"title\":\"browserContext.newPage\",\"category\":\"pw:api\"}`,
`%% end {\"title\":\"Before Hooks\",\"category\":\"hook\",\"steps\":[{\"title\":\"browserContext.newPage\",\"category\":\"pw:api\"}]}`,
`%% begin {\"title\":\"expect.not.toHaveTitle\",\"category\":\"expect\"}`,
`%% begin {\"title\":\"object.expect.toHaveTitle(:root)\",\"category\":\"pw:api\"}`,
`%% end {\"title\":\"object.expect.toHaveTitle(:root)\",\"category\":\"pw:api\"}`,
`%% end {\"title\":\"expect.not.toHaveTitle\",\"category\":\"expect\",\"steps\":[{\"title\":\"object.expect.toHaveTitle(:root)\",\"category\":\"pw:api\"}]}`,
`%% end {\"title\":\"expect.not.toHaveTitle\",\"category\":\"expect\"}`,
`%% begin {\"title\":\"After Hooks\",\"category\":\"hook\"}`,
`%% begin {\"title\":\"browserContext.close\",\"category\":\"pw:api\"}`,
`%% end {\"title\":\"browserContext.close\",\"category\":\"pw:api\"}`,
Expand Down