Skip to content

Commit abfbf41

Browse files
authored
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`
1 parent 53d1b00 commit abfbf41

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test/integration/production/test/index.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import dynamicImportTests from './dynamic'
2626
import processEnv from './process-env'
2727
import security from './security'
2828
import { promisify } from 'util'
29+
import { error } from 'console'
2930

3031
const glob = promisify(globOriginal)
3132

@@ -53,10 +54,14 @@ describe('Production Usage', () => {
5354
context.appPort = appPort
5455
app = await nextStart(appDir, appPort, { cwd: appDir })
5556
output = (result.stderr || '') + (result.stdout || '')
56-
console.log(output)
5757

5858
if (result.code !== 0) {
59+
error(output)
5960
throw new Error(`Failed to build, exited with code ${result.code}`)
61+
} else {
62+
// Note: jest captures calls to console and only emits when there's assertion fails,
63+
// so this won't log anything for normal test execution path.
64+
console.log(output)
6065
}
6166
})
6267
afterAll(async () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy