Repository navigation
Expand file tree
/
Copy pathcypress.config.cjs
More file actions
71 lines (62 loc) · 1.73 KB
/
Copy pathcypress.config.cjs
File metadata and controls
71 lines (62 loc) · 1.73 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
const { defineConfig } = require('cypress');
const fs = require('fs');
const path = require('path');
const DEV_PORT_FILE = path.join(__dirname, '.temp/dev-server-port');
const ensureTrailingSlash = (value) =>
value.endsWith('/') ? value : `${value}/`;
const readActiveDevPort = () => {
try {
if (!fs.existsSync(DEV_PORT_FILE)) {
return undefined;
}
const rawValue = fs.readFileSync(DEV_PORT_FILE, 'utf8').trim();
const parsed = Number(rawValue);
if (Number.isNaN(parsed) || parsed <= 0) {
return undefined;
}
return parsed;
} catch (error) {
// eslint-disable-next-line no-console
console.warn(
'[cypress.config] Unable to read dev server port file:',
error
);
return undefined;
}
};
const buildLocalhostUrl = (port) => ensureTrailingSlash(`http://localhost:${port}`);
const resolveBaseUrl = () => {
const explicitBaseUrl = process.env.CYPRESS_BASE_URL;
if (explicitBaseUrl) {
return ensureTrailingSlash(explicitBaseUrl);
}
const detectedPort = readActiveDevPort();
if (detectedPort) {
return buildLocalhostUrl(detectedPort);
}
const preferredPort =
process.env.VITE_DEV_SERVER_PORT ||
process.env.DEV_SERVER_PORT ||
process.env.PORT ||
'5175';
return buildLocalhostUrl(preferredPort);
};
module.exports = defineConfig({
e2e: {
baseUrl: resolveBaseUrl(),
specPattern: [
'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
'src/**/*.cy.{js,jsx,ts,tsx}',
],
setupNodeEvents(on) {
on('task', {
log(message) {
// Using console methods in Cypress tasks is intentional
// eslint-disable-next-line no-console
console.log(message);
return null;
},
});
},
},
});