Skip to content

Commit 298974a

Browse files
committed
local-identifiere
1 parent 6bcdd4d commit 298974a

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

.github/workflows/javascript.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ jobs:
4444
runs-on: ubuntu-latest
4545
strategy:
4646
fail-fast: false
47-
max-parallel: 1
4847
matrix:
4948
browser: ['chrome', 'firefox', 'edge', 'safari']
5049
env:

scripts/run-browser-tests.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@ const browserstack = require('browserstack-local');
2121
// Browser configurations grouped by browser name
2222
const BROWSER_CONFIGS = {
2323
chrome: [
24-
// { name: 'chrome-windows-latest', browserVersion: 'latest', os: 'Windows', osVersion: '11' },
25-
{ name: 'chrome-windows-102', browserVersion: '102', os: 'Windows', osVersion: '11' },
24+
{ name: 'chrome-102-windows', browserVersion: '102', os: 'Windows', osVersion: '11' },
25+
{ name: 'chrome-latest-windows', browserVersion: 'latest', os: 'Windows', osVersion: '11' },
2626
],
2727
firefox: [
28-
{ name: 'firefox-windows-91', browserVersion: '91', os: 'Windows', osVersion: '11' },
28+
{ name: 'firefox-91-windows', browserVersion: '91', os: 'Windows', osVersion: '11' },
29+
{ name: 'firefox-latest-macos', browserVersion: 'latest', os: 'OS X', osVersion: 'Sequoia' },
2930
],
3031
edge: [
31-
// { name: 'edge-windows-latest', browserVersion: 'latest', os: 'Windows', osVersion: '11' },
32-
{ name: 'edge-windows-88', browserVersion: '88', os: 'Windows', osVersion: '11' },
32+
{ name: 'edge-89-windows', browserVersion: '89', os: 'Windows', osVersion: '11' },
33+
{ name: 'edge-latest-windows', browserVersion: 'latest', os: 'Windows', osVersion: '11' },
3334
],
3435
safari: [
3536
{ name: 'safari-monterey', os: 'OS X', osVersion: 'Monterey' },
36-
// { name: 'safari-sonoma', os: 'OS X', osVersion: 'Sonoma' },
37+
{ name: 'safari-sequoia', os: 'OS X', osVersion: 'Sequoia' },
3738
]
3839
};
3940

@@ -59,24 +60,22 @@ if (!useLocalBrowser) {
5960
}
6061
}
6162

62-
// BrowserStack Local is optional - only needed if tests require localhost access
63-
const useBrowserStackLocal = process.env.BROWSERSTACK_LOCAL === 'true';
63+
6464
let bs_local = null;
6565

66-
function startTunnel() {
67-
const username = process.env.BROWSERSTACK_USERNAME || process.env.BROWSER_STACK_USERNAME;
66+
function startTunnel(localIdentifier) {
6867
const accessKey = process.env.BROWSERSTACK_ACCESS_KEY || process.env.BROWSER_STACK_ACCESS_KEY;
6968

70-
console.log('Starting BrowserStack Local tunnel...');
69+
console.log(`Starting BrowserStack Local tunnel with identifier: ${localIdentifier}...`);
7170
bs_local = new browserstack.Local();
7271
const bsLocalArgs = {
7372
key: accessKey,
7473
force: true,
7574
forceLocal: true,
7675
// Enable verbose logging to debug tunnel issues
7776
verbose: true,
78-
// Enable local testing for all sites - more permissive
79-
onlyAutomate: true,
77+
// Use the provided identifier for parallel tunnel support
78+
localIdentifier: localIdentifier,
8079
};
8180

8281
return new Promise((resolve, reject) => {
@@ -86,7 +85,8 @@ function startTunnel() {
8685
reject(error);
8786
} else {
8887
console.log('BrowserStack Local tunnel started successfully');
89-
console.log(`Local Identifier: ${bs_local.pid}`);
88+
console.log(`BrowserStack Local PID: ${bs_local.pid}`);
89+
console.log(`Local Identifier: ${localIdentifier}`);
9090
// Wait longer for tunnel to fully establish and register with BrowserStack
9191
console.log('Waiting for tunnel to establish...');
9292
setTimeout(() => {
@@ -147,8 +147,12 @@ async function runTests() {
147147
}
148148

149149
// Only start tunnel if using BrowserStack
150+
let localIdentifier;
150151
if (!useLocalBrowser) {
151-
await startTunnel();
152+
// Generate a random identifier for parallel tunnel support (100000-900000)
153+
localIdentifier = Math.floor(Math.random() * 800000) + 100000;
154+
localIdentifier = localIdentifier.toString();
155+
await startTunnel(localIdentifier);
152156
} else {
153157
console.log('Using local browser mode - no BrowserStack connection needed');
154158
}
@@ -175,6 +179,8 @@ async function runTests() {
175179
TEST_BROWSER_VERSION: config.browserVersion,
176180
TEST_OS_NAME: config.os,
177181
TEST_OS_VERSION: config.osVersion,
182+
// Pass the local identifier to vitest config for BrowserStack capabilities
183+
BROWSERSTACK_LOCAL_IDENTIFIER: localIdentifier,
178184
};
179185

180186

vitest.browser.config.mts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ function buildLocalCapabilities() {
5555

5656
// Build BrowserStack capabilities
5757
function buildBrowserStackCapabilities() {
58+
const localIdentifier = process.env.BROWSERSTACK_LOCAL_IDENTIFIER;
59+
5860
return {
5961
browserName: testBrowser,
6062
'wdio:enforceWebDriverClassic': true, // this doesn't work due to vitest bug, still keeping here for future reference
@@ -73,10 +75,13 @@ function buildBrowserStackCapabilities() {
7375
projectName: 'Optimizely JavaScript SDK',
7476
sessionName: `${testBrowser} ${testBrowserVersion || ''} on ${testOsName} ${testOsVersion}`,
7577
local: true,
76-
debug: false,
77-
networkLogs: false,
78-
consoleLogs: 'errors' as const,
79-
seleniumLogs: false,
78+
// Include localIdentifier for parallel tunnel support
79+
...(localIdentifier && { localIdentifier }),
80+
debug: true,
81+
networkLogs: true,
82+
consoleLogs: 'verbose' as const,
83+
seleniumLogs: true,
84+
video: true,
8085
idleTimeout: 900, // 15 minutes idle timeout - prevents premature session closure during long test runs
8186
},
8287
};
@@ -121,11 +126,11 @@ export default defineConfig({
121126
},
122127
},
123128
esbuild: {
124-
target: 'es2015',
125-
format: 'esm',
129+
target: 'es2015',
130+
format: 'esm',
126131
},
127132
build: {
128-
target: 'es2015',
133+
target: 'es2015',
129134
},
130135
optimizeDeps: {
131136
// Force chai to be pre-bundled with ES6 target to remove class static blocks
@@ -144,7 +149,7 @@ export default defineConfig({
144149
isolate: false,
145150
fileParallelism: true,
146151
// Reduce concurrency for BrowserStack to minimize tunnel load and WebSocket connection issues
147-
maxConcurrency: useLocalBrowser ? 5 : 1,
152+
maxConcurrency: 3,
148153
onConsoleLog: () => true,
149154
browser: {
150155
enabled: true,

0 commit comments

Comments
 (0)