(args)
| 18 | |
| 19 | |
| 20 | function main(args) { |
| 21 | const command = args['command']; |
| 22 | const times = parseInt(args['times']); |
| 23 | |
| 24 | if (times === 0) { |
| 25 | throw new Error(`Flaky test asked to run zero times: '${command}'`); |
| 26 | } |
| 27 | |
| 28 | console.log(`Running flaky test at most ${times} times`); |
| 29 | console.log(`Command: '${command}'`); |
| 30 | const exitCodes = []; |
| 31 | for (let i = 0; i < times; i++) { |
| 32 | console.log(`Flaky run ${i + 1} of a potential ${times} for '${command}'`); |
| 33 | const exitCode = exec(command).code; |
| 34 | exitCodes.push(exitCode); |
| 35 | if (exitCode === 0) { |
| 36 | break; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | const success = exitCodes[exitCodes.length - 1] === 0; |
| 41 | if (!success) { |
| 42 | console.error(`Flaky test failed ${times} times`); |
| 43 | } else if (exitCodes.length > 1) { |
| 44 | console.warn( |
| 45 | `Flaky test failed ${exitCodes.length - 1} times before passing.`); |
| 46 | } else { |
| 47 | // Test passed with no fails |
| 48 | console.log('Flaky test passed on the first run'); |
| 49 | } |
| 50 | console.error(`Command: '${command}'`); |
| 51 | console.error(`Exit codes: ${exitCodes}`); |
| 52 | |
| 53 | if (!success) { |
| 54 | process.exit(1); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | const parser = new ArgumentParser( |
| 59 | {description: 'Run a flaky test a number of times or until it passes'}); |
no test coverage detected
searching dependent graphs…