-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypress.config.ci.js
51 lines (46 loc) · 1.57 KB
/
cypress.config.ci.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
import { defineConfig } from 'cypress';
import path from 'path';
import fs from 'fs';
const getLastDownloadFilePath = (dirPath) => {
const filesOrdered = fs
.readdirSync(dirPath)
.map((entry) => path.join(dirPath, entry))
.filter((entryWithPath) => fs.lstatSync(entryWithPath).isFile())
.map((fileName) => ({ fileName, mtime: fs.lstatSync(fileName).mtime }))
.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
return filesOrdered.length ? filesOrdered[0].fileName : false;
};
const hasFile = (dirPath, ms) => {
const delay = 10;
return new Promise((resolve, reject) => {
if (ms < 0) {
return reject(new Error(`Could not find file in ${dirPath}`));
}
const found = getLastDownloadFilePath(dirPath);
if (found) {
return resolve(found);
}
setTimeout(() => {
hasFile(dirPath, ms - delay).then(resolve, reject);
}, delay);
});
};
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
fixturesFolder: 'cypress/fixtures',
specPattern: 'cypress/integration/*.spec.js',
screenshotOnRunFailure: false,
video: false,
supportFile: 'cypress/support/index.js',
setupNodeEvents(on, config) {
on('task', {
isExistFile(dirPath, ms = 4000) {
console.log(`looking for file in ${dirPath}`, dirPath, ms);
return hasFile(dirPath, ms);
},
});
return config;
},
},
});