Skip to content

Commit db06d72

Browse files
committed
feat: enhance Cypress config for WSL2 with retry logic and browser options
1 parent 21dd32b commit db06d72

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

cypress.config.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig({
1010
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
1111
video: false,
1212
screenshotOnRunFailure: false,
13+
experimentalSingleTabRunMode: true,
1314
},
1415
e2e: {
1516
baseUrl: 'http://localhost:3000',
@@ -21,13 +22,26 @@ export default defineConfig({
2122
chromeWebSecurity: false,
2223
viewportWidth: 1280,
2324
viewportHeight: 800,
24-
defaultCommandTimeout: 10000,
25+
defaultCommandTimeout: 15000,
2526
setupNodeEvents(on, config) {
2627
// Handle WSL2 specific configurations
2728
if (process.env.WSL_DISTRO_NAME) {
2829
config.baseUrl = 'http://localhost:3000';
2930
config.chromeWebSecurity = false;
31+
config.experimentalSingleTabRunMode = true;
32+
config.experimentalInteractiveRunEvents = true;
3033
}
34+
35+
// Add browser launch options
36+
on('before:browser:launch', (browser, launchOptions) => {
37+
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+
}
42+
return launchOptions;
43+
});
44+
3145
return config;
3246
},
3347
},

cypress/e2e/mainPage.cy.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ describe('MainPage Component', () => {
55
// Handle WSL2 specific setup
66
if (Cypress.platform === 'linux') {
77
cy.log('Running in WSL2 environment');
8-
cy.exec('wsl --set-version Ubuntu 2', { failOnNonZeroExit: false });
8+
cy.wslExec('--set-version Ubuntu 2');
9+
10+
// Ensure X server is running
11+
cy.wslExec('export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk \'{print $2}\'):0');
912
}
1013
});
1114

@@ -21,8 +24,14 @@ describe('MainPage Component', () => {
2124
}
2225
}).as('getEntries');
2326

24-
cy.mount(<MainPage />);
25-
cy.wait('@getEntries');
27+
// Add retry logic for mounting
28+
cy.mount(<MainPage />, {
29+
retryOnNetworkFailure: true,
30+
retryOnStatusCodeFailure: true,
31+
retryOnMountFailure: true
32+
});
33+
34+
cy.wait('@getEntries', { timeout: 10000 });
2635
});
2736

2837
it('should display the main page container', () => {

cypress/support/e2e.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ if (Cypress.platform === 'linux') {
77

88
// Add custom commands for WSL2
99
Cypress.Commands.add('wslExec', (command) => {
10-
return cy.exec(`wsl ${command}`);
10+
return cy.exec(`wsl ${command}`, {
11+
failOnNonZeroExit: false,
12+
timeout: 10000
13+
});
14+
});
15+
16+
// Add retry logic for flaky tests
17+
Cypress.Commands.overwrite('should', (originalFn, subject, expectation, ...args) => {
18+
const retries = 3;
19+
let attempts = 0;
20+
21+
const tryAgain = (err) => {
22+
if (attempts < retries) {
23+
attempts++;
24+
cy.wait(500, { log: false });
25+
return originalFn(subject, expectation, ...args);
26+
}
27+
throw err;
28+
};
29+
30+
return originalFn(subject, expectation, ...args).catch(tryAgain);
1131
});
1232
}

0 commit comments

Comments
 (0)