-
Notifications
You must be signed in to change notification settings - Fork 7
/
runner_queue.js
69 lines (58 loc) · 1.69 KB
/
runner_queue.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
#!/usr/bin/env node
const cypress = require("cypress");
const glob = require("glob");
const Queue = require("@shelex/promise-queue-timeout");
/* Parse args */
let { executors = 1, filter } = process.argv.slice(2).reduce((acc, pair) => {
let [key, value] = pair.split("=");
acc[key] = value;
return acc;
}, {});
process.exitCode = 0;
/* get list of all .spec files*/
let specs = glob
.sync("cypress/e2e/**/*.cy.js")
.filter((specPath) => (filter ? specPath.includes(filter) : specPath));
const initialSpecsCount = specs.length;
console.log(`Running cypress with ${executors} executors\n`);
console.log(`Found ${initialSpecsCount} spec files\n`);
const runner = new Queue({
executors: executors,
timeout: 10000,
});
specs.forEach((spec, index) => {
const globalHooks = {};
// global before hook:
index === 0 && (globalHooks.setupSuite = true);
// global after hook:
index === specs.length - 1 && (globalHooks.teardownSuite = true);
runner.enqueue(() => {
return cypress.run({
browser: "chrome",
spec: spec,
config: {
video: false,
},
env: {
...globalHooks,
},
});
}, spec);
});
runner.on("resolve", (results) => {
process.exitCode += results.totalFailed || 0;
});
runner.on("reject", (err) => {
process.stdout.write(err);
process.exitCode += 1;
});
runner.on("starting_task", (spec, specsCount) => {
console.log(
`starting ${spec}, ${
initialSpecsCount - specsCount + 1
}/${initialSpecsCount}`
);
});
process.on("exit", (code) => {
return console.log(`Runner process exit with code ${code}`);
});