Skip to content

Commit a311531

Browse files
committed
👷 Split unit-bs CI job per browser
1 parent 3f307c4 commit a311531

5 files changed

Lines changed: 53 additions & 16 deletions

File tree

‎.gitlab-ci.yml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,18 @@ unit-bs:
303303
- .base-configuration
304304
- .bs-allowed-branches
305305
interruptible: true
306-
resource_group: browserstack
306+
resource_group: browserstack-$BS_BROWSER
307+
parallel:
308+
matrix:
309+
- BS_BROWSER: [edge, firefox, safari-desktop, chrome-desktop, chrome-mobile]
307310
artifacts:
308311
reports:
309-
junit: test-report/unit-bs/*.xml
312+
junit: test-report/unit-bs-$BS_BROWSER/*.xml
310313
script:
311314
- yarn
312-
- node scripts/test/ci-bs.ts test:unit
315+
- node scripts/test/ci-bs.ts test:unit --browser $BS_BROWSER
313316
after_script:
314-
- node ./scripts/test/export-test-result.ts unit-bs
317+
- node ./scripts/test/export-test-result.ts unit-bs-$BS_BROWSER
315318

316319
script-tests:
317320
extends:

‎scripts/test/ci-bs.ts‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { parseArgs } from 'node:util'
12
import { printLog, runMain } from '../lib/executionUtils.ts'
23
import { command } from '../lib/command.ts'
34
import { fetchPR, getLastCommonCommit, LOCAL_BRANCH } from '../lib/gitUtils.ts'
@@ -16,9 +17,20 @@ const RELEVANT_FILE_PATTERNS = [
1617
]
1718

1819
runMain(async () => {
19-
const testCommand = process.argv[2]
20+
const {
21+
values: { browser },
22+
positionals,
23+
} = parseArgs({
24+
args: process.argv.slice(2),
25+
options: {
26+
browser: { type: 'string' },
27+
},
28+
allowPositionals: true,
29+
})
30+
31+
const testCommand = positionals[0]
2032
if (!testCommand) {
21-
throw new Error('Usage: ci-bs.ts <test:unit>')
33+
throw new Error('Usage: ci-bs.ts <test:unit> [--browser <id>]')
2234
}
2335

2436
const pr = await fetchPR(LOCAL_BRANCH!)
@@ -30,13 +42,19 @@ runMain(async () => {
3042
return
3143
}
3244

33-
command`yarn ${testCommand}:bs`
34-
.withEnvironment({
35-
BS_USERNAME: getBrowserStackUsername(),
36-
BS_ACCESS_KEY: getBrowserStackAccessKey(),
37-
})
38-
.withLogs()
39-
.run()
45+
const environment: Record<string, string> = {
46+
BS_USERNAME: getBrowserStackUsername(),
47+
BS_ACCESS_KEY: getBrowserStackAccessKey(),
48+
}
49+
50+
if (browser) {
51+
environment.BS_BROWSER = browser
52+
// Override CI_JOB_NAME so getTestReportDirectory() produces a per-browser path
53+
// (e.g. test-report/unit-bs-firefox/) instead of sharing test-report/unit-bs/ across all browsers.
54+
environment.CI_JOB_NAME = `unit-bs-${browser}`
55+
}
56+
57+
command`yarn ${testCommand}:bs`.withEnvironment(environment).withLogs().run()
4058
})
4159

4260
function hasRelevantChanges(baseCommit: string): boolean {

‎test/browsers.conf.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface BrowserConfiguration {
2+
id?: string
23
sessionName: string
34
name: string
45
version?: string

‎test/unit/browsers.conf.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,39 @@ export const OLDEST_BROWSER_ECMA_VERSION = 2017
99

1010
export const browserConfigurations: BrowserConfiguration[] = [
1111
{
12+
id: 'edge',
1213
sessionName: 'Edge',
1314
name: 'Edge',
1415
version: '80.0',
1516
os: 'Windows',
1617
osVersion: '11',
1718
},
1819
{
20+
id: 'firefox',
1921
sessionName: 'Firefox',
2022
name: 'Firefox',
2123
version: '78.0',
2224
os: 'Windows',
2325
osVersion: '11',
2426
},
2527
{
28+
id: 'safari-desktop',
2629
sessionName: 'Safari desktop',
2730
name: 'Safari',
2831
version: '14.0',
2932
os: 'OS X',
3033
osVersion: 'Big Sur',
3134
},
3235
{
36+
id: 'chrome-desktop',
3337
sessionName: 'Chrome desktop',
3438
name: 'Chrome',
3539
version: '80.0',
3640
os: 'Windows',
3741
osVersion: '11',
3842
},
3943
{
44+
id: 'chrome-mobile',
4045
sessionName: 'Chrome mobile',
4146
name: 'chrome',
4247
os: 'android',

‎test/unit/karma.bs.conf.js‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import { getBuildInfos } from '../envUtils.ts'
22
import { browserConfigurations } from './browsers.conf.ts'
33
import karmaBaseConf from './karma.base.conf.js'
44

5+
const selectedBrowser = process.env.BS_BROWSER
6+
const filteredConfigurations = selectedBrowser
7+
? browserConfigurations.filter((configuration) => configuration.id === selectedBrowser)
8+
: browserConfigurations
9+
10+
if (selectedBrowser && filteredConfigurations.length === 0) {
11+
const availableIds = browserConfigurations.map((c) => c.id).join(', ')
12+
throw new Error(`Unknown BS_BROWSER "${selectedBrowser}". Available: ${availableIds}`)
13+
}
14+
515
// eslint-disable-next-line import/no-default-export
616
export default function (config) {
717
config.set({
@@ -13,8 +23,8 @@ export default function (config) {
1323
],
1424
plugins: [...karmaBaseConf.plugins, 'karma-browserstack-launcher'],
1525
reporters: [...karmaBaseConf.reporters, 'BrowserStack'],
16-
browsers: browserConfigurations.map((configuration) => configuration.sessionName),
17-
concurrency: 5,
26+
browsers: filteredConfigurations.map((configuration) => configuration.sessionName),
27+
concurrency: 1,
1828
browserDisconnectTolerance: 3,
1929
captureTimeout: 2 * 60 * 1000,
2030
browserStack: {
@@ -25,7 +35,7 @@ export default function (config) {
2535
video: false,
2636
},
2737
customLaunchers: Object.fromEntries(
28-
browserConfigurations.map((configuration) => [
38+
filteredConfigurations.map((configuration) => [
2939
configuration.sessionName,
3040
// See https://github.com/karma-runner/karma-browserstack-launcher#per-browser-options
3141
{

0 commit comments

Comments
 (0)