-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcypress.config.js
More file actions
244 lines (213 loc) · 7.79 KB
/
Copy pathcypress.config.js
File metadata and controls
244 lines (213 loc) · 7.79 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
const { defineConfig } = require('cypress');
const path = require('path');
const globby = require('globby');
const converter = require('json-2-csv');
const { downloadFile } = require('cypress-downloadfile/lib/addPlugin');
const { rm, unlink } = require('fs');
const fs = require('fs');
const allureWriter = require('@shelex/cypress-allure-plugin/writer');
const { cloudPlugin } = require('cypress-cloud/plugin');
const registerReportPortalPlugin = require('@reportportal/agent-js-cypress/lib/plugin');
const webpackPreprocessor = require('@cypress/webpack-batteries-included-preprocessor');
const testRailPlugin = require('cypress-testrail-simple/src/plugin');
const httpTasks = require('./cypress/tasks/httpTasks');
const flakyMarkerHandler = require('./scripts/report-portal/afterSpecHandler');
let activeEnvironment = null; // DO NOT SET ENV HERE, do it in ./environments.js file
let environments = {};
try {
// eslint-disable-next-line global-require
({ activeEnvironment, environments } = require('./environments'));
} catch (e) {
// cypress/environments.js is gitignored and proceed with defaults
}
const delay = async (ms) => new Promise((res) => setTimeout(res, ms));
const envOverrides = (activeEnvironment && environments[activeEnvironment]) || {};
if (activeEnvironment && !environments[activeEnvironment]) {
const available = Object.keys(environments).join(', ');
throw new Error(
`Environment "${activeEnvironment}" not found in cypress/environments.js\nAvailable: ${available}`,
);
}
let cypressLocal = {};
try {
// eslint-disable-next-line global-require, import/extensions
cypressLocal = require('./cypress.local.js');
} catch (e) {
// cypress.local.js is gitignored and optional
}
/**
* Chains after:spec handlers to ensure both TestRail and flaky marker handlers execute.
* Since Cypress's on() overwrites previous handlers (except for 'task'), we need to intercept
* the TestRail plugin's handler registration and combine it with the flaky marker handler.
*/
async function setupAfterSpecChaining(on, config) {
if (config.env.itemsFilePath) {
on('before:browser:launch', (browser, launchOptions) => {
if (browser.family === 'chromium') {
launchOptions.args.push('--no-sandbox');
launchOptions.args.push('--disable-gpu');
}
return launchOptions;
});
let testRailAfterSpecHandler;
// Intercept after:spec registration from TestRail plugin
const interceptedOn = (event, handler) => {
if (event === 'after:spec') {
testRailAfterSpecHandler = handler;
} else {
on(event, handler);
}
};
// Let TestRail plugin register its handler (captured by interceptor)
await testRailPlugin(interceptedOn, config);
// Register combined handler that calls both
on('after:spec', async (spec, results) => {
// Call TestRail handler first
if (testRailAfterSpecHandler) {
await testRailAfterSpecHandler(spec, results);
}
// Then call flaky marker handler
await flakyMarkerHandler(spec, results, config.env.itemsFilePath);
});
} else {
// Normal flow: just register TestRail plugin
await testRailPlugin(on, config);
}
}
const reportportalOptions = {
apiKey: process.env.CI_API_KEY ? process.env.CI_API_KEY : '',
restClientConfig: {
timeout: 360000,
},
};
module.exports = defineConfig({
retries: {
runMode: 0,
openMode: 0,
},
numTestsKeptInMemory: 1,
watchForFileChanges: true,
viewportWidth: 1920,
viewportHeight: 1080,
video: false,
defaultCommandTimeout: 51000,
pageLoadTimeout: 60000,
requestTimeout: 60000,
responseTimeout: 60000,
downloadsFolder: 'cypress/downloads',
env: {
OKAPI_HOST: 'https://folio-etesting-cypress-kong.ci.folio.org',
OKAPI_TENANT: 'diku',
diku_login: 'diku_admin',
diku_password: 'admin',
z3950_login: 'z3950Admin',
z3950_password: 'password',
// it is necessary to set the ECS environment name when running ECS tests to get correct tenants names on the target env: 'sprint' or 'snapshot'
ecs_env_name: 'snapshot',
is_kiwi_release: false,
downloadTimeout: 2000,
allure: true,
allureReuseAfterSpec: true,
grepFilterSpecs: true,
grepOmitFiltered: true,
rtrAuth: true,
ecsEnabled: false,
eureka: true,
runAsAdmin: false,
systemRoleName: 'adminRole',
newSettings: false,
...(envOverrides.env || {}),
},
reporterOptions: reportportalOptions,
e2e: {
async setupNodeEvents(on, config) {
on('file:preprocessor', webpackPreprocessor());
allureWriter(on, config);
on('task', {
log(message) {
// eslint-disable-next-line no-console
console.log(message);
return null;
},
async findFiles(mask) {
if (!mask) {
throw new Error('Missing a file mask to search');
}
const list = await globby(mask);
if (!list.length) {
return null;
}
return list;
},
convertCsvToJson(data) {
const options = { excelBOM: true, trimHeaderFields: true, trimFieldValues: true };
return converter.csv2json(data, options);
},
downloadFile,
deleteFolder(folderName) {
return new Promise((resolve, reject) => {
rm(
folderName,
{ maxRetries: 10, recursive: true, force: true },
// eslint-disable-next-line consistent-return
(err) => {
if (err && err.code !== 'ENOENT') {
return reject(err);
}
resolve(null);
},
);
});
},
deleteFile(pathToFile) {
return new Promise((resolve, reject) => {
// eslint-disable-next-line consistent-return
unlink(pathToFile, (err) => {
if (err && err.code !== 'ENOENT') {
return reject(err);
}
resolve(null);
});
});
},
readFileFromDownloads(filename) {
const downloadsFolder =
config.downloadsFolder || path.join(__dirname, '..', '..', 'Downloads');
const filePath = path.join(downloadsFolder, filename);
return fs.readFileSync(filePath, 'utf-8');
},
// HTTP tasks (axios requests in Node.js context)
...httpTasks,
...cypressLocal.tasks?.(on, config),
});
// keep Cypress running until the ReportPortal reporter is finished. this is a
// very critical step, as otherwise results might not be completely pushed into
// ReportPortal, resulting in unfinished launches and failing merges
on('after:run', async (result) => {
if (result) {
if (globby.sync('rplaunchinprogress*.tmp').length > 0) {
// eslint-disable-next-line no-console
console.log('Report portal. Await for a 20s...');
await delay(20000);
}
}
});
// fix for cypress-testrail-simple plugin
if ('TESTRAIL_PROJECTID' in process.env && process.env.TESTRAIL_PROJECTID === '') {
delete process.env.TESTRAIL_PROJECTID;
}
registerReportPortalPlugin(on, config);
// eslint-disable-next-line global-require
const grepConfig = require('@cypress/grep/src/plugin')(config);
const result = await cloudPlugin(on, grepConfig);
// Since Cypress's on() overwrites previous handlers (except for 'task' event),
// we need to ensure that all handlers that need to run on after:spec
// are registered in setupAfterSpecChaining to ensure they all execute.
await setupAfterSpecChaining(on, config);
return result;
},
baseUrl: envOverrides.baseUrl || 'https://folio-etesting-cypress-diku.ci.folio.org',
testIsolation: false,
},
...cypressLocal.cypress,
});