Skip to content

Commit 0d3bf2a

Browse files
authored
improve default test results focus behavior (#1128)
1 parent cd80572 commit 0d3bf2a

File tree

12 files changed

+487
-278
lines changed

12 files changed

+487
-278
lines changed

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
},
1111
"typescript.tsdk": "./node_modules/typescript/lib",
1212
// jest
13-
"jest.runMode":"on-demand",
14-
// "testing.openTesting": "neverOpen",
13+
1514
// eslint
1615
"tslint.enable": false,
1716
"eslint.enable": true,

README.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,15 @@ 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+
390391
<a id="outputconfig-conflict"></a>
391-
**Handling Conflicts with "TEST RESULTS" panel**
392+
**Handling Conflicts with "TEST RESULTS" panel setting**
392393

393394
_The Problem_
394395

395396
The behavior of the "TEST RESULTS" panel is influenced by VSCode's native `"testing.openTesting"` setting. This can cause inconsistencies with your `"jest.outputConfig"` settings.
396397

397-
For instance, if you set `"jest.outputConfig": {"revealWithFocus": "none"}` to prevent automatic focus changes, but leave `"testing.openTesting"` at its default value of `"openOnTestStart"`, the "TEST RESULTS" panel will still automatically switch focus whenever tests run.
398+
For instance, if you set `"jest.outputConfig": {"revealWithFocus": "none"}` to prevent automatic focus changes, but leave `"testing.openTesting"` at its default value of `"openOnTestStart"`, the "TEST RESULTS" panel will still automatically switch focus when the tests are run via UI.
398399

399400
_The Universal Solution_
400401

@@ -410,18 +411,18 @@ _Validation and Diagnosis_
410411

411412
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.
412413

