-
-
Notifications
You must be signed in to change notification settings - Fork 360
Expand file tree
/
Copy pathmaestro.ts
More file actions
41 lines (38 loc) · 1.12 KB
/
maestro.ts
File metadata and controls
41 lines (38 loc) · 1.12 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
import { spawn } from 'node:child_process';
import path from 'node:path';
const MAX_ATTEMPTS = 3;
const runMaestro = (test: string): Promise<void> => {
return new Promise((resolve, reject) => {
const process = spawn('maestro', ['test', test, '--format', 'junit'], {
cwd: path.join(__dirname, '..'),
stdio: 'inherit',
});
process.on('close', code => {
if (code !== 0) {
reject(`Maestro test failed with code ${code}. See logs above.`);
} else {
resolve(undefined);
}
});
});
};
/**
* Run a Maestro test with retries to handle transient failures on slow CI VMs.
*
* @param test - The path to the Maestro test file relative to the `e2e` directory.
* @returns A promise that resolves when the test passes.
*/
export const maestro = async (test: string) => {
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
try {
await runMaestro(test);
return;
} catch (error) {
if (attempt < MAX_ATTEMPTS) {
console.warn(`Maestro attempt ${attempt}/${MAX_ATTEMPTS} failed, retrying...`);
} else {
throw error;
}
}
}
};