test: unflake two tests (#24416)

This commit is contained in:
Dmitry Gozman 2023-07-26 06:50:38 -07:00 committed by GitHub
parent ed99ac7395
commit c33a32dc9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

@ -712,7 +712,11 @@ test('should not emit after w/o before', async ({ browserType, mode }, testInfo)
const page = await context.newPage();
await context.tracing.start({ name: 'name1', snapshots: true });
const evaluatePromise = page.evaluate(() => new Promise(f => (window as any).callback = f)).catch(() => {});
const evaluatePromise = page.evaluate(() => {
console.log('started');
return new Promise(f => (window as any).callback = f);
}).catch(() => {});
await page.waitForEvent('console');
await context.tracing.stopChunk({ path: testInfo.outputPath('trace1.zip') });
expect(fs.existsSync(path.join(tracesDir, 'name1.trace'))).toBe(true);
@ -738,21 +742,34 @@ test('should not emit after w/o before', async ({ browserType, mode }, testInfo)
let call1: number;
{
const { events } = await parseTraceRaw(testInfo.outputPath('trace1.zip'));
expect(events.map(sanitize).filter(Boolean)).toEqual([
const sanitized = events.map(sanitize).filter(Boolean);
expect(sanitized).toEqual([
{
type: 'before',
callId: expect.any(Number),
apiName: 'page.evaluate'
}
},
{
type: 'before',
callId: expect.any(Number),
apiName: 'page.waitForEvent'
},
{
type: 'after',
callId: expect.any(Number),
apiName: undefined,
},
]);
call1 = events.map(sanitize).filter(Boolean)[0].callId;
call1 = sanitized[0].callId;
expect(sanitized[1].callId).toBe(sanitized[2].callId);
}
let call2before: number;
let call2after: number;
{
const { events } = await parseTraceRaw(testInfo.outputPath('trace2.zip'));
expect(events.map(sanitize).filter(Boolean)).toEqual([
const sanitized = events.map(sanitize).filter(Boolean);
expect(sanitized).toEqual([
{
type: 'before',
callId: expect.any(Number),
@ -764,8 +781,8 @@ test('should not emit after w/o before', async ({ browserType, mode }, testInfo)
apiName: undefined
}
]);
call2before = events.map(sanitize).filter(Boolean)[0].callId;
call2after = events.map(sanitize).filter(Boolean)[1].callId;
call2before = sanitized[0].callId;
call2after = sanitized[1].callId;
}
expect(call2before).toBeGreaterThan(call1);
expect(call2after).toBe(call2before);

View File

@ -146,6 +146,8 @@ it('should report navigation requests and responses handled by service worker wi
const [, failedRequest] = await Promise.all([
page.evaluate(() => {
window.location.href = '/serviceworkers/stub/error.html';
// eslint-disable-next-line
undefined
}),
page.waitForEvent('requestfailed'),
]);