Skip to content

Commit b565164

Browse files
test: Update test splitting to support new test workflows (#35905)
## **Description** The script responsible for determining how to split up tests in a given workflow was failing when I tried to add a new workflow. It didn't seem to handle the case where a workflow had zero past runs. It has been updated to use a naive fallback splitting algorithm in this case. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/35905?quickstart=1) ## **Changelog** CHANGELOG entry: null ## **Related issues** This fixes a CI bug encountered on #31435 ## **Manual testing steps** See this PR for an example of the failures: #35906 See here for a rebased version of that PR on this branch, which works: #35913 ## **Screenshots/Recordings** N/A ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Howard Braham <howrad@gmail.com>
1 parent 2c6193c commit b565164

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

.github/scripts/split-tests-by-timings.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
// Quality Gate Retries
1111
const RETRIES_FOR_NEW_OR_CHANGED_TESTS = 4;
1212

13-
function readTestResults(TEST_RESULTS_PATH: string): TestRun | undefined {
13+
function readTestResults(TEST_RESULTS_PATH: string): TestRun {
1414
const testSuiteName =
1515
process.env.TEST_SUITE_NAME || 'test-e2e-chrome-browserify';
1616

@@ -19,9 +19,12 @@ function readTestResults(TEST_RESULTS_PATH: string): TestRun | undefined {
1919
readFileSync(TEST_RESULTS_PATH, 'utf8'),
2020
);
2121

22-
const testRun: TestRun | undefined = testRuns.find(
22+
const testRun: TestRun = testRuns.find(
2323
(run) => run.name === testSuiteName,
24-
);
24+
) || { // If the TestRun is not found, return a dummy object to do the naïve split
25+
name: testSuiteName,
26+
testFiles: [],
27+
};
2528

2629
return testRun;
2730
} catch (error) {
@@ -82,31 +85,22 @@ export function splitTestsByTimings(
8285
TEST_RESULTS_FILE = `test/test-results/test-runs-${process.env.SELENIUM_BROWSER}.json`,
8386
} = process.env;
8487

85-
try {
86-
const testRunLastTime = readTestResults(TEST_RESULTS_FILE);
87-
88-
if (testRunLastTime) {
89-
let testRunNew: TestRun = { name: testRunLastTime.name, testFiles: [] };
88+
const testRunLastTime = readTestResults(TEST_RESULTS_FILE);
89+
let testRunNew: TestRun = { name: testRunLastTime.name, testFiles: [] };
9090

91-
testList.forEach((path) => {
92-
const testFileLastTime = testRunLastTime.testFiles.find(
93-
(file) => file.path === path,
94-
);
95-
96-
if (testFileLastTime) {
97-
testRunNew.testFiles.push(testFileLastTime);
98-
} else {
99-
testRunNew.testFiles.push(getNewBlankTestFile(path));
100-
}
101-
});
91+
testList.forEach((path) => {
92+
const testFileLastTime = testRunLastTime.testFiles.find(
93+
(file) => file.path === path,
94+
);
10295

103-
return splitTests(testRunNew, changedOrNewTests, totalChunks);
96+
if (testFileLastTime) {
97+
testRunNew.testFiles.push(testFileLastTime);
98+
} else {
99+
testRunNew.testFiles.push(getNewBlankTestFile(path));
104100
}
105-
} catch (error) {
106-
console.trace(error);
107-
}
101+
});
108102

109-
return [];
103+
return splitTests(testRunNew, changedOrNewTests, totalChunks);
110104
}
111105

112106
/**

0 commit comments

Comments
 (0)