const executeCommand = (command, args) => { const child = spawn(command, args, { stdio: 'inherit' }); return new Promise((resolve, reject) => { child.on('close', code => { if (code !== 0) { reject(new Error(`${command} ${args.join(' ')} failed with exit code ${code}`)); return; } resolve(); }); }); }
function test (file) { file = join('fixtures', 'broken-pipe', file) t.test(file, { parallel: true }, async ({ is }) => { const child = fork(join(__dirname, file), { silent: true }) child.stdout.destroy() child.stderr.pipe(process.stdout) const res = await once(child, 'close') is(res, 0) // process exits successfully }) }
app.get('/playground/dashboard-app-status', catchErrors(async (req, res) => { this.cubejsServer.event('Dev Server Dashboard App Status'); const dashboardPort = this.dashboardAppProcess && await this.dashboardAppProcess.dashboardUrlPromise; res.json({ running: !!dashboardPort, dashboardPort, dashboardAppPath: path.resolve(dashboardAppPath) }); }));
describe('server listening', () => { it('should be listening', async () => { const child = childProcess.exec(`node ${appPath}`); const isOpen = await waitPort({port: PORT}); expect(isOpen).to.be.true; process.kill(child.pid, 'SIGTERM'); }); });
child.on('close', (code) => { if (code !== 0) { reject(`Ended with code ${code}`); } else { resolve(); } });
test.serial('Running `carbon-now` fails without file or stdin', async t => { try { // https://github.com/sindresorhus/get-stdin/issues/13#issuecomment-279234249 const command = exec(`node ${SCRIPT}`); command.childProcess.stdin.end(); await command; t.fail(); } catch (error) { t.pass(); } });
test('do not use SonicBoom is someone tampered with process.stdout.write', async ({ isNot }) => { var actual = '' const child = fork(join(__dirname, 'fixtures', 'stdout-hack-protection.js'), { silent: true }) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(actual.match(/^hack/), null) })
// we open a 4th stdio as IPC doesn't work on windows for python->node child.stdio[4].on("data", async function(message) { await waitPort({ port: parseInt(message.toString()), output: "silent", timeout: 1000 * 60 * 2 // 2 Minutes }); resolve(expressWrap(message.toString().trim())); });
child.stdout.on("data", (data) => { dashboard.onEvent({ type: "stdout", data: data.toString("utf8") }); });
runner.on('exit', function (code) { server.close() process.exit(code) })
child.stderr.on("data", (data) => { dashboard.onEvent({ type: "stderr", data: data.toString("utf8") }); });
runner.on('error', function (err) { server.close() throw err })
function executeCommand(command, args, options = {}) { const child = spawn(command, args, { stdio: 'inherit', ...options }); return new Promise((resolve, reject) => { child.on('close', (code) => { if (code !== 0) { reject(new Error(`${command} ${args.join(' ')} failed with exit code ${code}. Please check your console.`)); return; } resolve(); }); }); }
describe('gae_flex_postgres_connect', () => { it('should be listening', async () => { const child = childProcess.exec(`node ${appPath}`); const isOpen = await waitPort({port: PORT}); expect(isOpen).to.be.true; process.kill(child.pid, 'SIGTERM'); }); });
// we open a 4th stdio as IPC doesn't work on windows for python->node child.stdio[4].on("data", async function(message) { await waitPort({ port: parseInt(message.toString()), output: "silent", timeout: 1000 * 60 * 2 // 2 Minutes }); resolve(expressWrap(message.toString().trim())); });