2024-09-11 17:28:29 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* 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';
|
|
|
|
|
|
|
2024-09-11 22:33:25 +02:00
|
|
|
|
export type TestExpectation = 'unknown' | 'flaky' | 'pass' | 'fail' | 'timeout';
|
|
|
|
|
|
|
2024-09-11 17:28:29 +02:00
|
|
|
|
type ShouldSkipPredicate = (info: TestInfo) => boolean;
|
|
|
|
|
|
|
2024-09-11 22:33:25 +02:00
|
|
|
|
export async function createSkipTestPredicate(projectName: string): Promise<ShouldSkipPredicate> {
|
2024-09-11 23:24:32 +02:00
|
|
|
|
if (!process.env.PWTEST_USE_BIDI_EXPECTATIONS)
|
|
|
|
|
|
return () => false;
|
2024-09-11 22:33:25 +02:00
|
|
|
|
const expectationsMap = await parseBidiExpectations(projectName);
|
|
|
|
|
|
return (info: TestInfo) => {
|
2024-09-12 00:15:10 +02:00
|
|
|
|
const key = info.titlePath.join(' › ');
|
2024-09-11 22:33:25 +02:00
|
|
|
|
const expectation = expectationsMap.get(key);
|
2024-12-17 00:28:21 +01:00
|
|
|
|
return expectation === 'timeout';
|
2024-09-11 22:33:25 +02:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function parseBidiExpectations(projectName: string): Promise<Map<string, TestExpectation>> {
|
2024-09-11 17:28:29 +02:00
|
|
|
|
const filePath = projectExpectationPath(projectName);
|
|
|
|
|
|
try {
|
|
|
|
|
|
await fs.promises.access(filePath);
|
|
|
|
|
|
} catch (e) {
|
2024-09-11 22:33:25 +02:00
|
|
|
|
return new Map();
|
2024-09-11 17:28:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
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];
|
2024-09-11 22:33:25 +02:00
|
|
|
|
}).filter(Boolean) as [string, TestExpectation][];
|
|
|
|
|
|
return new Map(pairs);
|
2024-09-11 17:28:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function projectExpectationPath(project: string): string {
|
|
|
|
|
|
return path.join(__dirname, 'expectations', project + '.txt');
|
|
|
|
|
|
}
|