Skip to content

Commit df87aa1

Browse files
authored
Enhance output config support (#1119)
* fix auto-focus issue; adding more diagnosis messages; clean up dead files * prepare for release 6.2.2 * make conflict warning message non-modal and more consistent with the rest of the doc * updated release note
1 parent bab26b4 commit df87aa1

14 files changed

+392
-278
lines changed

README.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You can see the full [features](#features) and learn more details in the [How-To
2626
Happy testing!
2727

2828
## Releases
29-
- **Current** ([v6.2.1](https://github.com/jest-community/vscode-jest/releases/tag/v6.2.1)): [release note](release-notes/release-note-v6.md#v621)
29+
- **Current** ([v6.2.2](https://github.com/jest-community/vscode-jest/releases/tag/v6.2.2)): [release note](release-notes/release-note-v6.md#v622)
3030
- **Previous** ([v5.2.3](https://github.com/jest-community/vscode-jest/releases/tag/v5.2.3)): [release note](release-notes/release-note-v5.x.md#v523)
3131

3232

@@ -348,7 +348,7 @@ for example:
348348

349349
#### outputConfig
350350

351-
The `outputConfig` controls the Jest output experience by specifying when and where to create, display, and clear the output content. It supports 2 output panels: `TEST RESULTS` and `TERMINAL`. The `TEST RESULTS` panel displays test results in the order they were run, while the `TERMINAL` panel organizes outputs by workspace folder. `TERMINAL` panel also contains the non-test run outputs, such as [quick-fix link](#quick-fix-chooser), extension auto-config info and tips.
351+
The `outputConfig` controls the Jest output experience by specifying when and where to create, display, and clear the output content. It supports 2 output panels: `TEST RESULTS` and `TERMINAL`. The `TEST RESULTS` panel displays test results in the order they were run, while the `TERMINAL` panel organizes outputs by workspace folder. `TERMINAL` panel also contains the non-test run outputs, such as [quick-fix link](#quick-fix-chooser), extension auto-config info, and tips.
352352

353353
**Type Definitions**
354354
```ts
@@ -387,8 +387,8 @@ This setting can be one of the predefined types or a custom object.
387387
4. "none": Do not clear any panel. (default)
388388
(_**Note**: As of the current version, the testing framework does not support the clearing of the "TEST RESULTS" panel without side effects. The closest available command also clears all test item statuses, which may not be desirable. We are aware of this limitation and will raise the issue with the VS Code team._)
389389

390-
**Handling Conflicts with "TEST RESULTS" panel**
391390
<a id="outputconfig-conflict"></a>
391+
**Handling Conflicts with "TEST RESULTS" panel**
392392

393393
_The Problem_
394394

@@ -404,14 +404,25 @@ _Further Customization_
404404

405405
However, if you prefer "TEST RESULTS" and "TERMINAL" panels to behave differently and don't mind managing 2 settings yourself, you could play with different combinations.
406406

407-
For instance, if `"testing.openTesting"` is set to `"openOnTestFailure"`, and you want your terminal panel to still reveal when any tests run, your setting would look like this: `"jest.outputConfig": {revealWithFocus: "test-results"}`
407+
For instance, if `"testing.openTesting"` is set to `"openOnTestFailure"`, and you want your terminal panel to still reveal when any tests run, your setting would look like this: `"jest.outputConfig": {revealWithFocus: "terminal"}`.
408+
409+
_Validation and Diagnosis_
410+
411+
The extension features output config diagnosis information in the jest terminal, as well as the built-in conflict detection and quick fixes to assist with the transition.
412+
413+
<a id="outputconfig-issues"></a>
414+
**Common Issues**
408415

409-
_Built-in Validation_
416+
Upon upgrading to v6.2, some users, frequently with auto run modes (e.g., 'watch', 'on-save'), might experience frequent "TEST RESULTS" panel automatically grabbing focus whenever files are saved or tests are run.
410417

411-
The extension also features built-in conflict detection and quick fixes to assist.
418+
This is due to the extension generates a default `jest.outputConfig`, if none is existing in your settings, to match the existing `testing.openTesting` setting, which defaults to `"openOnTestStart"`. If this is not your desired output experience, you can easily disable `testing.openTesting` in your settings.json:
419+
```json
420+
"testing.openTesting": "neverOpen"
421+
```
422+
Then use the `jest.outputConfig` to find-tune the output experience you prefer.
412423

413424
**Examples**
414-
- Choose a passive output experience that is identical to the previous version.
425+
- Choose a passive output experience that is identical to the previous version: no automatic focus switch, no automatic clear.
415426
```json
416427
"testing.openTesting": "neverOpen",
417428
"jest.outputConfig": "neutral"
@@ -421,20 +432,17 @@ The extension also features built-in conflict detection and quick fixes to assis
421432
"testing.openTesting": "neverOpen",
422433
"jest.outputConfig": "terminal-based"
423434
```
424-
- Choose a test-results-based experience and switch focus to it when test fails.
435+
- Choose a test-results-based experience and switch focus to it when test run starts.
425436
```json
426437
"testing.openTesting": "neverOpen",
427-
"jest.outputConfig": {
428-
"revealOn": "error",
429-
"revealWithFocus": "test-results",
430-
}
438+
"jest.outputConfig": "test-results-based"
431439
```
432-
alternatively:
440+
- Choose a test-results-based experience and switch focus to it when test fails.
433441
```json
434-
"testing.openTesting": "openOnTestFailure",
442+
"testing.openTesting": "neverOpen",
435443
"jest.outputConfig": {
436444
"revealOn": "error",
437-
"revealWithFocus": "test-results"
445+
"revealWithFocus": "test-results",
438446
}
439447
```
440448
- Clear the terminal output on each run but do not automatically switch focus to any panel.
@@ -556,10 +564,11 @@ While the concepts of performance and automation are generally clear, "completen
556564
2. If you modify the source or test code, potential failures in other tests may remain hidden until they are explicitly run.
557565
3. Tests bearing dynamic names, like those using test.each with variables or template literals, won't be translated. As a result, they must be executed through higher-level constructs, such as describe blocks with static names or entire test suites.
558566

559-
560-
<a id="runmode-migration"></a>
561-
**Migration Guide**
562-
Starting from v6.1.0, if no runMode is defined in settings.json, the extension will automatically generate one using legacy settings (`autoRun`, `showCoverageOnLoad`). To migrate, simply use the `"Jest: Save Current RunMode"` command from the command palette to update the setting, then remove the deprecated settings.
567+
> [!NOTE]
568+
> <a id="runmode-migration"></a>
569+
> **Migration Guide**
570+
>
571+
> Starting from v6.1.0, if no runMode is defined in settings.json, the extension will automatically generate one using legacy settings (`autoRun`, `showCoverageOnLoad`). To migrate, simply use the `"Jest: Save Current RunMode"` command from the command palette to update the setting, then remove the deprecated settings.
563572
564573
---
565574

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-jest",
33
"displayName": "Jest",
44
"description": "Use Facebook's Jest With Pleasure.",
5-
"version": "6.2.1",
5+
"version": "6.2.2",
66
"publisher": "Orta",
77
"engines": {
88
"vscode": "^1.68.1"
@@ -406,6 +406,10 @@
406406
"command": "io.orta.jest.save-output-config",
407407
"title": "Jest: Save Current Output Config"
408408
},
409+
{
410+
"command": "io.orta.jest.disable-auto-focus",
411+
"title": "Jest: Disable Auto Focus Test Output"
412+
},
409413
{
410414
"command": "io.orta.jest.run-all-tests",
411415
"title": "Jest: Run All Tests"

release-notes/release-note-v6.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
Release Notes <!-- omit in toc -->
44
---
55

6-
- [v6.2.1](#v621)
6+
- [v6.2.2](#v622)
77
- [CHANGELOG](#changelog)
8+
- [v6.2.1](#v621)
9+
- [CHANGELOG](#changelog-1)
810
- [v6.2.0](#v620)
911
- [New Features Summary](#new-features-summary)
1012
- [Bug Fixes and Technical Debt Reduction](#bug-fixes-and-technical-debt-reduction)
1113
- [Breaking Changes](#breaking-changes)
12-
- [CHANGELOG](#changelog-1)
14+
- [CHANGELOG](#changelog-2)
1315
- [v6.1 (pre-release)](#v61-pre-release)
1416
- [Main Features](#main-features)
1517
- [1. Enhanced Test Execution Control with "runMode"](#1-enhanced-test-execution-control-with-runmode)
@@ -29,10 +31,37 @@ Release Notes <!-- omit in toc -->
2931
- [3. Control extension activation within each folder](#3-control-extension-activation-within-each-folder)
3032
- [4. Auto clear output upon test run](#4-auto-clear-output-upon-test-run)
3133
- [Fixes](#fixes)
32-
- [CHANGELOG](#changelog-2)
34+
- [CHANGELOG](#changelog-3)
3335

3436
---
3537

38+
## v6.2.2
39+
This release is a patch release with the following changes:
40+
41+
**Enhancement**
42+
43+
- Improved output config validation logic and showed warning if detected upon starting up. ([#1119](https://github.com/jest-community/vscode-jest/pull/1119) - @connectdotz)
44+
45+
- Added more diagnosis and fix-it instructions in the jest terminal: ([#1119](https://github.com/jest-community/vscode-jest/pull/1119) - @connectdotz)
46+
47+
- Display critical settings such as "jest.runMode", "jest.outputConfig" and "testing.openTesting" settings
48+
- Provide warning messages for common output issues, such as aggressive auto-focus for auto run modes, when detected. Provides quick fix instructions to address them.
49+
50+
51+
**Bug Fixes**
52+
- Fixed an outputConfig initialization bug that did not honor "testing.openTesting": "openOnTestFailure" setting correctly. ([#1119](https://github.com/jest-community/vscode-jest/pull/1119) - @connectdotz)
53+
54+
**New Command**
55+
- Added a new command `"Jest: Disable Auto Focus Test Output"` to easily disable TEST RESULTS panel auto focus. It will set the output to the "neutral" mode, i.e., no auto focusing. ([#1119](https://github.com/jest-community/vscode-jest/pull/1119) - @connectdotz)
56+
57+
58+
**Documentation**
59+
- Minor docs updates for the migration guides. ([#1116](https://github.com/jest-community/vscode-jest/pull/1116) - @pmcelhaney)
60+
- Minor update for the output config info in README and release notes. ([#1119](https://github.com/jest-community/vscode-jest/pull/1119) - @connectdotz)
61+
62+
### CHANGELOG
63+
- [v6.2.2](https://github.com/jest-community/vscode-jest/releases/tag/v6.2.2)
64+
3665
## v6.2.1
3766
This release is a patch release with the following bug fix:
3867

@@ -161,7 +190,25 @@ Here are a few scenarios and how to configure them:
161190
"jest.outputConfig": "neutral"
162191
}
163192

164-
// Auto-focus on "TEST RESULTS" when errors occur, ideal for on-demand testing
193+
// or semi-minimal interaction, suitable for watch/on-save modes prefer to see output if there is errors
194+
{
195+
"testing.openTesting": "neverOpen",
196+
"jest.outputConfig": {
197+
"revealOn": "error",
198+
"revealWithFocus": "test-results"
199+
}
200+
}
201+
202+
// Auto-focus on "TEST RESULTS" when run starts, ideal for on-demand testing
203+
{
204+
"testing.openTesting": "neverOpen",
205+
"jest.outputConfig": {
206+
"revealOn": "run",
207+
"revealWithFocus": "test-results"
208+
}
209+
}
210+
211+
// or Auto-focus on "TEST RESULTS" when errors occurred, for on-demand testing prefer to only show output with errors
165212
{
166213
"testing.openTesting": "neverOpen",
167214
"jest.outputConfig": {

src/JestExt/core.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { CoverageMapData } from 'istanbul-lib-coverage';
1919
import { Logging } from '../logging';
2020
import { createProcessSession, ProcessSession } from './process-session';
2121
import { JestExtContext, JestSessionEvents, JestExtSessionContext, JestRunEvent } from './types';
22-
import { extensionName, SupportedLanguageIds } from '../appGlobals';
22+
import { extensionName, OUTPUT_CONFIG_HELP_URL, SupportedLanguageIds } from '../appGlobals';
2323
import { createJestExtContext, getExtensionResourceSettings, prefixWorkspace } from './helper';
2424
import { PluginResourceSettings } from '../Settings';
2525
import { WizardTaskId } from '../setup-wizard';
@@ -38,6 +38,8 @@ interface JestCommandSettings {
3838
jestCommandLine: string;
3939
}
4040

41+
const AUTO_FOCUS_WARNING = `The TEST RESULTS panel has auto-focus enabled, which may cause frequent focus shifts during the current run mode. If this becomes a problem, you can disable the auto-focus using the command "Jest: Disable Auto Focus Test Output". Alternatively, click on the action link below. For more details, see ${OUTPUT_CONFIG_HELP_URL}`;
42+
4143
/** extract lines starts and end with [] */
4244
export class JestExt {
4345
coverageMapProvider: CoverageMapProvider;
@@ -139,8 +141,12 @@ export class JestExt {
139141
if (pluginSettings.enable === false) {
140142
throw new Error(`Jest is disabled for workspace ${workspaceFolder.name}`);
141143
}
144+
const { outputConfig, openTesting } = outputManager.outputConfigs();
142145
this.output.write(
143-
`RunMode: ${JSON.stringify(pluginSettings.runMode.config, undefined, 4)}`,
146+
'Critical Settings:\r\n' +
147+
`jest.runMode: ${JSON.stringify(pluginSettings.runMode.config, undefined, 4)}\r\n` +
148+
`jest.outputConfig: ${JSON.stringify(outputConfig, undefined, 4)}\r\n` +
149+
`testing.openTesting: ${JSON.stringify(openTesting, undefined, 4)}\r\n`,
144150
'info'
145151
);
146152
return pluginSettings;
@@ -309,6 +315,7 @@ export class JestExt {
309315

310316
// update visible editors that belong to this folder
311317
this.updateVisibleTextEditors();
318+
this.warnAutoRunAutoFocus();
312319
} catch (e) {
313320
this.outputActionMessages(
314321
`Failed to start jest session: ${e}`,
@@ -341,6 +348,24 @@ export class JestExt {
341348
}
342349
}
343350

351+
// check if output config has conflict, especially for auto-run modes
352+
private async warnAutoRunAutoFocus(): Promise<void> {
353+
if (
354+
this.extContext.settings.runMode.config.deferred ||
355+
this.extContext.settings.runMode.config.type === 'on-demand' ||
356+
outputManager.isAutoFocus() === false
357+
) {
358+
return;
359+
}
360+
const cmdLink = executableTerminalLinkProvider.executableLink(
361+
this.extContext.workspace.name,
362+
`${extensionName}.disable-auto-focus`
363+
);
364+
365+
this.output.write(AUTO_FOCUS_WARNING, 'warn');
366+
this.output.write(`Disable Auto Focus: \u2192 ${cmdLink}\r\n`, 'info');
367+
}
368+
344369
private updateTestFileEditor(editor: vscode.TextEditor): void {
345370
if (!this.isTestFileEditor(editor)) {
346371
return;

src/appGlobals.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ export const SupportedLanguageIds = [
77
'typescriptreact',
88
'vue',
99
];
10+
11+
export const REPO_BASE_URL = 'https://github.com/jest-community/vscode-jest';
12+
export const TROUBLESHOOTING_URL = `${REPO_BASE_URL}#troubleshooting`;
13+
export const LONG_RUN_TROUBLESHOOTING_URL = `${REPO_BASE_URL}#what-to-do-with-long-running-tests-warning`;
14+
export const OUTPUT_CONFIG_HELP_URL = `${REPO_BASE_URL}#outputconfig`;

src/extension-manager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { enabledWorkspaceFolders } from './workspace-manager';
1717
import { VirtualFolderBasedCache } from './virtual-workspace-folder';
1818
import { updateSetting } from './Settings';
1919
import { showQuickFix } from './quick-fix';
20+
import { outputManager } from './output-manager';
2021

2122
export type GetJestExtByURI = (uri: vscode.Uri) => JestExt[];
2223

@@ -518,6 +519,7 @@ export class ExtensionManager {
518519

519520
activate(): void {
520521
this.showReleaseMessage();
522+
outputManager.validate();
521523

522524
if (vscode.window.activeTextEditor?.document.uri) {
523525
this.onExtensionByUri(vscode.window.activeTextEditor?.document.uri, (ext) => {
@@ -529,7 +531,7 @@ export class ExtensionManager {
529531

530532
const ReleaseNoteBase = 'https://github.com/jest-community/vscode-jest/blob/master/release-notes';
531533
const ReleaseNotes: Record<string, string> = {
532-
'6.2.1': `${ReleaseNoteBase}/release-note-v6.md#v621`,
534+
'6.2.2': `${ReleaseNoteBase}/release-note-v6.md#v622`,
533535
'6.2.0': `${ReleaseNoteBase}/release-note-v6.md#v620`,
534536
'6.1.0': `${ReleaseNoteBase}/release-note-v6.md#v610-pre-release`,
535537
'6.0.0': `${ReleaseNoteBase}/release-note-v6.md#v600-pre-release`,

src/messaging.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)