Skip to content

Commit 7121a44

Browse files
committed
fix: improve WSL2 X server configuration and browser launch options in Cypress
1 parent db06d72 commit 7121a44

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

cypress.config.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,23 @@ export default defineConfig({
3030
config.chromeWebSecurity = false;
3131
config.experimentalSingleTabRunMode = true;
3232
config.experimentalInteractiveRunEvents = true;
33+
34+
// Add X server configuration
35+
process.env.DISPLAY = `$(grep nameserver /etc/resolv.conf | awk '{print $2}'):0`;
3336
}
3437

3538
// Add browser launch options
3639
on('before:browser:launch', (browser, launchOptions) => {
3740
if (browser.family === 'chromium' && browser.name !== 'electron') {
38-
launchOptions.args.push('--disable-gpu');
39-
launchOptions.args.push('--no-sandbox');
40-
launchOptions.args.push('--disable-dev-shm-usage');
41+
launchOptions.args.push(
42+
'--disable-gpu',
43+
'--no-sandbox',
44+
'--disable-dev-shm-usage',
45+
'--disable-software-rasterizer',
46+
'--disable-background-timer-throttling',
47+
'--disable-backgrounding-occluded-windows',
48+
'--disable-renderer-backgrounding'
49+
);
4150
}
4251
return launchOptions;
4352
});

cypress/e2e/mainPage.cy.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ describe('MainPage Component', () => {
55
// Handle WSL2 specific setup
66
if (Cypress.platform === 'linux') {
77
cy.log('Running in WSL2 environment');
8-
cy.wslExec('--set-version Ubuntu 2');
98

10-
// Ensure X server is running
11-
cy.wslExec('export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk \'{print $2}\'):0');
9+
// Set up X server display
10+
cy.exec('wsl export DISPLAY=$(grep nameserver /etc/resolv.conf | awk \'{print $2}\'):0', {
11+
failOnNonZeroExit: false
12+
});
13+
14+
// Verify X server connection
15+
cy.exec('wsl xdpyinfo', {
16+
failOnNonZeroExit: false
17+
}).then((result) => {
18+
if (result.code !== 0) {
19+
throw new Error('X server connection failed. Please ensure an X server is running on your Windows host.');
20+
}
21+
});
1222
}
1323
});
1424

cypress/support/e2e.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ if (Cypress.platform === 'linux') {
1313
});
1414
});
1515

16+
// Add X server configuration
17+
before(() => {
18+
const display = cy.exec('wsl grep nameserver /etc/resolv.conf | awk \'{print $2}\'').then((result) => {
19+
process.env.DISPLAY = `${result.stdout.trim()}:0`;
20+
});
21+
});
22+
1623
// Add retry logic for flaky tests
1724
Cypress.Commands.overwrite('should', (originalFn, subject, expectation, ...args) => {
1825
const retries = 3;

0 commit comments

Comments
 (0)