chore: include log in matcherResult (#27164)

This commit is contained in:
Pavel Feldman 2023-09-21 16:23:46 -07:00 committed by GitHub
parent 287d720b8e
commit 51a774f8a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 6 deletions

View File

@ -253,6 +253,7 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
params: args[0] ? { expected: args[0] } : undefined,
wallTime,
infectParentStepsWithError: this._info.isSoft,
laxParent: true,
}) : undefined;
const reportStepError = (jestError: Error) => {

View File

@ -34,4 +34,5 @@ export type MatcherResult<E, A> = {
message: () => string;
pass: boolean;
actual?: A;
log?: string[];
};

View File

@ -48,5 +48,5 @@ export async function toBeTruthy(
return matches ? `${header}Expected: not ${expected}\nReceived: ${expected}${logText}` :
`${header}Expected: ${expected}\nReceived: ${unexpected}${logText}`;
};
return { locator: receiver, message, pass: matches, actual, name: matcherName, expected };
return { locator: receiver, message, pass: matches, actual, name: matcherName, expected, log };
}

View File

@ -67,5 +67,5 @@ export async function toEqual<T>(
// Passing the actual and expected objects so that a custom reporter
// could access them, for example in order to display a custom visual diff,
// or create a different error message
return { locator: receiver, actual: received, expected, message, name: matcherName, pass };
return { locator: receiver, actual: received, expected, message, name: matcherName, pass, log };
}

View File

@ -157,7 +157,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
this.kind = this.mimeType.startsWith('image/') ? 'Screenshot' : 'Snapshot';
}
createMatcherResult(message: string, pass: boolean): ImageMatcherResult {
createMatcherResult(message: string, pass: boolean, log?: string[]): ImageMatcherResult {
const unfiltered: ImageMatcherResult = {
name: this.matcherName,
locator: this.locator,
@ -166,6 +166,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
diff: this.diffPath,
pass,
message: () => message,
log,
};
return Object.fromEntries(Object.entries(unfiltered).filter(([_, v]) => v !== undefined)) as ImageMatcherResult;
}
@ -255,7 +256,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
else
output.push('');
return this.createMatcherResult(output.join('\n'), false);
return this.createMatcherResult(output.join('\n'), false, log);
}
handleMatching(): ImageMatcherResult {

View File

@ -105,6 +105,7 @@ export async function toMatchText(
message,
pass,
actual: received,
log,
};
}

View File

@ -348,8 +348,8 @@ export class TestInfoImpl implements TestInfo {
this.errors.push(error);
}
async _runAsStep<T>(stepInfo: Omit<TestStepInternal, 'complete' | 'wallTime' | 'parentStepId' | 'stepId' | 'steps'>, cb: (step: TestStepInternal) => Promise<T>): Promise<T> {
const step = this._addStep({ ...stepInfo, wallTime: Date.now() });
async _runAsStep<T>(stepInfo: Omit<TestStepInternal, 'complete' | 'wallTime' | 'parentStepId' | 'stepId' | 'steps'> & { wallTime?: number }, cb: (step: TestStepInternal) => Promise<T>): Promise<T> {
const step = this._addStep({ wallTime: Date.now(), ...stepInfo });
return await zones.run('stepZone', step, async () => {
try {
const result = await cb(step);

View File

@ -31,6 +31,7 @@ test('toMatchText-based assertions should have matcher result', async ({ page })
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toHaveText(expected)`),
name: 'toHaveText',
pass: false,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toHaveText(expected)
@ -52,6 +53,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toHaveText(expected)`),
name: 'toHaveText',
pass: true,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toHaveText(expected)
@ -77,6 +79,7 @@ test('toBeTruthy-based assertions should have matcher result', async ({ page })
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeVisible()`),
name: 'toBeVisible',
pass: false,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeVisible()
@ -98,6 +101,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeVisible()`),
name: 'toBeVisible',
pass: true,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeVisible()
@ -123,6 +127,7 @@ test('toEqual-based assertions should have matcher result', async ({ page }) =>
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toHaveCount(expected)`),
name: 'toHaveCount',
pass: false,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toHaveCount(expected)
@ -143,6 +148,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toHaveCount(expected)`),
name: 'toHaveCount',
pass: true,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toHaveCount(expected)
@ -171,6 +177,7 @@ test('toBeChecked({ checked: false }) should have expected: false', async ({ pag
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeChecked()`),
name: 'toBeChecked',
pass: false,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeChecked()
@ -192,6 +199,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeChecked()`),
name: 'toBeChecked',
pass: true,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeChecked()
@ -213,6 +221,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeChecked({ checked: false })`),
name: 'toBeChecked',
pass: false,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeChecked({ checked: false })
@ -234,6 +243,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeChecked({ checked: false })`),
name: 'toBeChecked',
pass: true,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeChecked({ checked: false })
@ -259,6 +269,7 @@ test('toHaveScreenshot should populate matcherResult', async ({ page, server })
message: expect.stringContaining(`Screenshot comparison failed`),
name: 'toHaveScreenshot',
pass: false,
log: expect.any(Array),
});
expect.soft(stripAnsi(e.toString())).toContain(`Error: Screenshot comparison failed: