Skip to content

Commit a253f7b

Browse files
committed
workflow
1 parent d9b5495 commit a253f7b

File tree

5 files changed

+83
-29
lines changed

5 files changed

+83
-29
lines changed

.github/workflows/javascript.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ jobs:
4040
CI_USER_TOKEN: ${{ secrets.CI_USER_TOKEN }}
4141
TRAVIS_COM_TOKEN: ${{ secrets.TRAVIS_COM_TOKEN }}
4242

43+
browser_tests:
44+
runs-on: ubuntu-latest
45+
strategy:
46+
matrix:
47+
browser: ['chrome', 'firefox', 'edge', 'safari']
48+
env:
49+
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
50+
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
51+
BROWSERSTACK_LOCAL: 'true'
52+
USE_LOCAL_BROWSER: 'false'
53+
VITEST_BROWSER: ${{ matrix.browser }}
54+
steps:
55+
- uses: actions/checkout@v3
56+
- name: Set up Node
57+
uses: actions/setup-node@v3
58+
with:
59+
node-version: 20
60+
cache: 'npm'
61+
cache-dependency-path: ./package-lock.json
62+
- name: Browser tests - ${{ matrix.browser }}
63+
working-directory: .
64+
run: |
65+
npm install
66+
npm run test-vitest-browser
67+
4368
# crossbrowser_and_umd_unit_tests:
4469
# runs-on: ubuntu-latest
4570
# env:

public/broadcast-channel-polyfill-bundle.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Apply BroadcastChannel polyfill for Safari 14 and other browsers that don't support it
2+
// The bundled library exposes BroadcastChannel2
3+
(function() {
4+
if (typeof window !== 'undefined' && typeof window.BroadcastChannel === 'undefined') {
5+
if (typeof window.BroadcastChannel2 !== 'undefined') {
6+
window.BroadcastChannel = window.BroadcastChannel2;
7+
console.log('[Polyfill] BroadcastChannel polyfill applied successfully');
8+
} else {
9+
console.error('[Polyfill] BroadcastChannel2 not found - polyfill bundle may not have loaded');
10+
}
11+
} else if (typeof window !== 'undefined') {
12+
console.log('[Polyfill] Native BroadcastChannel detected, polyfill not needed');
13+
}
14+
})();

scripts/run-browser-tests.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ require('dotenv').config();
2222
const { execSync } = require('child_process');
2323
const browserstack = require('browserstack-local');
2424

25-
26-
// Note: Browser instances are now configured in vitest.browser.config.mts
27-
// The Vitest config will run all browsers (Chrome, Firefox, Edge, Safari, Opera) automatically
28-
2925
// Determine if we should use local browser or BrowserStack
3026
// Priority: USE_LOCAL_BROWSER env var, then check for BrowserStack credentials
3127
let useLocalBrowser = process.env.USE_LOCAL_BROWSER === 'true';
@@ -98,6 +94,9 @@ let hasFailures = false;
9894

