Skip to content

Commit

Permalink
test(integration): emit console error when test fails (#35507)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
kwonoj committed Mar 28, 2022
1 parent 53d1b00 commit abfbf41
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/integration/production/test/index.test.js
Expand Up @@ -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)

Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit abfbf41

Please sign in to comment.