413-
<a id="outputconfig-issues"></a>
414-
**Common Issues**
414+
<a id="default-output-focus"></a>
415+
**Default Output Focus Behavior by RunMode**
416+
When none of the output settings (`"testing.openTesting"` and `"jest.outputConfig"`) are present, The default output behavior is determined by [runMode](#runmode):
415417

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.
418+
| runMode| auto reveal "TEST RESULTS" | auto reveal "TERMINAL" |
419+
|:--:|:--:|:--:|
420+
| "watch" | :heavy_multiplication_x: | :heavy_multiplication_x:|
421+
| "on-save" | :heavy_multiplication_x: | :heavy_multiplication_x: |
422+
| "on-demand" | :heavy_check_mark: | :heavy_multiplication_x:|
417423

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.
423424

424-
**Examples**
425+
**Configuration Examples**
425426
- Choose a passive output experience that is identical to the previous version: no automatic focus switch, no automatic clear.
426427
```json
427428
"testing.openTesting": "neverOpen",
@@ -432,12 +433,7 @@ Then use the `jest.outputConfig` to find-tune the output experience you prefer.
432433
"testing.openTesting": "neverOpen",
433434
"jest.outputConfig": "terminal-based"
434435
```
435-
- Choose a test-results-based experience and switch focus to it when test run starts.
436-
```json
437-
"testing.openTesting": "neverOpen",
438-
"jest.outputConfig": "test-results-based"
439-
```
440-
- Choose a test-results-based experience and switch focus to it when test fails.
436+
- Choose a test-results-based experience and switch focus to it only when test fails.
441437
```json
442438
"testing.openTesting": "neverOpen",
443439
"jest.outputConfig": {
@@ -457,16 +453,17 @@ Then use the `jest.outputConfig` to find-tune the output experience you prefer.
457453
> <a id="outputconfig-migration"></a>
458454
> **Migration Guide**
459455
>
460-
> Migrating to the new `"jest.outputConfig"` can require some manual adjustments, especially if you're working in a multi-root workspace. Here are some guidelines to help with the transition:
456+
> Migrating to the new `"jest.outputConfig"` might require some manual adjustments, especially if you're working in a multi-root workspace. Here are some guidelines to help with the transition:
461457
>
462458
> 1. **Workspace Level vs Workspace-Folder Level**: The new `"jest.outputConfig"` is a workspace-level setting, unlike legacy settings like `"jest.autoClearTerminal"` and `"jest.autoRevealOutput"`, which are workspace-folder level settings.
463459
>
464460
> 2. **Backward Compatibility**: If no `"jest.outputConfig"` is defined in your settings.json, the extension will attempt to generate a backward-compatible outputConfig in memory. This uses the `"testing.openTesting"` setting and any legacy settings (`"jest.autoClearTerminal"`, `"jest.autoRevealOutput"`) you might have. Note that this might only work for single-root workspaces.
465461
>
466-
> 3. **Migration Steps**:
467-
> - Use the `"Jest: Save Current Output Config"` command from the command palette to update your settings.json.
468-
> - (optional) Fix warning: The save does not include `"testing.openTesting"`, so you might see the conflict warning message. You can either use the "Quick Fix" action or adjust the `settings.json` manually (see [handling conflict](#outputconfig-conflict)).
469-
> - Finally, remove any deprecated settings.
462+
> 3. **Customization Steps**:
463+
In general it should work out of the box, but if you encounter any issues, here are some steps to help adjusting the output behavior:
464+
> - Use the `"Jest: Save Current Output Config"` command from the command palette to update your settings.json. Then adjust it to fit your needs.
465+
> - Fix warning if any: The save does not include `"testing.openTesting"`, so you might see the conflict warning message. You can either use the "Quick Fix" action or adjust the `settings.json` manually (see [handling conflict](#outputconfig-conflict)).
466+
> - Finally, remove any deprecated settings.
470467
>
471468
> By following these guidelines, you should be able to smoothly transition to using `"jest.outputConfig"`.
472469

package.json

Lines changed: 1 addition & 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.2",
5+
"version": "6.2.3",
66
"publisher": "Orta",
77
"engines": {
88
"vscode": "^1.68.1"

release-notes/release-note-v6.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Release Notes <!-- omit in toc -->
44
---
55

6+
- [v6.2.3](#v623)
67
- [v6.2.2](#v622)
78
- [CHANGELOG](#changelog)
89
- [v6.2.1](#v621)
@@ -35,6 +36,14 @@ Release Notes <!-- omit in toc -->
3536

3637
---
3738

39+
## v6.2.3
40+
This release is a patch release with the following changes:
41+
42+
**Enhancement**
43+
44+
- Improve output-focus default behavior for auto runs (e.g., "watch", "on-save"). This will eliminate the issue that the focus auto switching to "TEST RESULTS" panel whenever files are saved in auto-run modes. Now the default behavior is runMode aware and will not auto switch for auto runs unless specifically configured to do so. See [default output focus behavior](https://github.com/jest-community/vscode-jest#default-output-focus). ([#1128](https://github.com/jest-community/vscode-jest/pull/1128) - @connectdotz)
45+
- docs: update README to fix jest run mode type. ([#1126](https://github.com/jest-community/vscode-jest/pull/1126) - @kota-kamikawa)
46+
3847
## v6.2.2
3948
This release is a patch release with the following changes:
4049

src/JestExt/core.ts

Lines changed: 5 additions & 26 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, OUTPUT_CONFIG_HELP_URL, SupportedLanguageIds } from '../appGlobals';
22+
import { extensionName, SupportedLanguageIds } from '../appGlobals';
2323
import { createJestExtContext, getExtensionResourceSettings, prefixWorkspace } from './helper';
2424
import { PluginResourceSettings } from '../Settings';
2525
import { WizardTaskId } from '../setup-wizard';
@@ -38,8 +38,6 @@ 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-
4341
/** extract lines starts and end with [] */
4442
export class JestExt {
4543
coverageMapProvider: CoverageMapProvider;
@@ -145,8 +143,8 @@ export class JestExt {
145143
this.output.write(
146144
'Critical Settings:\r\n' +
147145
`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`,
146+
`jest.outputConfig: ${JSON.stringify(outputConfig.value, undefined, 4)}\r\n` +
147+
`testing.openTesting: ${JSON.stringify(openTesting.value, undefined, 4)}\r\n`,
150148
'info'
151149
);
152150
return pluginSettings;
@@ -186,7 +184,7 @@ export class JestExt {
186184
}
187185

188186
private enableOutputOnRun(): void {
189-
outputManager.showOutputOn('run', this.output);
187+
outputManager.showOutputOn('run', this.output, this.extContext.settings.runMode);
190188
}
191189
private setupRunEvents(events: JestSessionEvents): void {
192190
events.onRunEvent.event((event: JestRunEvent) => {
@@ -236,7 +234,7 @@ export class JestExt {
236234
}
237235
case 'test-error': {
238236
if (!event.process.userData?.testError) {
239-
outputManager.showOutputOn('test-error', this.output);
237+
outputManager.showOutputOn('test-error', this.output, this.extContext.settings.runMode);
240238
event.process.userData = { ...(event.process.userData ?? {}), testError: true };
241239
}
242240
break;
@@ -321,7 +319,6 @@ export class JestExt {
321319

322320
// update visible editors that belong to this folder
323321
this.updateVisibleTextEditors();
324-
this.warnAutoRunAutoFocus();
325322
} catch (e) {
326323
this.outputActionMessages(
327324
`Failed to start jest session: ${e}`,
@@ -354,24 +351,6 @@ export class JestExt {
354351
}
355352
}
356353

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

src/Settings/helper.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as vscode from 'vscode';
2-
import { GetConfigFunction, VirtualFolderSettings, VirtualFolderSettingKey } from './types';
2+
import {
3+
GetConfigFunction,
4+
VirtualFolderSettings,
5+
VirtualFolderSettingKey,
6+
SettingDetail,
7+
} from './types';
38
import { isVirtualWorkspaceFolder } from '../virtual-workspace-folder';
49

510
/**
@@ -55,3 +60,23 @@ export const updateSetting = async (
5560
(vFolder as any)[key] = value;
5661
await config.update('virtualFolders', virtualFolders);
5762
};
63+
64+
export const getSettingDetail = <T>(configName: string, section: string): SettingDetail<T> => {
65+
// Use the `inspect` method to get detailed information about the setting
66+
const config = vscode.workspace.getConfiguration(configName);
67+
const value = config.get<T>(section);
68+
const settingInspection = config.inspect<T>(section);
69+
70+
if (settingInspection) {
71+
const isExplicitlySet =
72+
settingInspection.globalValue !== undefined ||
73+
settingInspection.workspaceValue !== undefined ||
74+
settingInspection.workspaceFolderValue !== undefined ||
75+
settingInspection.globalLanguageValue !== undefined ||
76+
settingInspection.workspaceLanguageValue !== undefined ||
77+
settingInspection.workspaceFolderLanguageValue !== undefined;
78+
79+
return { value, isExplicitlySet };
80+
}
81+
return { value: undefined, isExplicitlySet: false };
82+
};

src/Settings/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ export interface VirtualFolderSettings extends AllPluginResourceSettings {
9797
}
9898

9999
export type GetConfigFunction = <T>(key: VirtualFolderSettingKey) => T | undefined;
100+
101+
export interface SettingDetail<T> {
102+
value: T | undefined;
103+
/** true if the setting is explicitly defined in a settings file, i.e., not from default value */
104+
isExplicitlySet: boolean;
105+
}

src/extension-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ export class ExtensionManager {
531531

532532
const ReleaseNoteBase = 'https://github.com/jest-community/vscode-jest/blob/master/release-notes';
533533
const ReleaseNotes: Record<string, string> = {
534+
'6.2.3': `${ReleaseNoteBase}/release-note-v6.md#v623`,
534535
'6.2.2': `${ReleaseNoteBase}/release-note-v6.md#v622`,
535536
'6.2.0': `${ReleaseNoteBase}/release-note-v6.md#v620`,
536537
'6.1.0': `${ReleaseNoteBase}/release-note-v6.md#v610-pre-release`,

0 commit comments

Comments
 (0)