Skip to content

Commit

Permalink
feat: set correct process exit code (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Mar 1, 2020
1 parent 9c3fa21 commit 28670ea
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions src/bin/testProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,41 @@ const exec = ({
sequence: string
browser: BrowserType
params: string[]
}): void => {
const options = getSpawnOptions(browser)
if (sequence === PARALLEL) {
const process = spawn(
'node',
[`node_modules/jest/bin/jest.js ${params}`],
options,
)
process.on('close', status => {
console.log(`${getResultByStatus(status)} tests for ${browser}\n\n`)
})
} else {
const { status } = spawnSync(
'node',
[`node_modules/jest/bin/jest.js ${params}`],
options,
)
console.log(`${getResultByStatus(status)} tests for ${browser}`)
}
}
}): Promise<number | null> =>
new Promise(resolve => {
const options = getSpawnOptions(browser)
if (sequence === PARALLEL) {
const process = spawn(
'node',
[`node_modules/jest/bin/jest.js ${params}`],
options,
)
process.on('close', status => {
console.log(`${getResultByStatus(status)} tests for ${browser}\n\n`)
resolve(status)
})
} else {
const { status } = spawnSync(
'node',
[`node_modules/jest/bin/jest.js ${params}`],
options,
)
console.log(`${getResultByStatus(status)} tests for ${browser}`)
resolve(status)
}
})

const runner = async (sequence: string, params: string[]): Promise<void> => {
const { browsers = [] } = await readConfig()
checkBrowsers(browsers)
browsers.forEach(browser => exec({ sequence, browser, params }))
const exitCodes = await Promise.all(
browsers.map(browser => exec({ sequence, browser, params })),
)
if (exitCodes.every(code => code === 0)) {
process.exit(0)
} else {
process.exit(1)
}
}

export default runner

0 comments on commit 28670ea

Please sign in to comment.