process#stderr TypeScript Examples
The following examples show how to use
process#stderr.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: mocha-integration.test.ts From earl with MIT License | 5 votes |
function errorMessage(results: TestResults) {
return {
extraMessage:
`Expected to pass ${PASSING_TESTS} instead of ${results.passing} and fail ${FAILING_TESTS} instead of ${results.failing}.\n` +
`\nSTDOUT:\n\`${results.stdout}\`` +
`\nSTDERR:\n\`${results.stderr}\`\n\n`,
}
}
Example #2
Source File: mocha-integration.test.ts From earl with MIT License | 5 votes |
function runMocha(modes: { watch?: boolean; parallel?: boolean }) {
return new Promise<TestResults>((resolve, reject) => {
const child = spawn(
'mocha',
['--config', './mocha-config.tested.js', modes.watch && '--watch', modes.parallel && '--parallel'].filter(
(x): x is string => !!x,
),
{ env: process.env, cwd: __dirname },
)
const result = { passing: NaN, failing: NaN, stdout: '', stderr: '' }
const fail = (err: string | Error) => {
child.kill('SIGKILL')
reject(typeof err === 'string' ? new Error(err) : err)
}
const succeed = () => {
child.kill('SIGKILL')
resolve(result)
}
child.stderr.on('data', (data) => {
const str = String(data)
result.stderr += str
const ERROR_PREFIXES = ['\nĂ— \x1B[31mERROR:\x1B[39m Error:', '(node:']
if (ERROR_PREFIXES.some((prefix) => str.startsWith(prefix))) {
fail('Process crashed.\n' + str)
}
d(`stderr: ${str}`)
if (modes.watch) {
if (str.includes('[mocha] waiting for changes...')) {
succeed()
}
}
})
child.stdout.on('data', (data) => {
const str = String(data)
result.stdout += str
d(`stdout: ${str}`)
const passing = str.match(/(\d+) passing/)
if (passing) {
result.passing = parseInt(passing[1])
}
const failing = str.match(/(\d+) failing/)
if (failing) {
result.failing = parseInt(failing[1])
if (!modes.watch) {
succeed()
}
}
})
child.on('error', (err) => {
// eslint-disable-next-line no-console
console.error({ stderr })
fail(err)
})
})
}