diff --git a/build-tests/heft-jest-reporters-test/config/jest.config.json b/build-tests/heft-jest-reporters-test/config/jest.config.json index 1af6352cc6e..294f12cc0bb 100644 --- a/build-tests/heft-jest-reporters-test/config/jest.config.json +++ b/build-tests/heft-jest-reporters-test/config/jest.config.json @@ -2,7 +2,7 @@ "extends": "@rushstack/heft-jest-plugin/includes/jest-shared.config.json", "coverageDirectory": "/coverage", "reporters": ["default", "../lib/test/customJestReporter.cjs"], - "testMatch": ["/lib/**.test.cjs"], + "testMatch": ["/lib/**/*.test.cjs"], "collectCoverageFrom": [ "lib/**/*.cjs", "!lib/**/*.d.ts", diff --git a/common/changes/@rushstack/heft-jest-plugin/octogonz-jest-console-log_2023-10-20-19-18.json b/common/changes/@rushstack/heft-jest-plugin/octogonz-jest-console-log_2023-10-20-19-18.json new file mode 100644 index 00000000000..ab44a43588f --- /dev/null +++ b/common/changes/@rushstack/heft-jest-plugin/octogonz-jest-console-log_2023-10-20-19-18.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/heft-jest-plugin", + "comment": "Use Jest verbose logging when `heft --debug test` or `heft test --verbose` is specified", + "type": "minor" + } + ], + "packageName": "@rushstack/heft-jest-plugin" +} \ No newline at end of file diff --git a/common/changes/@rushstack/heft-jest-plugin/octogonz-jest-console-log_2023-10-20-23-29.json b/common/changes/@rushstack/heft-jest-plugin/octogonz-jest-console-log_2023-10-20-23-29.json new file mode 100644 index 00000000000..7c6c1346ba3 --- /dev/null +++ b/common/changes/@rushstack/heft-jest-plugin/octogonz-jest-console-log_2023-10-20-23-29.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/heft-jest-plugin", + "comment": "Fix an issue where `silent: true` was ignored when specified in `jest.config.json`", + "type": "minor" + } + ], + "packageName": "@rushstack/heft-jest-plugin" +} \ No newline at end of file diff --git a/heft-plugins/heft-jest-plugin/src/JestPlugin.ts b/heft-plugins/heft-jest-plugin/src/JestPlugin.ts index caced55c1fa..a7683553c4a 100644 --- a/heft-plugins/heft-jest-plugin/src/JestPlugin.ts +++ b/heft-plugins/heft-jest-plugin/src/JestPlugin.ts @@ -576,6 +576,18 @@ export default class JestPlugin implements IHeftTaskPlugin { jestConfig.displayName = heftConfiguration.projectPackageJson.name; } + let silent: boolean | undefined; + if (taskSession.parameters.verbose || taskSession.parameters.debug) { + // If Heft's "--verbose" or "--debug" parameters were used, then we're debugging Jest problems, + // so we always want to see "console.log()" even if jest.config.json asked to suppress it. + // If someone really dislikes that, we could expose "--silent" in the Heft CLI, + // but it is a confusing combination. + silent = false; + } else { + // If "silent" is specified via IJestPluginOptions, that takes precedence over jest.config.json + silent = options.silent ?? jestConfig.silent ?? false; + } + const jestArgv: Config.Argv = { // In debug mode, avoid forking separate processes that are difficult to debug runInBand: taskSession.parameters.debug, @@ -590,7 +602,23 @@ export default class JestPlugin implements IHeftTaskPlugin { listTests: false, rootDir: buildFolderPath, - silent: options.silent || false, + // What these fields mean for Jest: + // + // If "silent" is true: + // - Jest discards all console.log() output and there is no way to retrieve it + // + // If "silent" is false and "verbose" is false: + // - Jest uses BufferedConsole which doesn't show console.log() until after the test run completes, + // which is annoying in the debugger. The output is formatted nicely using HeftJestReporter. + // + // If "silent" is false and "verbose" is true: + // - Jest uses CustomConsole which logs immediately, but shows ugly call stacks with each log. + // + // If "verbose" is true (regardless of "silent"): + // - Jest reports include detailed results for every test, even if all tests passed within a test suite. + silent, + verbose: taskSession.parameters.verbose || taskSession.parameters.debug, + testNamePattern: options.testNamePattern, testPathIgnorePatterns: options.testPathIgnorePatterns ? [options.testPathIgnorePatterns] : undefined, testPathPattern: options.testPathPattern ? [options.testPathPattern] : undefined,