Skip to content

Commit 61066db

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

5 files changed

Lines changed: 34 additions & 12 deletions

File tree

‎.gitlab-ci.yml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,16 @@ 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:
309312
junit: test-report/unit-bs/*.xml
310313
script:
311314
- yarn
312-
- node scripts/test/ci-bs.ts test:unit
315+
- BS_BROWSER=$BS_BROWSER node scripts/test/ci-bs.ts test:unit
313316
after_script:
314317
- node ./scripts/test/export-test-result.ts unit-bs
315318

‎scripts/test/ci-bs.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ runMain(async () => {
3030
return
3131
}
3232

33-
command`yarn ${testCommand}:bs`
34-
.withEnvironment({
35-
BS_USERNAME: getBrowserStackUsername(),
36-
BS_ACCESS_KEY: getBrowserStackAccessKey(),
37-
})
38-
.withLogs()
39-
.run()
33+
const environment: Record<string, string> = {
34+
BS_USERNAME: getBrowserStackUsername(),
35+
BS_ACCESS_KEY: getBrowserStackAccessKey(),
36+
}
37+
38+
if (process.env.BS_BROWSER) {
39+
environment.BS_BROWSER = process.env.BS_BROWSER
40+
}
41+
42+
command`yarn ${testCommand}:bs`.withEnvironment(environment).withLogs().run()
4043
})
4144

4245
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: filteredConfigurations.length,
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)