(args = [], env = {})
| 16 | |
| 17 | // Run the script with given args, return { stdout, stderr, code } |
| 18 | function run(args = [], env = {}) { |
| 19 | try { |
| 20 | const stdout = execFileSync('node', [SCRIPT, ...args], { |
| 21 | encoding: 'utf8', |
| 22 | stdio: ['pipe', 'pipe', 'pipe'], |
| 23 | env: { ...process.env, ...env }, |
| 24 | timeout: 10000 |
| 25 | }); |
| 26 | return { stdout, stderr: '', code: 0 }; |
| 27 | } catch (err) { |
| 28 | return { |
| 29 | stdout: err.stdout || '', |
| 30 | stderr: err.stderr || '', |
| 31 | code: err.status || 1 |
| 32 | }; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // Test helper |
| 37 | function test(name, fn) { |