forked from Altinn/app-frontend-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypress.config.js
83 lines (75 loc) · 2.89 KB
/
cypress.config.js
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
/* eslint-disable @typescript-eslint/no-require-imports */
const { defineConfig } = require('cypress');
const path = require('node:path');
const fs = require('node:fs/promises');
const env = require('dotenv').config();
const CYPRESS_WINDOW_WIDTH = env.parsed?.CYPRESS_WINDOW_WIDTH || 1920;
const CYPRESS_WINDOW_HEIGHT = env.parsed?.CYPRESS_WINDOW_HEIGHT || 1080;
// noinspection JSUnusedGlobalSymbols
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'electron') {
launchOptions.preferences.width = CYPRESS_WINDOW_WIDTH;
launchOptions.preferences.height = CYPRESS_WINDOW_HEIGHT;
launchOptions.preferences.webPreferences = {
...(launchOptions.preferences.webPreferences || {}),
webSecurity: false,
};
}
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args.push(`--window-size=${CYPRESS_WINDOW_WIDTH},${CYPRESS_WINDOW_HEIGHT}`);
}
// Adding chromeWebSecurity: false
if (browser.name === 'chrome') {
launchOptions.args.push('--disable-web-security');
}
return launchOptions;
});
on('after:spec', async (_spec, results) => {
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
await fs.unlink(results.video);
}
}
});
const validEnvironments = ['docker', 'podman', 'tt02'];
if (validEnvironments.includes(config.env.environment)) {
return getConfigurationByFile(config.env.environment);
}
throw new Error(`Unknown environment "${config.env.environment}"
Valid environments are:
- ${validEnvironments.join('\n- ')}`);
},
specPattern: ['test/e2e/integration/', 'test/e2e/manual/'],
supportFile: 'test/e2e/support/index.ts',
},
fixturesFolder: 'test/e2e/fixtures',
downloadsFolder: 'test/downloads',
screenshotOnRunFailure: true,
screenshotsFolder: 'test/screenshots',
trashAssetsBeforeRuns: true,
video: env.parsed?.CYPRESS_RECORD_VIDEO === 'true',
videosFolder: 'test/videos',
videoCompression: JSON.parse(env.parsed?.CYPRESS_VIDEO_COMPRESSION || '32'),
viewportHeight: 768,
viewportWidth: 1536,
requestTimeout: 20000,
defaultCommandTimeout: 20000,
reporter: 'junit',
reporterOptions: {
mochaFile: 'test/reports/result-[hash].xml',
},
retries: {
runMode: 1,
openMode: 0,
},
});
async function getConfigurationByFile(file) {
const pathToJsonDataFile = path.resolve('test/e2e/config', `${file}.json`);
return JSON.parse((await fs.readFile(pathToJsonDataFile)).toString());
}