-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-runner.js
72 lines (61 loc) · 2.25 KB
/
test-runner.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
import { spawn } from "child_process";
// Function to delay for a specified amount of time
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
// Function to run a single test file
async function runTest(testFile, isHeaded = false) {
return new Promise((resolve) => {
const headedOption = isHeaded ? "--headed" : "";
const command = `npx playwright test ${testFile} ${headedOption}`;
const testProcess = spawn(command, { shell: true });
// Stream stdout (console logs) to the terminal
testProcess.stdout.on("data", (data) => {
console.log(data.toString());
});
// Stream stderr (errors) to the terminal
testProcess.stderr.on("data", (data) => {
console.error(data.toString());
});
// Handle process exit
testProcess.on("exit", (code) => {
if (code === 0) {
console.log(`Successfully ran ${testFile}`);
} else {
console.error(`Error running ${testFile}, exit code: ${code}`);
}
resolve(); // Resolve regardless of success or failure
});
});
}
// Function to run all tests with delays and repetition
async function runTestsWithDelayAndRepeat(isHeaded = false) {
const testFiles = [
"tests/test-13.spec.ts",
// "tests/test-2.spec.ts",
// "tests/test-3.spec.ts",
// "tests/test-4.spec.ts",
// "tests/test-5.spec.ts",
// "tests/test-6.spec.ts",
// "tests/test-7.spec.ts",
// "tests/test-8.spec.ts",
];
const repetitions = 20; // Number of times to run the tests
for (let i = 0; i < repetitions; i++) {
console.log(`Running all tests, repetition ${i + 1} of ${repetitions}`);
for (const testFile of testFiles) {
console.log(`Running ${testFile}`);
await runTest(testFile, isHeaded); // Run each test in headed mode if set to true
const delayTime = Math.floor(Math.random() * (30000 - 7000 + 1)) + 7000; // Random delay between 7 to 30 seconds
console.log(
`Waiting for ${
delayTime / 1000
} seconds before running the next test...`
);
await delay(delayTime); // Wait for the generated delay
}
}
console.log("Finished running all tests");
}
// Execute the test runner in headed mode (set to true for headed mode)
runTestsWithDelayAndRepeat(true);