Unverified Commit abfbf41e authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

test(integration): emit console error when test fails (#35507)



Minor improvements to the integration test runner to emit process's stdout when its execution failed.

We have `console.log` for the output, but it doesn't emit actually since jest suppresses console output unlesss _assertion_ fails. If we throws in `before*` hook, since there's no actual assertion fails jest won't release captured console logs.

PR adds one straightforward workaround (https://stackoverflow.com/questions/48695717/console-log-statements-output-nothing-at-all-in-jest) to emit if process exits with non-zero errorcode. To avoid any existing behavior, this is not enabled for the cases when process successfully exits.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
parent 53d1b00c
......@@ -26,6 +26,7 @@ import dynamicImportTests from './dynamic'
import processEnv from './process-env'
import security from './security'
import { promisify } from 'util'
import { error } from 'console'
const glob = promisify(globOriginal)
......@@ -53,10 +54,14 @@ describe('Production Usage', () => {
context.appPort = appPort
app = await nextStart(appDir, appPort, { cwd: appDir })
output = (result.stderr || '') + (result.stdout || '')
console.log(output)
if (result.code !== 0) {
error(output)
throw new Error(`Failed to build, exited with code ${result.code}`)
} else {
// Note: jest captures calls to console and only emits when there's assertion fails,
// so this won't log anything for normal test execution path.
console.log(output)
}
})
afterAll(async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment