Skip to content

Commit ead5ab1

Browse files
authored
Github Workflow: split tests (#227)
- Allow splitting of tests by tags - Run shell tests separately on ubuntu to avoid job limits - Run browser tests separately to slightly speed up results
1 parent bb77d06 commit ead5ab1

File tree

4 files changed

+252
-82
lines changed

4 files changed

+252
-82
lines changed

.github/workflows/test.yml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
test:
14-
name: Test
13+
browser:
14+
name: Test Browser
1515
runs-on: macos-latest
1616
env:
1717
GITHUB_ACTIONS_OUTPUT: ""
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
browser: [chrome, firefox, jsc, safari, spidermonkey, v8]
21+
browser: [chrome, firefox, safari]
22+
suite: [default, disabled, main]
2223
steps:
2324
- name: Extract Week Number
2425
run: echo "WEEK_NUMBER=$(date +%W)" >> $GITHUB_ENV
@@ -39,19 +40,48 @@ jobs:
3940
- name: Install Node Packages
4041
run: npm ci
4142

43+
- name: Run Tests
44+
run: |
45+
echo "Running in $BROWSER"
46+
npm run test:${{ matrix.browser }} -- ${{ matrix.suite }}
47+
shell:
48+
name: Test Shell
49+
runs-on: ubuntu-latest
50+
env:
51+
GITHUB_ACTIONS_OUTPUT: ""
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
shell: [jsc, spidermonkey, v8]
56+
suite: [default, disabled, main]
57+
steps:
58+
- name: Extract Week Number
59+
run: echo "WEEK_NUMBER=$(date +%W)" >> $GITHUB_ENV
60+
61+
- name: Checkout Branch
62+
uses: actions/checkout@v5
63+
64+
- name: Setup Node
65+
uses: actions/setup-node@v5
66+
with:
67+
node-version-file: package.json
68+
cache: npm
69+
70+
- name: Install Node Packages
71+
run: npm ci
72+
4273
- name: Cache jsvu Binaries
4374
uses: actions/cache@v4
4475
with:
4576
path: ~/.jsvu
46-
key: ${{ runner.os }}-jsvu-${{ matrix.browser }}-week-${{ env.WEEK_NUMBER }}
77+
key: ${{ runner.os }}-jsvu-${{ matrix.shell }}-week-${{ env.WEEK_NUMBER }}
4778

4879
- name: Run Tests
4980
run: |
5081
echo "Running in $BROWSER"
51-
npm run test:${{ matrix.browser }}
52-
82+
npm run test:${{ matrix.shell }} -- ${{ matrix.suite }}
5383
build:
54-
name: Build
84+
name: Test Build
5585
runs-on: ubuntu-latest
5686
steps:
5787
- name: Checkout Branch

tests/helper.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export async function logGroup(name, body) {
8181
}
8282

8383

84-
export function printHelp(message = "", optionDefinitions) {
84+
export function printHelp(message, optionDefinitions) {
8585
const usage = commandLineUsage([
8686
{
8787
header: "Run all tests",
@@ -91,13 +91,13 @@ export function printHelp(message = "", optionDefinitions) {
9191
optionList: optionDefinitions,
9292
},
9393
]);
94-
if (!message) {
94+
if (!message?.length) {
9595
console.log(usage);
9696
process.exit(0);
9797
} else {
9898
console.error(message);
99-
console.error();
100-
console.error(usage);
99+
console.log();
100+
console.log(usage);
101101
process.exit(1);
102102
}
103103
}

tests/run-browser.mjs

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,45 @@ import os from "os";
3333

3434
import {logInfo, logError, printHelp, runTest} from "./helper.mjs";
3535

36+
const TESTS = [
37+
{
38+
name: "Run Single Suite",
39+
tags: ["all", "main"],
40+
run() {
41+
return runEnd2EndTest("Run Single Suite", { test: "proxy-mobx" });
42+
}
43+
},
44+
{
45+
name: "Run Multiple Suites",
46+
tags: ["all", "main"],
47+
run() {
48+
return runEnd2EndTest("Run Multiple Suites", { test: "prismjs-startup-es6,postcss-wtb" });
49+
}
50+
},
51+
{
52+
name: "Run Tag No Prefetch",
53+
tags: ["all", "main"],
54+
run() {
55+
return runEnd2EndTest("Run Tag No Prefetch", { tag: "proxy", prefetchResources: "false" });
56+
}
57+
},
58+
{
59+
name: "Run Disabled Suite",
60+
tags: ["all", "disabled"],
61+
run() {
62+
return runEnd2EndTest("Run Disabled Suite", { tag: "disabled" });
63+
}
64+
},
65+
{
66+
name: "Run Default Suite",
67+
tags: ["all", "default"],
68+
run() {
69+
return runEnd2EndTest("Run Default Suite");
70+
}
71+
}
72+
];
73+
74+
const VALID_TAGS = Array.from(new Set(TESTS.map((each) => each.tags).flat()));
3675

3776
function sleep(ms) {
3877
return new Promise(resolve => setTimeout(resolve, ms));
@@ -42,12 +81,16 @@ const optionDefinitions = [
4281
{ name: "browser", type: String, description: "Set the browser to test, choices are [safari, firefox, chrome, edge]. By default the $BROWSER env variable is used." },
4382
{ name: "port", type: Number, defaultValue: 8010, description: "Set the test-server port, The default value is 8010." },
4483
{ name: "help", alias: "h", description: "Print this help text." },
84+
{ name: "suite", type: String, defaultOption: true, typeLabel: `{underline choices}: ${VALID_TAGS.join(", ")}`, description: "Run a specific suite by name." }
4585
];
4686

4787
const options = commandLineArgs(optionDefinitions);
4888

4989
if ("help" in options)
50-
printHelp(optionDefinitions);
90+
printHelp("". optionDefinitions);
91+
92+
if (options.suite && !VALID_TAGS.includes(options.suite))
93+
printHelp(`Invalid suite: ${options.suite}. Choices are: ${VALID_TAGS.join(", ")}`);
5194

5295
const BROWSER = options?.browser;
5396
if (!BROWSER)
@@ -73,7 +116,7 @@ switch (BROWSER) {
73116
break;
74117
}
75118
default: {
76-
printHelp(`Invalid browser "${BROWSER}", choices are: "safari", "firefox", "chrome", "edge"`);
119+
printHelp(`Invalid browser "${BROWSER}", choices are: "safari", "firefox", "chrome", "edge"`, optionDefinitions);
77120
}
78121
}
79122

@@ -91,12 +134,19 @@ const server = await serve(PORT);
91134

92135
async function runTests() {
93136
let success = true;
137+
const suiteFilter = options.suite || "all";
138+
139+
const testsToRun = TESTS.filter(test => test.tags.includes(suiteFilter));
140+
141+
if (testsToRun.length === 0) {
142+
console.error(`No suite found for filter: ${suiteFilter}`);
143+
process.exit(1);
144+
}
145+
94146
try {
95-
success &&= await runEnd2EndTest("Run Single Suite", { test: "proxy-mobx" });
96-
success &&= await runEnd2EndTest("Run Multiple Suites", { test: "prismjs-startup-es6,postcss-wtb" });
97-
success &&= await runEnd2EndTest("Run Tag No Prefetch", { tag: "proxy", prefetchResources: "false" });
98-
success &&= await runEnd2EndTest("Run Disabled Suite", { tag: "disabled" });
99-
success &&= await runEnd2EndTest("Run Default Suite");
147+
for (const test of testsToRun) {
148+
success &&= await test.run();
149+
}
100150
} finally {
101151
server.close();
102152
}

0 commit comments

Comments
 (0)