9995
async function runTests() {
10096
try {
97+
// Get browser name from environment variable (default to chrome)
98+
const browserName = process.env.VITEST_BROWSER || 'chrome';
99+
101100
// Only start tunnel if using BrowserStack
102101
if (!useLocalBrowser) {
103102
await startTunnel();
@@ -106,26 +105,26 @@ async function runTests() {
106105
}
107106

108107
console.log(`\n${'='.repeat(80)}`);
109-
const browserList = process.env.VITEST_BROWSER || 'Chrome 102, Firefox 91, Edge 84, Safari 13.1, Opera 76';
110-
console.log(`Running tests on ${useLocalBrowser ? 'local browsers' : 'BrowserStack'} (${browserList})...`);
108+
console.log(`Running tests on ${useLocalBrowser ? 'local' : 'BrowserStack'}: ${browserName}`);
111109
console.log('='.repeat(80));
112110

113111
// Set environment variables
114112
const env = {
115113
...process.env,
116114
USE_LOCAL_BROWSER: useLocalBrowser ? 'true' : 'false',
115+
VITEST_BROWSER: browserName,
117116
};
118117

119118
try {
120-
// Run vitest with the browser config - it will run all browser instances
119+
// Run vitest with the browser config
121120
execSync('npm run test-vitest -- --config vitest.browser.config.mts', {
122121
stdio: 'inherit',
123122
env,
124123
});
125124

126-
console.log('\n✓ All browser tests passed!');
125+
console.log(`\n✓ ${browserName} tests passed!`);
127126
} catch (error) {
128-
console.error('\n✗ Some browser tests failed');
127+
console.error(`\n✗ ${browserName} tests failed`);
129128
hasFailures = true;
130129
}
131130

@@ -134,9 +133,9 @@ async function runTests() {
134133
console.log('='.repeat(80));
135134

136135
if (hasFailures) {
137-
console.error('Some browser tests failed. See above for details.');
136+
console.error(`${browserName} tests failed. See above for details.`);
138137
} else {
139-
console.log('All browser tests passed!');
138+
console.log(`${browserName} tests passed!`);
140139
}
141140
} finally {
142141
// Only stop tunnel if using BrowserStack

vitest.browser.config.mts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,24 @@ const useLocalBrowser = process.env.USE_LOCAL_BROWSER === 'true';
171171
// }
172172

173173
// Define browser configurations
174+
// BroadcastChannel API support: Safari 15.4+, Edge 84+, Firefox 91+, Chrome 102+, Opera 76+
174175
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-
// we need safari 15.4 + cause vitest/browser relies on BroadcastChannel API
179-
{ name: 'safari', browserName: 'safari', os: 'OS X', osVersion: 'Monterey' }, // Safari 15+ has BroadcastChannel support
176+
{ name: 'chrome', browserName: 'chrome', os: 'Windows', osVersion: '11' },
177+
{ name: 'firefox', browserName: 'firefox', os: 'Windows', osVersion: '11' },
178+
{ name: 'edge', browserName: 'edge', os: 'Windows', osVersion: '11' },
179+
{ name: 'safari', browserName: 'safari', os: 'OS X', osVersion: 'Monterey' },
180+
{ name: 'opera', browserName: 'opera', os: 'Windows', osVersion: '11' },
180181
];
181182

182-
// Filter browsers based on VITEST_BROWSER environment variable
183-
const browserFilter = process.env.VITEST_BROWSER;
184-
const browserConfigs = browserFilter
185-
? allBrowserConfigs.filter(config => config.name === browserFilter.toLowerCase())
186-
: allBrowserConfigs;
183+
// Get browser from VITEST_BROWSER env var (default to chrome)
184+
const browserName = process.env.VITEST_BROWSER || 'chrome';
185+
const browserConfig = allBrowserConfigs.find(c => c.name === browserName.toLowerCase());
186+
187+
if (!browserConfig) {
188+
throw new Error(`Browser "${browserName}" not found. Available: ${allBrowserConfigs.map(c => c.name).join(', ')}`);
189+
}
190+
191+
const browserConfigs = [browserConfig];
187192

188193
// Build local browser capabilities
189194
function buildLocalCapabilities(browserName: string) {
@@ -203,13 +208,13 @@ function buildLocalCapabilities(browserName: string) {
203208
function buildBrowserStackCapabilities(config: typeof allBrowserConfigs[0]) {
204209
return {
205210
browserName: config.browserName,
206-
'goog:chromeOptions': {
207-
args: [
208-
'--disable-blink-features=AutomationControlled',
209-
'--disable-dev-shm-usage',
210-
'--no-sandbox',
211-
],
212-
},
211+
// 'goog:chromeOptions': {
212+
// args: [
213+
// '--disable-blink-features=AutomationControlled',
214+
// '--disable-dev-shm-usage',
215+
// '--no-sandbox',
216+
// ],
217+
// },
213218
'bstack:options': {
214219
os: config.os,
215220
osVersion: config.osVersion,
@@ -260,6 +265,16 @@ export default defineConfig({
260265
name: 'console-capture-plugin',
261266
enforce: 'pre', // Run before other plugins
262267
configureServer(server) {
268+
// Check if console capture is enabled (default to false)
269+
const consoleCaptureEnabled = process.env.VITEST_CONSOLE_CAPTURE === 'true';
270+
271+
if (!consoleCaptureEnabled) {
272+
console.log('[Console Capture] Disabled (set VITEST_CONSOLE_CAPTURE=true to enable)');
273+
return;
274+
}
275+
276+
console.log('[Console Capture] Enabled');
277+
263278
// Add middleware to handle console log posts from browser
264279
server.middlewares.use((req, res, next) => {
265280
if (req.url === '/__vitest_console__' && req.method === 'POST') {
@@ -442,7 +457,7 @@ export default defineConfig({
442457
browser: {
443458
enabled: true,
444459
provider: 'webdriverio',
445-
headless: useLocalBrowser ? (process.env.CI === 'true' || process.env.HEADLESS === 'true') : false,
460+
headless: false,
446461
// Vitest 3 browser mode configuration
447462
instances: buildBrowserInstances(),
448463
// Increase browser connection timeout for Safari on BrowserStack (default is 60s)

0 commit comments

Comments
 (0)