| 47 | ); |
| 48 | |
| 49 | async function runTest(config) { |
| 50 | if (config.before) { |
| 51 | await config.before(); |
| 52 | } |
| 53 | return new Promise((resolve, reject) => { |
| 54 | let stdout = ''; |
| 55 | let stderr = ''; |
| 56 | |
| 57 | const spawnOptions = { |
| 58 | timeout: 40_000, |
| 59 | env: { ...process.env, FORCE_COLOR: '0', ...config.env }, |
| 60 | killSignal: 'SIGKILL' |
| 61 | }; |
| 62 | const childProcess = config.spawnArgs |
| 63 | ? spawn('node', [config.spawnScript || rollupBinary, ...config.spawnArgs], spawnOptions) |
| 64 | : exec(config.command.replace(/(^| )rollup($| )/g, ` node ${rollupBinary} `), spawnOptions); |
| 65 | |
| 66 | childProcess.stdout.on('data', data => { |
| 67 | stdout += String(data); |
| 68 | }); |
| 69 | |
| 70 | childProcess.stderr.on('data', async data => { |
| 71 | stderr += String(data); |
| 72 | if (config.abortOnStderr) { |
| 73 | try { |
| 74 | if (await config.abortOnStderr(String(data))) { |
| 75 | childProcess.kill('SIGTERM'); |
| 76 | } |
| 77 | } catch (error) { |
| 78 | childProcess.kill('SIGTERM'); |
| 79 | reject(error); |
| 80 | } |
| 81 | } |
| 82 | }); |
| 83 | |
| 84 | childProcess.on('error', error => { |
| 85 | console.log('GOT AN ERROR', error); |
| 86 | reject(error); |
| 87 | childProcess.kill('SIGKILL'); |
| 88 | }); |
| 89 | |
| 90 | childProcess.on('close', async code => { |
| 91 | try { |
| 92 | let error; |
| 93 | if (code > 0) { |
| 94 | error = new Error(stderr); |
| 95 | error.code = code; |
| 96 | } |
| 97 | if (config.after) { |
| 98 | await config.after(error, stdout, stderr); |
| 99 | } |
| 100 | if (error && !childProcess.killed) { |
| 101 | if (config.error) { |
| 102 | if (!config.error(error)) { |
| 103 | return resolve(); |
| 104 | } |
| 105 | } else { |
| 106 | return reject(error); |