1616/// <reference types="@vitest/browser/providers/webdriverio" />
1717import path from 'path' ;
1818import { defineConfig } from 'vitest/config'
19- import type { BrowserInstanceOption } from 'vitest/node'
20- import { transform } from 'esbuild'
2119import dotenv from 'dotenv' ;
22- import tsconfigPaths from 'vite-tsconfig-paths'
20+ // import type { BrowserInstanceOption } from 'vitest/node'
21+ // import { transform } from 'esbuild'
22+ // import tsconfigPaths from 'vite-tsconfig-paths'
2323
2424// Load environment variables from .env file
2525dotenv . config ( ) ;
@@ -170,24 +170,12 @@ const useLocalBrowser = process.env.USE_LOCAL_BROWSER === 'true';
170170// };
171171// }
172172
173- // Define browser configuration types
174- interface BrowserConfig {
175- name : string ;
176- browserName : string ;
177- browserVersion : string ;
178- os : string ;
179- osVersion : string ;
180- }
181-
182173// Define browser configurations
183- // Testing minimum supported versions: Edge 84+, Firefox 91+, Safari 13+, Chrome 102+, Opera 76+
184- const allBrowserConfigs : BrowserConfig [ ] = [
185- { name : 'chrome' , browserName : 'chrome' , browserVersion : '102' , os : 'Windows' , osVersion : '11' } ,
186- // { name: 'firefox', browserName: 'firefox', browserVersion: '91', os: 'Windows', osVersion: '11' },
187- // { name: 'edge', browserName: 'edge', browserVersion: '84', os: 'Windows', osVersion: '10' },
188- // { name: 'safari', browserName: 'safari', browserVersion: '14', os: 'OS X', osVersion: 'Big Sur' },
189- // { name: 'chrome', browserName: 'chrome', browserVersion: '102', os: 'OS X', osVersion: 'Big Sur' },
190- // { name: 'opera', browserName: 'opera', browserVersion: '76', os: 'Windows', osVersion: '11' },
174+ const allBrowserConfigs = [
175+ { name : 'chrome' , browserName : 'chrome' , os : 'Windows' , osVersion : '11' } ,
176+ // { name: 'firefox', browserName: 'firefox', os: 'Windows', osVersion: '11' },
177+ // { name: 'edge', browserName: 'edge', os: 'Windows', osVersion: '11' },
178+ // { name: 'safari', browserName: 'safari', os: 'OS X', osVersion: 'Big Sur' },
191179] ;
192180
193181// Filter browsers based on VITEST_BROWSER environment variable
@@ -196,93 +184,52 @@ const browserConfigs = browserFilter
196184 ? allBrowserConfigs . filter ( config => config . name === browserFilter . toLowerCase ( ) )
197185 : allBrowserConfigs ;
198186
199- // Local browser capabilities type
200- interface LocalCapabilities {
201- browserName : string ;
202- 'goog:chromeOptions' ?: {
203- args : string [ ] ;
204- } ;
205- 'webkit:WebRTC' ?: {
206- DisableICECandidateFiltering ?: boolean ;
207- } ;
208- }
209-
210187// Build local browser capabilities
211- function buildLocalCapabilities ( browserName : string ) : LocalCapabilities {
212- const baseCapabilities : LocalCapabilities = {
188+ function buildLocalCapabilities ( browserName : string ) {
189+ return {
213190 browserName,
214- } ;
215-
216- // Add browser-specific options
217- if ( browserName === 'chrome' || browserName === 'edge' ) {
218- baseCapabilities [ 'goog:chromeOptions' ] = {
191+ 'goog:chromeOptions' : {
219192 args : [
220193 '--disable-blink-features=AutomationControlled' ,
221194 '--disable-dev-shm-usage' ,
222195 '--no-sandbox' ,
223196 ] ,
224- } ;
225- } else if ( browserName === 'safari' ) {
226- // Safari uses safaridriver and doesn't need special options for basic testing
227- // safaridriver is built into macOS and starts automatically
228- baseCapabilities [ 'webkit:WebRTC' ] = {
229- DisableICECandidateFiltering : true ,
230- } ;
231- }
232-
233- return baseCapabilities ;
197+ } ,
198+ } ;
234199}
235200
236201// Build BrowserStack capabilities
237202function buildBrowserStackCapabilities ( config : typeof allBrowserConfigs [ 0 ] ) {
238- const capabilities : any = {
203+ return {
239204 browserName : config . browserName ,
205+ 'goog:chromeOptions' : {
206+ args : [
207+ '--disable-blink-features=AutomationControlled' ,
208+ '--disable-dev-shm-usage' ,
209+ '--no-sandbox' ,
210+ ] ,
211+ } ,
240212 'bstack:options' : {
241213 os : config . os ,
242214 osVersion : config . osVersion ,
243- browserVersion : config . browserVersion ,
215+ browserVersion : 'latest' ,
244216 buildName : process . env . VITEST_BUILD_NAME || 'Vitest Browser Tests' ,
245217 projectName : 'Optimizely JavaScript SDK' ,
246- sessionName : `${ config . browserName } ${ config . browserVersion } on ${ config . os } ${ config . osVersion } ` ,
218+ sessionName : `${ config . browserName } on ${ config . os } ${ config . osVersion } ` ,
247219 local : process . env . BROWSERSTACK_LOCAL === 'true' ? true : false ,
248- wsLocalSupport : true ,
249- disableCorsRestrictions : true ,
250220 debug : true ,
251221 networkLogs : true ,
252222 consoleLogs : 'verbose' as const ,
253223 idleTimeout : 300 , // 5 minutes idle timeout
254224 } ,
255225 } ;
256-
257- // Add browser-specific options
258- if ( config . browserName === 'chrome' || config . browserName === 'edge' ) {
259- capabilities [ 'goog:chromeOptions' ] = {
260- args : [
261- '--disable-blink-features=AutomationControlled' ,
262- '--disable-dev-shm-usage' ,
263- '--no-sandbox' ,
264- ] ,
265- } ;
266- } else if ( config . browserName === 'safari' ) {
267- // Safari-specific capabilities to enable WebSocket connections
268- capabilities [ 'webkit:WebRTC' ] = {
269- DisableICECandidateFiltering : true ,
270- } ;
271- // Disable automatic HTTPS to allow HTTP connections (needed for ws:// WebSocket)
272- capabilities [ 'acceptInsecureCerts' ] = true ;
273- // Enable technology preview features for better WebSocket support
274- capabilities [ 'safari:automaticInspection' ] = false ;
275- capabilities [ 'safari:automaticProfiling' ] = false ;
276- }
277-
278- return capabilities ;
279226}
280227
281228// Build browser instance configuration
282- function buildBrowserInstances ( ) : BrowserInstanceOption [ ] {
229+ function buildBrowserInstances ( ) {
283230 if ( useLocalBrowser ) {
284231 // Local browser configurations - all browsers
285- return browserConfigs . map ( ( config : BrowserConfig ) : BrowserInstanceOption => ( {
232+ return browserConfigs . map ( config => ( {
286233 browser : config . browserName ,
287234 capabilities : buildLocalCapabilities ( config . browserName ) ,
288235 logLevel : 'error' as const ,
@@ -292,17 +239,12 @@ function buildBrowserInstances(): BrowserInstanceOption[] {
292239 const username = process . env . BROWSERSTACK_USERNAME || process . env . BROWSER_STACK_USERNAME ;
293240 const key = process . env . BROWSERSTACK_ACCESS_KEY || process . env . BROWSER_STACK_ACCESS_KEY ;
294241
295- return browserConfigs . map ( ( config : BrowserConfig ) : BrowserInstanceOption => ( {
242+ return browserConfigs . map ( config => ( {
296243 browser : config . browserName ,
297244 user : username ,
298245 key : key ,
299246 capabilities : buildBrowserStackCapabilities ( config ) ,
300- // WebDriverIO options to handle session cleanup and stability
301- // Safari on BrowserStack can be slow to start, increase timeouts
302- connectionRetryTimeout : config . browserName === 'safari' ? 300000 : 180000 , // 5 minutes for Safari, 3 for others
303- connectionRetryCount : 3 ,
304- waitforTimeout : config . browserName === 'safari' ? 180000 : 120000 , // 3 minutes for Safari, 2 for others
305- logLevel : 'trace' as const ,
247+ logLevel : 'error' as const ,
306248 } ) ) ;
307249 }
308250}
@@ -325,15 +267,20 @@ export default defineConfig({
325267 if ( event === 'request' ) {
326268 const req = args [ 0 ] ;
327269 const url = req . url || '' ;
328- console . log ( `[HTTP REQUEST] ${ req . method } http://${ req . headers . host } ${ url } ` ) ;
270+
271+ // Detect protocol from request
272+ const isSecure = req . connection ?. encrypted || req . socket ?. encrypted || req . headers [ 'x-forwarded-proto' ] === 'https' ;
273+ const protocol = isSecure ? 'https' : 'http' ;
274+
275+ console . log ( `[HTTP REQUEST] ${ req . method } ${ protocol } ://${ req . headers . host } ${ url } ` ) ;
329276
330277 if ( url . includes ( '__vitest_test__' ) && url . includes ( 'sessionId=' ) ) {
331- const fullUrl = new URL ( url , `http ://${ req . headers . host } ` ) ;
278+ const fullUrl = new URL ( url , `${ protocol } ://${ req . headers . host } ` ) ;
332279 const sessionId = fullUrl . searchParams . get ( 'sessionId' ) ;
333280 console . log ( '\n' + '=' . repeat ( 80 ) ) ;
334281 console . log ( `[VITEST TEST PAGE REQUEST]` ) ;
335282 console . log ( `Session ID: ${ sessionId } ` ) ;
336- console . log ( `Full URL: http ://${ req . headers . host } ${ url } ` ) ;
283+ console . log ( `Full URL: ${ protocol } ://${ req . headers . host } ${ url } ` ) ;
337284 console . log ( `Time: ${ new Date ( ) . toISOString ( ) } ` ) ;
338285 console . log ( '=' . repeat ( 80 ) + '\n' ) ;
339286 }
@@ -342,16 +289,20 @@ export default defineConfig({
342289 const url = req . url || '' ;
343290 const isWebSocket = req . headers . upgrade ?. toLowerCase ( ) === 'websocket' ;
344291
292+ // Detect protocol from request
293+ const isSecure = req . connection ?. encrypted || req . socket ?. encrypted || req . headers [ 'x-forwarded-proto' ] === 'https' ;
294+ const protocol = isSecure ? 'https' : 'http' ;
295+
345296 console . log ( '\n' + '-' . repeat ( 80 ) ) ;
346297 console . log ( `[WEBSOCKET UPGRADE REQUEST]` ) ;
347- console . log ( `URL: http ://${ req . headers . host } ${ url } ` ) ;
298+ console . log ( `URL: ${ protocol } ://${ req . headers . host } ${ url } ` ) ;
348299 console . log ( `Upgrade Header: ${ req . headers . upgrade } ` ) ;
349300 console . log ( `Connection Header: ${ req . headers . connection } ` ) ;
350301 console . log ( `Is WebSocket: ${ isWebSocket } ` ) ;
351302 console . log ( `Time: ${ new Date ( ) . toISOString ( ) } ` ) ;
352303
353304 if ( url . includes ( 'sessionId=' ) ) {
354- const fullUrl = new URL ( url , `http ://${ req . headers . host } ` ) ;
305+ const fullUrl = new URL ( url , `${ protocol } ://${ req . headers . host } ` ) ;
355306 const sessionId = fullUrl . searchParams . get ( 'sessionId' ) ;
356307 console . log ( `Session ID: ${ sessionId } ` ) ;
357308 }
@@ -409,12 +360,13 @@ export default defineConfig({
409360 fs : {
410361 strict : false , // Allow serving files outside root to prevent favicon issues
411362 } ,
412- hmr : {
413- // Configure WebSocket for Safari compatibility
414- protocol : 'ws' ,
415- host : 'bs-local.com' ,
416- port : 5173 ,
417- } ,
363+ hmr : false ,
364+ // hmr: {
365+ // // Configure WebSocket for Safari compatibility
366+ // protocol: 'ws',
367+ // host: 'bs-local.com',
368+ // port: 5173,
369+ // },
418370 watch : {
419371 // Disable file watching in browser tests
420372 ignored : [ '**/*' ] ,
0 commit comments