test('clinic flame -- node - bad status code', function (t) { // collect data cli({ relayStderr: false }, [ 'clinic', 'flame', '--no-open', '--', 'node', '-e', 'process.exit(1)' ], function (err, stdout, stderr) { t.strictDeepEqual(err, new Error('process exited with exit code 1')) t.strictEqual(stdout, 'To generate the report press: Ctrl + C\n') t.ok(stderr.includes('subprocess error, code: 1')) t.end() }) })
test('authenticate', async function (t) { let openedUrl = '' const openStub = url => { openedUrl = url return openSuccess() } const authenticate = proxyquire('../lib/authenticate', { open: openStub }) // mocking the browser opening const jwtToken = await authenticate(`http://127.0.0.1:${server.address().port}`) t.plan(2) t.strictEqual(openedUrl.split('/auth/token/')[1].replace('/', ''), cliToken) t.strictEqual(jwtToken, 'jwtToken') })
test('correctly log -Infinity', async (t) => { const stream = sink() const instance = pino(stream) const o = { num: -Infinity } instance.info(o) const { num } = await once(stream, 'data') t.is(num, null) })
test('clinic flame --on-port', function (t) { cli({ relayStderr: false }, [ 'clinic', 'flame', '--no-open', '--on-port', 'autocannon localhost:$PORT -d 2', '--', 'node', path.join(__dirname, 'server.js') ], function (err, stdout, stderr) { t.ifError(err) t.ok(stderr.indexOf('Running 2s test @ http://localhost:') > -1) t.strictEqual(stdout.split('\n')[0], 'Analysing data') t.end() }) })
test('clinic flame --version', function (t) { cli({}, ['clinic', 'flame', '--version'], function (err, stdout) { t.ifError(err) t.strictEqual( stdout, `v${require('@nearform/flame/version')}\n` ) t.end() }) })
test('clinic -v', function (t) { cli({}, ['clinic', '-v'], function (err, stdout) { t.ifError(err) t.strictEqual( stdout, `v${require('../package.json').version}\n` ) t.end() }) })
test('clinic bubbleprof --collect-only - missing data', function (t) { const arg = 'missing.clinic-bubbleprof' cli({ relayStderr: false }, [ 'clinic', 'bubbleprof', '--visualize-only', arg ], function (err, stdout, stderr) { t.strictDeepEqual(err, new Error('process exited with exit code 1')) t.strictEqual(stdout, '') t.ok(stderr.includes(`Unknown argument "${arg}". Pattern: {pid}.clinic-{command}`)) t.end() }) })
test('correctly log NaN', async (t) => { const stream = sink() const instance = pino(stream) const o = { num: NaN } instance.info(o) const { num } = await once(stream, 'data') t.is(num, null) })
test('clinic doctor --collect-only - bad status code', function (t) { cli({ relayStderr: false }, [ 'clinic', 'doctor', '--collect-only', '--dest', './foo', '--', 'node', '-e', 'process.exit(1)' ], function (err, stdout, stderr, tempdir) { t.strictDeepEqual(err, new Error('process exited with exit code 1')) t.strictEqual(stdout, 'To stop data collection press: Ctrl + C\n') t.ok(stderr.includes('process exited with exit code 1')) t.end() }) })
test('clinic bubbleprof -v', function (t) { cli({}, ['clinic', 'bubbleprof', '-v'], function (err, stdout) { t.ifError(err) t.strictEqual( stdout, `v${require('@nearform/bubbleprof/package.json').version}\n` ) t.end() }) })
test('clinic --version', function (t) { cli({}, ['clinic', '--version'], function (err, stdout) { t.ifError(err) t.strictEqual( stdout, `v${require('../package.json').version}\n` ) t.end() }) })