-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathchrome-failed-tests.ts
64 lines (56 loc) · 2.35 KB
/
chrome-failed-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import fs from 'fs';
import path from 'path';
import { runWptTests, WptTestResult } from './wpt';
// Some tests also fail in Chrome
// We don't also care about them
let chromeFailedTests: WptTestResult[] = [];
let totalNumberOfTests = 0;
export async function runChromeTests(wptTestList: string[]): Promise<void> {
chromeFailedTests = [];
totalNumberOfTests = 0;
if (!process.env.NO_CACHE_FOR_CHROME_TESTS) {
console.log("Default is to read chromeFailedTests from json file");
console.log("While it takes time to run all tests");
console.log("Set NO_CACHE_FOR_CHROME_TESTS to true in order to run all tests from scratch");
const filePath = path.join(__dirname, 'chromeFailedTests.json');
if (fs.existsSync(filePath)) {
const chromeFailedTestsFromFile = JSON.parse(fs.readFileSync(filePath).toString());
// Filter out tests that are not in wptTestList
chromeFailedTests = chromeFailedTestsFromFile.filter((test: WptTestResult) => wptTestList.includes(test.test));
for (let i = 0; i < chromeFailedTests.length; i++) {
totalNumberOfTests += chromeFailedTests[i].result.length;
}
}
return;
}
const results = await runWptTests(wptTestList, true);
for (let i = 0; i < results.length; i++) {
totalNumberOfTests += results[i].result?.length || 0;
if (results[i].result && results[i].result.some((test) => test.status === 1)) {
chromeFailedTests.push({
test: results[i].test,
result: results[i].result.filter((test) => test.status === 1),
});
}
}
// Write chromeFailedTests to json file
const filePath = path.join(__dirname, 'chromeFailedTests.json');
fs.writeFileSync(filePath, JSON.stringify(chromeFailedTests, null, 2));
}
export function getChromeFailedTests(): WptTestResult[] {
return chromeFailedTests;
}
export function isTestForChromeFailed(testPath, testName): boolean {
return chromeFailedTests.some(
(test) =>
test.test === testPath && test.result.some((result) => result.name === testName && result.status === 1),
);
}
export function getTotalNumberOfTests(): number {
return totalNumberOfTests;
}
// Test
// (async () => {
// await runChromeTests();
// console.log(getChromeFailedTests());
// })();