test: unflake trace-viewer.spec.ts (#8694)

This commit is contained in:
Dmitry Gozman 2021-09-03 12:34:47 -07:00 committed by GitHub
parent 1762f4c547
commit f7a490f80e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 28 deletions

View File

@ -147,16 +147,15 @@ test('should show empty trace viewer', async ({ showTraceViewer }, testInfo) =>
test('should open simple trace viewer', async ({ showTraceViewer }) => {
const traceViewer = await showTraceViewer(traceFile);
const actionTitles = await traceViewer.actionTitles.allTextContents();
expect(sanitize(actionTitles)).toEqual([
'page.gotodata:text/html,<html>Hello world</html>— Xms',
'page.setContent— Xms',
'page.evaluate— Xms',
'page.click\"Click\"— Xms',
'page.waitForNavigation— Xms',
'page.gotodata:text/html,<html>Hello world 2</html>— Xms',
'page.setViewportSize— Xms',
'page.hoverbody— Xms',
await expect(traceViewer.actionTitles).toHaveText([
/page.gotodata:text\/html,<html>Hello world<\/html>— \d+ms/,
/page.setContent— \d+ms/,
/page.evaluate— \d+ms/,
/page.click"Click"— \d+ms/,
/page.waitForNavigation— \d+ms/,
/page.gotodata:text\/html,<html>Hello world 2<\/html>— \d+ms/,
/page.setViewportSize— \d+ms/,
/page.hoverbody— \d+ms/,
]);
});
@ -198,10 +197,9 @@ test('should open console errors on click', async ({ showTraceViewer, browserNam
test('should show params and return value', async ({ showTraceViewer, browserName }) => {
const traceViewer = await showTraceViewer(traceFile);
await traceViewer.selectAction('page.evaluate');
const callLines = await traceViewer.callLines.allTextContents();
expect(sanitize(callLines)).toEqual([
'page.evaluate — Xms',
'expression: "({↵ a↵ }) => {↵ console.log(\'Info\');↵ console.warn(\'Warning\');↵ con…"',
await expect(traceViewer.callLines).toHaveText([
/page.evaluate — \d+ms/,
'expression: "({↵ a↵ }) => {↵ console.log(\'Info\');↵ console.warn(\'Warning\');↵ con…"',
'isFunction: true',
'arg: {"a":"paramA","b":4}',
'value: "return paramA"'
@ -222,20 +220,16 @@ test('should have correct stack trace', async ({ showTraceViewer }) => {
await traceViewer.selectAction('page.click');
await traceViewer.showSourceTab();
const stack1 = await traceViewer.stackFrames.allInnerTexts();
expect(sanitize(stack1).slice(0, 2)).toEqual([
'doClick trace-viewer.spec.ts :X',
'recordTrace trace-viewer.spec.ts :X',
const stack1 = (await traceViewer.stackFrames.allInnerTexts()).map(s => s.replace(/\s+/g, ' ').replace(/:[0-9]+/g, ':XXX'));
expect(stack1.slice(0, 2)).toEqual([
'doClick trace-viewer.spec.ts :XXX',
'recordTrace trace-viewer.spec.ts :XXX',
]);
await traceViewer.selectAction('page.hover');
await traceViewer.showSourceTab();
const stack2 = await traceViewer.stackFrames.allInnerTexts();
expect(sanitize(stack2).slice(0, 1)).toEqual([
'BrowserType.browserType._onWillCloseContext trace-viewer.spec.ts :X',
const stack2 = (await traceViewer.stackFrames.allInnerTexts()).map(s => s.replace(/\s+/g, ' ').replace(/:[0-9]+/g, ':XXX'));
expect(stack2.slice(0, 1)).toEqual([
'BrowserType.browserType._onWillCloseContext trace-viewer.spec.ts :XXX',
]);
});
function sanitize(texts: string[]): string[] {
return texts.map(s => s.replace(/\s+/g, ' ').replace(/\.ts :[0-9]+/g, '.ts :X').replace(/[0-9]+ms/g, 'Xms'));
}

View File

@ -29,7 +29,7 @@ export declare type Expect = {
stringMatching(expected: string | RegExp): AsymmetricMatcher;
};
type OverriddenExpectProperties =
type OverriddenExpectProperties =
'not' |
'resolves' |
'rejects' |
@ -122,7 +122,7 @@ declare global {
/**
* Asserts that DOM node has a given CSS class.
*/
toHaveClass(className: string | RegExp | string[], options?: { timeout?: number }): Promise<R>;
toHaveClass(className: string | RegExp | (string|RegExp)[], options?: { timeout?: number }): Promise<R>;
/**
* Asserts number of DOM nodes matching given locator.
@ -147,7 +147,7 @@ declare global {
/**
* Asserts element's text content.
*/
toHaveText(expected: string | RegExp | string[], options?: { timeout?: number, useInnerText?: boolean }): Promise<R>;
toHaveText(expected: string | RegExp | (string|RegExp)[], options?: { timeout?: number, useInnerText?: boolean }): Promise<R>;
/**
* Asserts page's title.