@@ -22,6 +22,27 @@ require('dotenv').config();
2222const { execSync } = require ( 'child_process' ) ;
2323const browserstack = require ( 'browserstack-local' ) ;
2424
25+ // Browser configurations grouped by browser name
26+ const BROWSER_CONFIGS = {
27+ chrome : [
28+ { name : 'chrome-windows-latest' , browserVersion : 'latest' , os : 'Windows' , osVersion : '11' } ,
29+ { name : 'chrome-windows-102' , browserVersion : '102' , os : 'Windows' , osVersion : '11' } ,
30+ ] ,
31+ firefox : [
32+ { name : 'firefox-windows-latest' , browserVersion : 'latest' , os : 'Windows' , osVersion : '11' } ,
33+ { name : 'firefox-windows-91' , browserVersion : '91' , os : 'Windows' , osVersion : '11' } ,
34+ ] ,
35+ edge : [
36+ { name : 'edge-windows-latest' , browserVersion : 'latest' , os : 'Windows' , osVersion : '11' } ,
37+ { name : 'edge-windows-84' , browserVersion : '84' , os : 'Windows' , osVersion : '10' } ,
38+ ] ,
39+ safari : [
40+ { name : 'safari-monterey' , os : 'OS X' , osVersion : 'Monterey' } ,
41+ // { name: 'safari-ventura', os: 'OS X', osVersion: 'Ventura' },
42+ { name : 'safari-sonoma' , os : 'OS X' , osVersion : 'Sonoma' } ,
43+ ]
44+ } ;
45+
2546// Determine if we should use local browser or BrowserStack
2647// Priority: USE_LOCAL_BROWSER env var, then check for BrowserStack credentials
2748let useLocalBrowser = process . env . USE_LOCAL_BROWSER === 'true' ;
@@ -90,12 +111,18 @@ function stopTunnel() {
90111 } ) ;
91112}
92113
93- let hasFailures = false ;
94-
95114async function runTests ( ) {
96115 try {
97116 // Get browser name from environment variable (default to chrome)
98- const browserName = process . env . VITEST_BROWSER || 'chrome' ;
117+ const browserName = ( process . env . TEST_BROWSER || 'chrome' ) . toLowerCase ( ) ;
118+
119+ // Get configs for this browser
120+ const configs = BROWSER_CONFIGS [ browserName ] ;
121+ if ( ! configs || configs . length === 0 ) {
122+ console . error ( `Error: No configurations found for browser '${ browserName } '` ) ;
123+ console . error ( `Available browsers: ${ Object . keys ( BROWSER_CONFIGS ) . join ( ', ' ) } ` ) ;
124+ process . exit ( 1 ) ;
125+ }
99126
100127 // Only start tunnel if using BrowserStack
101128 if ( ! useLocalBrowser ) {
@@ -104,47 +131,84 @@ async function runTests() {
104131 console . log ( 'Using local browser mode - no BrowserStack connection needed' ) ;
105132 }
106133
107- console . log ( `\n${ '=' . repeat ( 80 ) } ` ) ;
108- console . log ( `Running tests on ${ useLocalBrowser ? 'local' : 'BrowserStack' } : ${ browserName } ` ) ;
134+ console . log ( '\n' + '=' . repeat ( 80 ) ) ;
135+ console . log ( `Running tests for browser: ${ browserName } ` ) ;
136+ console . log ( `Total configurations: ${ configs . length } ` ) ;
137+ console . log ( '=' . repeat ( 80 ) + '\n' ) ;
138+
139+ const results = [ ] ;
140+
141+ // Run each config serially
142+ for ( const config of configs ) {
143+ console . log ( `\n${ '=' . repeat ( 80 ) } ` ) ;
144+ console . log ( `Running: ${ config . name } ` ) ;
145+ console . log ( `Browser: ${ browserName } ${ config . browserVersion ? ` ${ config . browserVersion } ` : '' } ` ) ;
146+ console . log ( `OS: ${ config . os } ${ config . osVersion } ` ) ;
147+ console . log ( '=' . repeat ( 80 ) ) ;
148+
149+ // Set environment variables for this config
150+ const env = {
151+ ...process . env ,
152+ USE_LOCAL_BROWSER : useLocalBrowser ? 'true' : 'false' ,
153+ TEST_BROWSER : browserName ,
154+ TEST_BROWSER_VERSION : config . browserVersion || '' ,
155+ TEST_OS_NAME : config . os ,
156+ TEST_OS_VERSION : config . osVersion ,
157+ } ;
158+
159+ try {
160+ // Run vitest with the browser config
161+ execSync ( 'npm run test-vitest -- --config vitest.browser.config.mts' , {
162+ stdio : 'inherit' ,
163+ env,
164+ } ) ;
165+
166+ console . log ( `\n✓ ${ config . name } passed!` ) ;
167+ results . push ( { config : config . name , success : true } ) ;
168+ } catch ( error ) {
169+ console . error ( `\n✗ ${ config . name } failed` ) ;
170+ results . push ( { config : config . name , success : false } ) ;
171+ }
172+ }
173+
174+ // Print summary
175+ console . log ( '\n' + '=' . repeat ( 80 ) ) ;
176+ console . log ( `Browser test summary for ${ browserName } :` ) ;
109177 console . log ( '=' . repeat ( 80 ) ) ;
110178
111- // Set environment variables
112- const env = {
113- ...process . env ,
114- USE_LOCAL_BROWSER : useLocalBrowser ? 'true' : 'false' ,
115- VITEST_BROWSER : browserName ,
116- } ;
117-
118- try {
119- // Run vitest with the browser config
120- execSync ( 'npm run test-vitest -- --config vitest.browser.config.mts' , {
121- stdio : 'inherit' ,
122- env,
123- } ) ;
124-
125- console . log ( `\n✓ ${ browserName } tests passed!` ) ;
126- } catch ( error ) {
127- console . error ( `\n✗ ${ browserName } tests failed` ) ;
128- hasFailures = true ;
129- }
179+ const failures = [ ] ;
180+ const successes = [ ] ;
130181
131- console . log ( `\n${ '=' . repeat ( 80 ) } ` ) ;
132- console . log ( 'Browser test summary:' ) ;
182+ results . forEach ( ( { config, success } ) => {
183+ if ( success ) {
184+ successes . push ( config ) ;
185+ console . log ( `✓ ${ config } : PASSED` ) ;
186+ } else {
187+ failures . push ( config ) ;
188+ console . error ( `✗ ${ config } : FAILED` ) ;
189+ }
190+ } ) ;
191+
192+ console . log ( '=' . repeat ( 80 ) ) ;
193+ console . log ( `Total: ${ results . length } configurations` ) ;
194+ console . log ( `Passed: ${ successes . length } ` ) ;
195+ console . log ( `Failed: ${ failures . length } ` ) ;
133196 console . log ( '=' . repeat ( 80 ) ) ;
134197
135- if ( hasFailures ) {
136- console . error ( `${ browserName } tests failed. See above for details.` ) ;
198+ // Exit with failure if any config failed
199+ if ( failures . length > 0 ) {
200+ console . error ( `\nSome ${ browserName } configurations failed. See above for details.` ) ;
201+ process . exit ( 1 ) ;
137202 } else {
138- console . log ( `${ browserName } tests passed!` ) ;
203+ console . log ( `\nAll ${ browserName } configurations passed!` ) ;
204+ process . exit ( 0 ) ;
139205 }
140206 } finally {
141207 // Only stop tunnel if using BrowserStack
142208 if ( ! useLocalBrowser ) {
143209 await stopTunnel ( ) ;
144210 }
145211 }
146-
147- process . exit ( hasFailures ? 1 : 0 ) ;
148212}
149213
150214// Run the tests
0 commit comments