chore: add bidi test expectations in separate file (#32549)
Based on the expectations the tests that are expected to timeout or fail will be skipped to save resources. The expectations can be manually updated when corresponding feature is fixed.
This commit is contained in:
parent
aaac57b948
commit
1f0514536e
76
tests/bidi/expectationReporter.ts
Normal file
76
tests/bidi/expectationReporter.ts
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type {
|
||||
FullConfig, FullResult, Reporter, Suite, TestCase
|
||||
} from '@playwright/test/reporter';
|
||||
import fs from 'fs';
|
||||
import { projectExpectationPath } from './expectationUtil';
|
||||
|
||||
type ReporterOptions = {
|
||||
rebase?: boolean;
|
||||
};
|
||||
|
||||
class ExpectationReporter implements Reporter {
|
||||
private _suite: Suite;
|
||||
private _options: ReporterOptions;
|
||||
|
||||
constructor(options: ReporterOptions) {
|
||||
this._options = options;
|
||||
}
|
||||
|
||||
onBegin(config: FullConfig, suite: Suite) {
|
||||
this._suite = suite;
|
||||
}
|
||||
|
||||
onEnd(result: FullResult) {
|
||||
if (!this._options.rebase)
|
||||
return;
|
||||
for (const project of this._suite.suites)
|
||||
this._updateProjectExpectations(project);
|
||||
}
|
||||
|
||||
private _updateProjectExpectations(project: Suite) {
|
||||
const results = project.allTests().map(test => {
|
||||
const outcome = getOutcome(test);
|
||||
const line = `${test.titlePath().slice(1).join(' › ')} [${outcome}]`;
|
||||
return line;
|
||||
});
|
||||
const outputFile = projectExpectationPath(project.title);
|
||||
console.log('Writing new expectations to', outputFile);
|
||||
fs.writeFileSync(outputFile, results.join('\n'));
|
||||
}
|
||||
|
||||
printsToStdio(): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getOutcome(test: TestCase): 'unknown' | 'flaky' | 'pass' | 'fail' | 'timeout' {
|
||||
if (test.results.length === 0)
|
||||
return 'unknown';
|
||||
if (test.results.every(r => r.status === 'timedOut'))
|
||||
return 'timeout';
|
||||
if (test.outcome() === 'expected')
|
||||
return 'pass';
|
||||
if (test.outcome() === 'unexpected')
|
||||
return 'fail';
|
||||
if (test.outcome() === 'flaky')
|
||||
return 'flaky';
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
export default ExpectationReporter;
|
||||
50
tests/bidi/expectationUtil.ts
Normal file
50
tests/bidi/expectationUtil.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import type { TestInfo } from 'playwright/test';
|
||||
|
||||
type ShouldSkipPredicate = (info: TestInfo) => boolean;
|
||||
|
||||
export async function parseBidiExpectations(projectName: string): Promise<ShouldSkipPredicate> {
|
||||
const filePath = projectExpectationPath(projectName);
|
||||
try {
|
||||
await fs.promises.access(filePath);
|
||||
} catch (e) {
|
||||
return () => false;
|
||||
}
|
||||
const content = await fs.promises.readFile(filePath);
|
||||
const pairs = content.toString().split('\n').map(line => {
|
||||
const match = /(?<titlePath>.+) \[(?<expectation>[^\]]+)\]$/.exec(line);
|
||||
if (!match) {
|
||||
console.error('Bad expectation line: ' + line);
|
||||
return undefined;
|
||||
}
|
||||
return [match.groups!.titlePath, match.groups!.expectation];
|
||||
}).filter(Boolean) as [string, string][];
|
||||
const expectationsMap = new Map(pairs);
|
||||
|
||||
return (info: TestInfo) => {
|
||||
const key = [info.project.name, ...info.titlePath].join(' › ');
|
||||
const expectation = expectationsMap.get(key);
|
||||
return expectation === 'fail' || expectation === 'timeout';
|
||||
};
|
||||
}
|
||||
|
||||
export function projectExpectationPath(project: string): string {
|
||||
return path.join(__dirname, 'expectations', project + '.txt');
|
||||
}
|
||||
1910
tests/bidi/expectations/bidi-chromium-library.txt
Normal file
1910
tests/bidi/expectations/bidi-chromium-library.txt
Normal file
File diff suppressed because it is too large
Load diff
1966
tests/bidi/expectations/bidi-chromium-page.txt
Normal file
1966
tests/bidi/expectations/bidi-chromium-page.txt
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -36,7 +36,8 @@ const reporters = () => {
|
|||
['json', { outputFile: path.join(outputDir, 'report.json') }],
|
||||
['blob', { fileName: `${process.env.PWTEST_BOT_NAME}.zip` }],
|
||||
] : [
|
||||
['html', { open: 'on-failure' }]
|
||||
['html', { open: 'on-failure' }],
|
||||
['./expectationReporter', { rebase: false }],
|
||||
];
|
||||
return result;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import { baseTest } from './baseTest';
|
|||
import { type RemoteServerOptions, type PlaywrightServer, RunServer, RemoteServer } from './remoteServer';
|
||||
import type { Log } from '../../packages/trace/src/har';
|
||||
import { parseHar } from '../config/utils';
|
||||
import { parseBidiExpectations as parseBidiProjectExpectations } from '../bidi/expectationUtil';
|
||||
import type { TestInfo } from '@playwright/test';
|
||||
|
||||
export type BrowserTestWorkerFixtures = PageWorkerFixtures & {
|
||||
browserVersion: string;
|
||||
|
|
@ -33,6 +35,7 @@ export type BrowserTestWorkerFixtures = PageWorkerFixtures & {
|
|||
browserType: BrowserType;
|
||||
isAndroid: boolean;
|
||||
isElectron: boolean;
|
||||
bidiTestSkipPredicate: (info: TestInfo) => boolean;
|
||||
};
|
||||
|
||||
interface StartRemoteServer {
|
||||
|
|
@ -46,6 +49,7 @@ type BrowserTestTestFixtures = PageTestFixtures & {
|
|||
startRemoteServer: StartRemoteServer;
|
||||
contextFactory: (options?: BrowserContextOptions) => Promise<BrowserContext>;
|
||||
pageWithHar(options?: { outputPath?: string, content?: 'embed' | 'attach' | 'omit', omitContent?: boolean }): Promise<{ context: BrowserContext, page: Page, getLog: () => Promise<Log>, getZip: () => Promise<Map<string, Buffer>> }>
|
||||
autoSkipBidiTest: void;
|
||||
};
|
||||
|
||||
const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>({
|
||||
|
|
@ -165,7 +169,18 @@ const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>
|
|||
};
|
||||
};
|
||||
await use(pageWithHar);
|
||||
}
|
||||
},
|
||||
|
||||
bidiTestSkipPredicate: [async ({ }, run) => {
|
||||
const filter = await parseBidiProjectExpectations(test.info().project.name);
|
||||
await run(filter);
|
||||
}, { scope: 'worker' }],
|
||||
|
||||
autoSkipBidiTest: [async ({ bidiTestSkipPredicate }, run) => {
|
||||
if (bidiTestSkipPredicate(test.info()))
|
||||
test.skip(true);
|
||||
await run();
|
||||
}, { auto: true, scope: 'test' }],
|
||||
});
|
||||
|
||||
export const playwrightTest = test;
|
||||
|
|
|
|||
Loading…
Reference in a new issue