Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,18 @@ unit-bs:
- .base-configuration
- .bs-allowed-branches
interruptible: true
resource_group: browserstack
resource_group: browserstack-$BS_BROWSER
parallel:
matrix:
- BS_BROWSER: [edge, firefox, safari-desktop, chrome-desktop, chrome-mobile]
artifacts:
reports:
junit: test-report/unit-bs/*.xml
junit: test-report/unit-bs-$BS_BROWSER/*.xml
Comment thread
mormubis marked this conversation as resolved.
Outdated
script:
- yarn
- node scripts/test/ci-bs.ts test:unit
- node scripts/test/ci-bs.ts test:unit --browser $BS_BROWSER
after_script:
- node ./scripts/test/export-test-result.ts unit-bs
- node ./scripts/test/export-test-result.ts unit-bs-$BS_BROWSER
Comment thread
mormubis marked this conversation as resolved.
Outdated

script-tests:
extends:
Expand Down
36 changes: 27 additions & 9 deletions scripts/test/ci-bs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { parseArgs } from 'node:util'
import { printLog, runMain } from '../lib/executionUtils.ts'
import { command } from '../lib/command.ts'
import { fetchPR, getLastCommonCommit, LOCAL_BRANCH } from '../lib/gitUtils.ts'
Expand All @@ -16,9 +17,20 @@ const RELEVANT_FILE_PATTERNS = [
]

runMain(async () => {
const testCommand = process.argv[2]
const {
values: { browser },
positionals,
} = parseArgs({
args: process.argv.slice(2),
options: {
browser: { type: 'string' },
},
allowPositionals: true,
})

const testCommand = positionals[0]
if (!testCommand) {
throw new Error('Usage: ci-bs.ts <test:unit>')
throw new Error('Usage: ci-bs.ts <test:unit> [--browser <id>]')
}

const pr = await fetchPR(LOCAL_BRANCH!)
Expand All @@ -30,13 +42,19 @@ runMain(async () => {
return
}

command`yarn ${testCommand}:bs`
.withEnvironment({
BS_USERNAME: getBrowserStackUsername(),
BS_ACCESS_KEY: getBrowserStackAccessKey(),
})
.withLogs()
.run()
const environment: Record<string, string> = {
BS_USERNAME: getBrowserStackUsername(),
BS_ACCESS_KEY: getBrowserStackAccessKey(),
}

if (browser) {
environment.BS_BROWSER = browser
// Override CI_JOB_NAME so getTestReportDirectory() produces a per-browser path
// (e.g. test-report/unit-bs-firefox/) instead of sharing test-report/unit-bs/ across all browsers.
environment.CI_JOB_NAME = `unit-bs-${browser}`
Comment thread
mormubis marked this conversation as resolved.
Outdated
}

command`yarn ${testCommand}:bs`.withEnvironment(environment).withLogs().run()
})

function hasRelevantChanges(baseCommit: string): boolean {
Expand Down
1 change: 1 addition & 0 deletions test/browsers.conf.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface BrowserConfiguration {
id?: string
sessionName: string
name: string
version?: string
Expand Down
5 changes: 5 additions & 0 deletions test/unit/browsers.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,39 @@ export const OLDEST_BROWSER_ECMA_VERSION = 2017

export const browserConfigurations: BrowserConfiguration[] = [
{
id: 'edge',
sessionName: 'Edge',
name: 'Edge',
version: '80.0',
os: 'Windows',
osVersion: '11',
},
{
id: 'firefox',
sessionName: 'Firefox',
name: 'Firefox',
version: '78.0',
os: 'Windows',
osVersion: '11',
},
{
id: 'safari-desktop',
sessionName: 'Safari desktop',
name: 'Safari',
version: '14.0',
os: 'OS X',
osVersion: 'Big Sur',
},
{
id: 'chrome-desktop',
sessionName: 'Chrome desktop',
name: 'Chrome',
version: '80.0',
os: 'Windows',
osVersion: '11',
},
{
id: 'chrome-mobile',
sessionName: 'Chrome mobile',
name: 'chrome',
os: 'android',
Expand Down
16 changes: 13 additions & 3 deletions test/unit/karma.bs.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { getBuildInfos } from '../envUtils.ts'
import { browserConfigurations } from './browsers.conf.ts'
import karmaBaseConf from './karma.base.conf.js'

const selectedBrowser = process.env.BS_BROWSER
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ question: ‏would it be possible to use parseArgs here, so we don't need to read it in ci-bs.ts and pass it here as env variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. --browser is parsed by ci-bs.ts, not by Karma. To use parseArgs in the Karma config we'd need to forward the flag through ci-bs.ts, bs-wrapper.ts and then karma start. The env var is simpler here because GitLab already sets BS_BROWSER as a matrix variable. What do you think?

const filteredConfigurations = selectedBrowser
? browserConfigurations.filter((configuration) => configuration.id === selectedBrowser)
: browserConfigurations

if (selectedBrowser && filteredConfigurations.length === 0) {
const availableIds = browserConfigurations.map((c) => c.id).join(', ')
throw new Error(`Unknown BS_BROWSER "${selectedBrowser}". Available: ${availableIds}`)
}

// eslint-disable-next-line import/no-default-export
export default function (config) {
config.set({
Expand All @@ -13,8 +23,8 @@ export default function (config) {
],
plugins: [...karmaBaseConf.plugins, 'karma-browserstack-launcher'],
reporters: [...karmaBaseConf.reporters, 'BrowserStack'],
browsers: browserConfigurations.map((configuration) => configuration.sessionName),
concurrency: 5,
browsers: filteredConfigurations.map((configuration) => configuration.sessionName),
concurrency: 1,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore full-run BrowserStack concurrency

When BS_BROWSER is unset (the documented backward-compatible yarn test:unit:bs / ci-bs.ts test:unit path), filteredConfigurations still contains all five BrowserStack launchers but this now forces concurrency to 1. That makes the full BrowserStack run execute the five browsers serially instead of the previous concurrency: 5, so the fallback/local full run no longer behaves “as before” and takes roughly five times longer; keep 1 only for the single-browser filtered case.

Useful? React with 👍 / 👎.

browserDisconnectTolerance: 3,
captureTimeout: 2 * 60 * 1000,
browserStack: {
Expand All @@ -25,7 +35,7 @@ export default function (config) {
video: false,
},
customLaunchers: Object.fromEntries(
browserConfigurations.map((configuration) => [
filteredConfigurations.map((configuration) => [
configuration.sessionName,
// See https://github.com/karma-runner/karma-browserstack-launcher#per-browser-options
{
Expand Down
Loading