8000 Merge pull request #4402 from microsoft/octogonz/jest-console-log · strogo/rushstack@8d6ba52 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d6ba52

Browse files
authored
Merge pull request microsoft#4402 from microsoft/octogonz/jest-console-log
[heft] "heft --debug test" and "heft test --verbose" should enable Jest's verbose mode
2 parents ac85843 + 0aa855b commit 8d6ba52

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

build-tests/heft-jest-reporters-test/config/jest.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "@rushstack/heft-jest-plugin/includes/jest-shared.config.json",
33
"coverageDirectory": "<rootDir>/coverage",
44
"reporters": ["default", "../lib/test/customJestReporter.cjs"],
5-
"testMatch": ["<rootDir>/lib/**.test.cjs"],
5+
"testMatch": ["<rootDir>/lib/**/*.test.cjs"],
66
"collectCoverageFrom": [
77
"lib/**/*.cjs",
88
"!lib/**/*.d.ts",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-jest-plugin",
5+
"comment": "Use Jest verbose logging when `heft --debug test` or `heft test --verbose` is specified",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-jest-plugin"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-jest-plugin",
5+
"comment": "Fix an issue where `silent: true` was ignored when specified in `jest.config.json`",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-jest-plugin"
10+
}

heft-plugins/heft-jest-plugin/src/JestPlugin.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,18 @@ export default class JestPlugin implements IHeftTaskPlugin<IJestPluginOptions> {
576576
jestConfig.displayName = heftConfiguration.projectPackageJson.name;
577577
}
578578

579+
let silent: boolean | undefined;
580+
if (taskSession.parameters.verbose || taskSession.parameters.debug) {
581+
// If Heft's "--verbose" or "--debug" parameters were used, then we're debugging Jest problems,
582+
// so we always want to see "console.log()" even if jest.config.json asked to suppress it.
583+
// If someone really dislikes that, we could expose "--silent" in the Heft CLI,
584+
// but it is a confusing combination.
585+
silent = false;
586+
} else {
587+
// If "silent" is specified via IJestPluginOptions, that takes precedence over jest.config.json
588+
silent = options.silent ?? jestConfig.silent ?? false;
589+
}
590+
579591
const jestArgv: Config.Argv = {
580592
// In debug mode, avoid forking separate processes that are difficult to debug
581593
runInBand: taskSession.parameters.debug,
@@ -590,7 +602,23 @@ export default class JestPlugin implements IHeftTaskPlugin<IJestPluginOptions> {
590602
listTests: false,
591603
rootDir: buildFolderPath,
592604

593-
silent: options.silent || false,
605+
// What these fields mean for Jest:
606+
//
607+
// If "silent" is true:
608+
// - Jest discards all console.log() output and there is no way to retrieve it
609+
//
610+
// If "silent" is false and "verbose" is false:
611+
// - Jest uses BufferedConsole which doesn't show console.log() until after the test run completes,
612+
// which is annoying in the debugger. The output is formatted nicely using HeftJestReporter.
613+
//
614+
// If "silent" is false and "verbose" is true:
615+
// - Jest uses CustomConsole which logs immediately, but shows ugly call stacks with each log.
616+
//
617+
// If "verbose" is true (regardless of "silent"):
618+
// - Jest reports include detailed results for every test, even if all tests passed within a test suite.
619+
silent,
620+
verbose: taskSession.parameters.verbose || taskSession.parameters.debug,
621+
594622
testNamePattern: options.testNamePattern,
595623
testPathIgnorePatterns: options.testPathIgnorePatterns ? [options.testPathIgnorePatterns] : undefined,
596624
testPathPattern: options.testPathPattern ? [options.testPathPattern] : undefined,

0 commit comments

Comments
 (0)
0