Repository navigation
Expand file tree
/
Copy pathcypress.config.js
More file actions
99 lines (92 loc) · 3.82 KB
/
Copy pathcypress.config.js
File metadata and controls
99 lines (92 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* eslint-disable no-undef */
const { defineConfig } = require('cypress');
const fs = require('fs');
const path = require('path');
module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
viewportHeight: 800,
viewportWidth: 1800,
numTestsKeptInMemory: 5,
videoCompression: false,
allowCypressEnv: false,
// Enable before:run event in open mode (cypress open) for local development.
// Required for on('before:run'...) hook (see #10026) to capture DB state.
// Note: after:run is only used in CI (run mode). Can be removed if Cypress defaults
// to enabling these events or if we no longer need the before:run hook.
experimentalInteractiveRunEvents: true,
// See: https://docs.cypress.io/app/references/experiments#Experimental-Flake-Detection-Features
retries: {
experimentalStrategy: 'detect-flake-and-pass-on-threshold',
experimentalOptions: {
maxRetries: 3,
passesRequired: 1,
},
openMode: false,
runMode: true,
},
setupNodeEvents(on, config) {
// Check for Cypress build marker
const markerPath = path.resolve(__dirname, 'tmp/.cypress-build-marker');
if (!fs.existsSync(markerPath)) {
const errorMsg = [
'',
'================================================================================',
'❌ ERROR: Webpack was not built with CYPRESS=true',
'================================================================================',
'',
'Debug notifications will appear in the UI and may block elements.',
'',
'To fix this, rebuild webpack with:',
' CYPRESS=true bin/webpack',
'',
'================================================================================',
'',
].join('\n');
console.error(errorMsg);
throw new Error('Webpack was not built with CYPRESS=true. See console for details');
}
// In open mode (cypress open), the process stays alive between spec runs so
// manually-created UI data would be wiped when a test calls cy.appDbState('restore').
// Capture before each spec so the snapshot always reflects the current DB state.
// In run mode (both CI and local cypress:run), the process exits after the run so
// a single upfront capture via before:run is sufficient.
const captureDbState = async () => {
try {
await fetch('http://localhost:3000/__e2e__/command', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'db_state', options: 'capture' }),
});
} catch (err) {
console.error('[DB] Failed to capture DB state:', err.message);
}
};
if (config.isInteractive) {
// open mode (cypress open) — capture per-spec to pick up any manual UI changes
on('before:spec', () => captureDbState());
} else {
on('before:run', () => captureDbState());
}
on('after:spec', (spec, results) => {
// Delete the video on CI if the spec passed and no tests retried
if (process.env.CI && results && results.video && fs.existsSync(results.video)) {
// Do we have failures for any retry attempts?
const failures = results.tests.some((test) =>
test.attempts.some((attempt) => attempt.state === 'failed')
);
if (!failures) {
fs.unlinkSync(results.video);
}
}
});
on('before:browser:launch', (browser = {}, launchOptions) => {
console.log('Launching browser:', browser.name);
if (browser.name === 'chrome') {
launchOptions.args.push('--disable-features=AutofillServerCommunication');
}
return launchOptions;
});
},
},
});