forked from huridocs/uwazi
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcypress.config.ts
More file actions
127 lines (118 loc) · 4.12 KB
/
Copy pathcypress.config.ts
File metadata and controls
127 lines (118 loc) · 4.12 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import fs from 'fs';
import { defineConfig } from 'cypress';
import webpackConfig from './webpack.config';
import cypressFailFast from 'cypress-fail-fast/plugin';
const cypressWebpackConfig = {
...webpackConfig,
cache: false, // disable cache for Cypress component testing
optimization: {
...webpackConfig.optimization,
minimize: false, // disable minification for Cypress (keeps debugging easier)
moduleIds: 'named', // CRITICAL FIX: use named module IDs instead of deterministic for cypress-axe
chunkIds: 'named', // CRITICAL FIX: use named chunk IDs instead of deterministic for cypress-axe
// Keep other optimizations like splitChunks for better performance
},
module: {
...webpackConfig.module,
rules: webpackConfig.module.rules.map(rule => {
// Remove thread-loader from Cypress builds (can cause module resolution issues)
if (rule.use && Array.isArray(rule.use)) {
return {
...rule,
use: rule.use.filter(loader => {
if (typeof loader === 'object' && loader.loader === 'thread-loader') {
return false;
}
return true;
}),
};
}
return rule;
}),
},
resolve: {
...webpackConfig.resolve,
// Ensure cypress-axe can resolve its files properly
fallback: {
...webpackConfig.resolve.fallback,
fs: false, // disable fs fallback for cypress-axe
path: false, // disable path fallback for cypress-axe
},
},
};
const { initPlugin } = require('cypress-plugin-snapshots/plugin');
const retries = process.env.CYPRESS_RETRIES ? parseInt(process.env.CYPRESS_RETRIES, 10) : 0;
export default defineConfig({
viewportWidth: 1280,
viewportHeight: 768,
defaultCommandTimeout: 12000,
requestTimeout: 30000,
env: {
FAIL_FAST_ENABLED: process.env.CYPRESS_FAIL_FAST_ENABLED || 'false',
FAIL_FAST_STRATEGY: process.env.CYPRESS_FAIL_FAST_STRATEGY || 'run',
},
e2e: {
baseUrl: 'http://localhost:3000',
video: true,
retries,
screenshotOnRunFailure: false,
testIsolation: false,
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
setupNodeEvents(on, config) {
initPlugin(on, config);
cypressFailFast(on, config);
// Add logging tasks for accessibility violations
on('task', {
log(message) {
console.log(message);
return null;
},
table(message) {
console.table(message);
return null;
},
});
on('after:spec', (spec: Cypress.Spec, results: CypressCommandLine.RunResult) => {
if (results && 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) {
// delete the video if the spec passed and no tests retried
fs.unlinkSync(results.video);
}
}
});
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome' || browser.name === 'chromium' || browser.name === 'edge') {
// Ensure consistent viewport and stable CI runs for Chromium-family browsers in both headed and headless modes
launchOptions.args.push('--window-size=1280,768');
launchOptions.args.push('--force-device-scale-factor=1');
launchOptions.args.push('--disable-dev-shm-usage');
launchOptions.args.push('--no-sandbox');
}
if (browser.name === 'electron' && browser.isHeadless) {
launchOptions.preferences.width = 1280;
launchOptions.preferences.height = 768;
}
if (browser.name === 'firefox' && browser.isHeadless) {
launchOptions.args.push('--width=1280');
launchOptions.args.push('--height=768');
}
return launchOptions;
});
},
},
component: {
devServer: {
framework: 'react',
bundler: 'webpack',
webpackConfig: cypressWebpackConfig,
},
specPattern: 'app/react/**/*.cy.tsx',
setupNodeEvents(on, config) {
initPlugin(on, config);
},
},
});