-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcypress-parallel.js
36 lines (29 loc) · 1.15 KB
/
cypress-parallel.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
const fs = require('fs');
const path = require('path');
const NODE_INDEX = Number(process.env.CI_NODE_INDEX || 1 );
const NODE_TOTAL = Number(process.env.CI_NODE_TOTAL || 1);
const TEST_FOLDER = './cypress/integration';
// This log will be printed out to the console
// so that cypress will know which files will be run.
// Also, since getSpecFiles returns an array, the paths are
// joined with comma
//console.log('"' + getSpecFiles().join(',') + '"');
console.log(getSpecFiles().join(','))
function getSpecFiles() {
const allSpecFiles = traverse(TEST_FOLDER);
console.log("The number of sepcs:"+ allSpecFiles.sort()
.filter((_, index) => (index % NODE_TOTAL) === (NODE_INDEX - 1)).length)
return allSpecFiles.sort()
.filter((_, index) => (index % NODE_TOTAL) === (NODE_INDEX - 1));
}
function traverse(dir) {
let files = fs.readdirSync(dir);
files = files.map(file => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) return traverse(filePath);
else if (stats.isFile())return filePath;
});
return files
.reduce((all, folderContents) => all.concat(folderContents), []);
}