Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[heft] "heft --debug test" and "heft test --verbose" should enable Jest's verbose mode #4402

Merged
merged 6 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "@rushstack/heft-jest-plugin/includes/jest-shared.config.json",
"coverageDirectory": "<rootDir>/coverage",
"reporters": ["default", "../lib/test/customJestReporter.cjs"],
"testMatch": ["<rootDir>/lib/**.test.cjs"],
"testMatch": ["<rootDir>/lib/**/*.test.cjs"],
"collectCoverageFrom": [
"lib/**/*.cjs",
"!lib/**/*.d.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
30 changes: 29 additions & 1 deletion heft-plugins/heft-jest-plugin/src/JestPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,18 @@ export default class JestPlugin implements IHeftTaskPlugin<IJestPluginOptions> {
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
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,
Expand All @@ -590,7 +602,23 @@ export default class JestPlugin implements IHeftTaskPlugin<IJestPluginOptions> {
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,
Expand Down
Loading