forked from influxdata/docs-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcypress.config.js
More file actions
304 lines (276 loc) · 10.3 KB
/
cypress.config.js
File metadata and controls
304 lines (276 loc) · 10.3 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import { defineConfig } from 'cypress';
import { cwd as _cwd } from 'process';
import * as fs from 'fs';
import * as yaml from 'js-yaml';
import {
BROKEN_LINKS_FILE,
FIRST_BROKEN_LINK_FILE,
initializeReport,
readBrokenLinksReport,
saveCacheStats,
saveValidationStrategy,
} from './cypress/support/link-reporter.js';
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:1315',
defaultCommandTimeout: 10000,
pageLoadTimeout: 30000,
responseTimeout: 30000,
experimentalMemoryManagement: true,
numTestsKeptInMemory: 5,
projectId: 'influxdata-docs',
setupNodeEvents(on, config) {
// Browser setup
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args.push('--disable-dev-shm-usage');
launchOptions.args.push('--disable-gpu');
launchOptions.args.push('--disable-extensions');
return launchOptions;
}
});
on('task', {
// Fetch the product list configured in /data/products.yml
getData(filename) {
return new Promise((resolve, reject) => {
const cwd = _cwd();
try {
resolve(
yaml.load(
fs.readFileSync(`${cwd}/data/${filename}.yml`, 'utf8')
)
);
} catch (e) {
reject(e);
}
});
},
// Log task for reporting
log(message) {
if (typeof message === 'object') {
if (message.type === 'error') {
console.error(`\x1b[31m${message.message}\x1b[0m`); // Red
} else if (message.type === 'warning') {
console.warn(`\x1b[33m${message.message}\x1b[0m`); // Yellow
} else if (message.type === 'success') {
console.log(`\x1b[32m${message.message}\x1b[0m`); // Green
} else if (message.type === 'divider') {
console.log(`\x1b[90m${message.message}\x1b[0m`); // Gray
} else {
console.log(message.message || message);
}
} else {
console.log(message);
}
return null;
},
// File tasks
writeFile({ path, content }) {
try {
fs.writeFileSync(path, content);
return true;
} catch (error) {
console.error(`Error writing to file ${path}: ${error.message}`);
return { error: error.message };
}
},
readFile(path) {
try {
return fs.existsSync(path) ? fs.readFileSync(path, 'utf8') : null;
} catch (error) {
console.error(`Error reading file ${path}: ${error.message}`);
return { error: error.message };
}
},
// Broken links reporting tasks
initializeBrokenLinksReport() {
return initializeReport();
},
// Special case domains are now handled directly in the test without additional reporting
// This task is kept for backward compatibility but doesn't do anything special
reportSpecialCaseLink(linkData) {
console.log(
`✅ Expected status code: ${linkData.url} (status: ${linkData.status}) is valid for this domain`
);
return true;
},
reportBrokenLink(linkData) {
try {
// Validate link data
if (!linkData || !linkData.url || !linkData.page) {
console.error('Invalid link data provided');
return false;
}
// Read current report
const report = readBrokenLinksReport();
// Find or create entry for this page
let pageReport = report.find((r) => r.page === linkData.page);
if (!pageReport) {
pageReport = { page: linkData.page, links: [] };
report.push(pageReport);
}
// Check if link is already in the report to avoid duplicates
const isDuplicate = pageReport.links.some(
(link) => link.url === linkData.url && link.type === linkData.type
);
if (!isDuplicate) {
// Add the broken link to the page's report
pageReport.links.push({
url: linkData.url,
status: linkData.status,
type: linkData.type,
linkText: linkData.linkText,
});
// Write updated report back to file
fs.writeFileSync(
BROKEN_LINKS_FILE,
JSON.stringify(report, null, 2)
);
// Store first broken link if not already recorded
const firstBrokenLinkExists =
fs.existsSync(FIRST_BROKEN_LINK_FILE) &&
fs.readFileSync(FIRST_BROKEN_LINK_FILE, 'utf8').trim() !== '';
if (!firstBrokenLinkExists) {
// Store first broken link with complete information
const firstBrokenLink = {
url: linkData.url,
status: linkData.status,
type: linkData.type,
linkText: linkData.linkText,
page: linkData.page,
time: new Date().toISOString(),
};
fs.writeFileSync(
FIRST_BROKEN_LINK_FILE,
JSON.stringify(firstBrokenLink, null, 2)
);
console.error(
`🔴 FIRST BROKEN LINK: ${linkData.url} (${linkData.status}) - ${linkData.type} on page ${linkData.page}`
);
}
// Log the broken link immediately to console
console.error(
`❌ BROKEN LINK: ${linkData.url} (${linkData.status}) - ${linkData.type} on page ${linkData.page}`
);
}
return true;
} catch (error) {
console.error(`Error reporting broken link: ${error.message}`);
// Even if there's an error, we want to ensure the test knows there was a broken link
return true;
}
},
// Cache and incremental validation tasks
saveCacheStatistics(stats) {
try {
saveCacheStats(stats);
return true;
} catch (error) {
console.error(`Error saving cache stats: ${error.message}`);
return false;
}
},
saveValidationStrategy(strategy) {
try {
saveValidationStrategy(strategy);
return true;
} catch (error) {
console.error(`Error saving validation strategy: ${error.message}`);
return false;
}
},
runIncrementalValidation(filePaths) {
return new Promise(async (resolve, reject) => {
try {
console.log('Loading incremental validator module...');
// Use CommonJS require for better compatibility
const {
IncrementalValidator,
} = require('./.github/scripts/incremental-validator.cjs');
console.log('✅ Incremental validator loaded successfully');
const validator = new IncrementalValidator();
const results = await validator.validateFiles(filePaths);
resolve(results);
} catch (error) {
console.error(`Incremental validation error: ${error.message}`);
console.error(`Stack: ${error.stack}`);
// Don't fail the entire test run due to cache issues
// Fall back to validating all files
console.warn('Falling back to validate all files without cache');
resolve({
validationStrategy: {
unchanged: [],
changed: filePaths.map((filePath) => ({
filePath,
fileHash: 'unknown',
links: [],
})),
newLinks: [],
total: filePaths.length,
},
filesToValidate: filePaths.map((filePath) => ({
filePath,
fileHash: 'unknown',
})),
cacheStats: {
totalFiles: filePaths.length,
cacheHits: 0,
cacheMisses: filePaths.length,
hitRate: 0,
},
});
}
});
},
cacheValidationResults(filePath, fileHash, results) {
return new Promise(async (resolve, reject) => {
try {
const {
IncrementalValidator,
} = require('./.github/scripts/incremental-validator.cjs');
const validator = new IncrementalValidator();
const success = await validator.cacheResults(
filePath,
fileHash,
results
);
resolve(success);
} catch (error) {
console.error(`Cache validation results error: ${error.message}`);
// Don't fail if caching fails - just continue without cache
resolve(false);
}
});
},
filePathToUrl(filePath) {
return new Promise(async (resolve, reject) => {
try {
const { filePathToUrl } = await import(
'./.github/scripts/utils/url-transformer.js'
);
resolve(filePathToUrl(filePath));
} catch (error) {
console.error(`URL transformation error: ${error.message}`);
// Fallback: return the file path as-is if transformation fails
console.warn(
`Using fallback URL transformation for: ${filePath}`
);
resolve(filePath);
}
});
},
});
// Load plugins file using dynamic import for ESM compatibility
return import('./cypress/plugins/index.js').then((module) => {
return module.default(on, config);
});
},
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'cypress/support/e2e.js',
viewportWidth: 1280,
viewportHeight: 720,
},
env: {
test_subjects: '',
},
});