Skip to content

Commit 15b61f5

Browse files
authored
supports test-results panel and refactor output settings (#1087)
* updated settings changes * create output config setting * adding test-error output handling * adding predefined outputConfig enum types * refactor JestTestRun for JIT creation and delayed end to reduce unnecessary run creation * remove migration tool and command * fix tests * update doc, version and minor fixes * update doc * address PR check issues * update dependency, adjust verbose message, and upgrade settings * adding missing test
1 parent 1f33012 commit 15b61f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3796
-2566
lines changed

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@
1818
"cSpell.words": [
1919
"unmock"
2020
],
21+
"testing.openTesting": "neverOpen",
22+
"jest.outputConfig": {
23+
"clearOnRun": "terminal"
24+
}
2125
}

README.md

Lines changed: 135 additions & 19 deletions
Large diffs are not rendered by default.

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = {
2323
'debug',
2424
'@babel/template',
2525
'graceful-fs',
26-
'@babel/core',
26+
'@babel/types',
2727
],
2828
moduleNameMapper: {
2929
'\\.(svg)$': '<rootDir>/tests/fileMock.ts',

package.json

Lines changed: 98 additions & 17 deletions
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.0.2",
5+
"version": "6.1.0",
66
"publisher": "Orta",
77
"engines": {
88
"vscode": "^1.68.1"
@@ -81,7 +81,9 @@
8181
"jest.autoClearTerminal": {
8282
"description": "Clear the terminal output at the start of any new test run.",
8383
"type": "boolean",
84-
"scope": "resource"
84+
"scope": "resource",
85+
"markdownDeprecationMessage": "**Deprecated**: Please use [outputConfig](https://github.com/jest-community/vscode-jest#outputconfig) instead.",
86+
"deprecationMessage": "Deprecated: Please use jest.outputConfig instead."
8587
},
8688
"jest.rootPath": {
8789
"description": "The path to your frontend src folder",
@@ -156,7 +158,9 @@
156158
"markdownDescription": "Configure jest TestExplorer. See valid [formats](https://github.com/jest-community/vscode-jest/blob/master/README.md#testexplorer) or [how to use test explorer](https://github.com/jest-community/vscode-jest/blob/master/README.md#how-to-use-the-test-explorer) for more details",
157159
"type": "object",
158160
"default": null,
159-
"scope": "resource"
161+
"scope": "resource",
162+
"markdownDeprecationMessage": "**Deprecated**: Please use [runMode](https://github.com/jest-community/vscode-jest/blob/master/README.md#runmode) instead.",
163+
"deprecationMessage": "Deprecated: Please use jest.runMode instead."
160164
},
161165
"jest.monitorLongRun": {
162166
"markdownDescription": "Enable monitoring for long running test process. See valid [monitorLongRun](https://github.com/jest-community/vscode-jest/blob/master/README.md#monitorLongRun) for details",
@@ -182,11 +186,11 @@
182186
"disable auto show test output"
183187
],
184188
"scope": "resource",
185-
"markdownDeprecationMessage": "**Deprecated**: Please use [runMode](https://github.com/jest-community/vscode-jest/blob/master/README.md#runmode) instead.",
186-
"deprecationMessage": "Deprecated: Please use jest.runMode instead."
189+
"markdownDeprecationMessage": "**Deprecated**: Please use [outputConfig](https://github.com/jest-community/vscode-jest#outputconfig) instead.",
190+
"deprecationMessage": "Deprecated: Please use jest.outputConfig instead."
187191
},
188192
"jest.parserPluginOptions": {
189-
"markdownDescription": "Configure babel parser plugins. See valid [format](https://github.com/jest-community/vscode-jest/blob/master/README.md#parserpluginoptions)",
193+
"markdownDescription": "Configure babel parser plugins. See valid [format](https://github.com/jest-community/vscode-jest#parserpluginoptions)",
190194
"type": "object",
191195
"default": null,
192196
"scope": "resource"
@@ -208,6 +212,84 @@
208212
"type": "object"
209213
}
210214
},
215+
"jest.outputConfig": {
216+
"scope": "window",
217+
"type": [
218+
"string",
219+
"object"
220+
],
221+
"markdownDescription": "Control jest output preference. See details in [outputConfig](https://github.com/jest-community/vscode-jest#outputconfig).",
222+
"default": null,
223+
"oneOf": [
224+
{
225+
"type": "string",
226+
"enum": [
227+
"neutral",
228+
"terminal-based",
229+
"test-results-based"
230+
],
231+
"enumDescriptions": [
232+
"A passive and neutral config, will not automatically change active panel nor clear output.",
233+
"Switch to terminal panel when running tests.",
234+
"Switch to test-results panel when running tests."
235+
],
236+
"description": "Specifies the predefined common outputConfig in a string form."
237+
},
238+
{
239+
"type": "object",
240+
"properties": {
241+
"revealOn": {
242+
"type": "string",
243+
"enum": [
244+
"run",
245+
"error",
246+
"demand"
247+
],
248+
"enumDescriptions": [
249+
"Reveal the output upon test run.",
250+
"Reveal the output upon test error.",
251+
"Reveal the output on demand."
252+
],
253+
"default": "run",
254+
"description": "Determines when to reveal the test run output. Default is 'run'."
255+
},
256+
"revealWithFocus": {
257+
"type": "string",
258+
"enum": [
259+
"none",
260+
"terminal",
261+
"test-results"
262+
],
263+
"enumDescriptions": [
264+
"Do not change focus when revealing output.",
265+
"Switch to terminal when revealing output.",
266+
"Switch to test-results panel when revealing output."
267+
],
268+
"default": "none",
269+
"description": "Specifies which output panel, if any, to switch focus to when revealing. Default is 'none'."
270+
},
271+
"clearOnRun": {
272+
"type": "string",
273+
"enum": [
274+
"none",
275+
"both",
276+
"terminal",
277+
"test-results"
278+
],
279+
"enumDescriptions": [
280+
"Do not automatically clear the output before each run.",
281+
"Clear both the terminal and test results output before each run.",
282+
"Clear the terminal output before each run.",
283+
"Clear the test results output before each run."
284+
],
285+
"default": "none",
286+
"description": "Specifies which output, if any, to be cleared before each run. Default is 'none'."
287+
}
288+
},
289+
"description": "Specifies a custom output config in an object form."
290+
}
291+
]
292+
},
211293
"jest.runMode": {
212294
"markdownDescription": "Control when to run jest tests and present the results. See details in [runMode](https://github.com/jest-community/vscode-jest#runmode)",
213295
"default": null,
@@ -243,14 +325,9 @@
243325
"type": "boolean",
244326
"description": "Specifies whether to collect and report coverage information."
245327
},
246-
"revealOutput": {
247-
"type": "string",
248-
"enum": [
249-
"on-run",
250-
"on-exec-error",
251-
"on-demand"
252-
],
253-
"description": "Determines when to reveal the test run output."
328+
"showInlineError": {
329+
"type": "boolean",
330+
"description": "Specify if to enable inline error display in test file editor"
254331
},
255332
"deferred": {
256333
"type": "boolean",
@@ -325,6 +402,10 @@
325402
"command": "io.orta.jest.workspace.save-run-mode",
326403
"title": "Jest: Save Current RunMode"
327404
},
405+
{
406+
"command": "io.orta.jest.save-output-config",
407+
"title": "Jest: Save Current Output Config"
408+
},
328409
{
329410
"command": "io.orta.jest.run-all-tests",
330411
"title": "Jest: Run All Tests"
@@ -582,13 +663,13 @@
582663
"dependencies": {
583664
"istanbul-lib-coverage": "^3.2.0",
584665
"istanbul-lib-source-maps": "^4.0.1",
585-
"jest-editor-support": "^31.1.1"
666+
"jest-editor-support": "^31.1.2"
586667
},
587668
"devDependencies": {
588669
"@types/fs-extra": "^11.0.2",
589670
"@types/istanbul-lib-coverage": "^2.0.4",
590671
"@types/istanbul-lib-source-maps": "^4.0.1",
591-
"@types/jest": "^29.2.5",
672+
"@types/jest": "^29.5.6",
592673
"@types/node": "^18.11.18",
593674
"@typescript-eslint/eslint-plugin": "^5.48.1",
594675
"@typescript-eslint/parser": "^5.48.1",
@@ -600,7 +681,7 @@
600681
"eslint-plugin-prefer-arrow": "^1.2.3",
601682
"eslint-plugin-prettier": "^4.2.1",
602683
"fs-extra": "^11.1.1",
603-
"jest": "^29.3.1",
684+
"jest": "^29.7",
604685
"jest-snapshot": "^27.2.0",
605686
"prettier": "^2.8.2",
606687
"raw-loader": "^4.0.1",

src/JestExt/core.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { WorkspaceManager, isInFolder } from '../workspace-manager';
4343
import { ansiEsc, JestOutputTerminal } from './output-terminal';
4444
import { QuickFixActionType } from '../quick-fix';
4545
import { executableTerminalLinkProvider } from '../terminal-link-provider';
46+
import { outputManager } from '../output-manager';
4647

4748
interface RunTestPickItem extends vscode.QuickPickItem {
4849
id: DebugTestIdentifier;
@@ -195,12 +196,7 @@ export class JestExt {
195196
}
196197

197198
private enableOutputOnRun(): void {
198-
if (
199-
!this.extContext.settings.runMode.config.revealOutput ||
200-
this.extContext.settings.runMode.config.revealOutput === 'on-run'
201-
) {
202-
this.output.enable();
203-
}
199+
outputManager.showOutputOn('run', this.output);
204200
}
205201
private setupRunEvents(events: JestSessionEvents): void {
206202
events.onRunEvent.event((event: JestRunEvent) => {
@@ -223,14 +219,14 @@ export class JestExt {
223219
case 'exit':
224220
if (event.error) {
225221
this.updateStatusBar({ state: 'exec-error' });
226-
if (!event.process.userData?.errorReported) {
222+
if (!event.process.userData?.execError) {
227223
this.outputActionMessages(
228224
`Jest process exited unexpectedly: ${event.error}`,
229225
['wizard', 'defer', 'disable-folder', 'help'],
230226
true,
231227
event.error
232228
);
233-
event.process.userData = { ...(event.process.userData ?? {}), errorReported: true };
229+
event.process.userData = { ...(event.process.userData ?? {}), execError: true };
234230
}
235231
} else {
236232
this.updateStatusBar({ state: 'done' });
@@ -242,6 +238,13 @@ export class JestExt {
242238
}
243239
break;
244240
}
241+
case 'test-error': {
242+
if (!event.process.userData?.testError) {
243+
outputManager.showOutputOn('test-error', this.output);
244+
event.process.userData = { ...(event.process.userData ?? {}), testError: true };
245+
}
246+
break;
247+
}
245248
case 'long-run': {
246249
this.outputActionMessages(this.longRunMessage(event), ['help-long-run'], false);
247250
break;
@@ -298,10 +301,6 @@ export class JestExt {
298301
});
299302
return;
300303
}
301-
const readyState = await this.validateJestCommandLine();
302-
if (readyState !== 'pass') {
303-
return;
304-
}
305304

306305
this.dirtyFiles.clear();
307306
this.resetStatusBar();
@@ -315,6 +314,11 @@ export class JestExt {
315314
this.testProvider?.dispose();
316315
this.testProvider = new JestTestProvider(this.getExtExplorerContext());
317316

317+
const readyState = await this.validateJestCommandLine();
318+
if (readyState !== 'pass') {
319+
return;
320+
}
321+
318322
await this.processSession.start();
319323

320324
this.events.onTestSessionStarted.fire({ ...this.extContext, session: this.processSession });
@@ -395,8 +399,7 @@ export class JestExt {
395399
}
396400

397401
private updateOutputSetting(settings: PluginResourceSettings): void {
398-
this.output.revealOnError =
399-
!settings.runMode.config.deferred && settings.runMode.config.revealOutput === 'on-exec-error';
402+
this.output.revealOnError = !settings.runMode.config.deferred;
400403
this.output.close();
401404
}
402405
private testResultProviderOptions(settings: PluginResourceSettings): TestResultProviderOptions {
@@ -412,13 +415,7 @@ export class JestExt {
412415
newSettings ?? this.getExtensionResourceSettings(this.extContext.workspace);
413416

414417
// output
415-
if (
416-
this.extContext.settings.runMode.config.revealOutput !==
417-
updatedSettings.runMode.config.revealOutput ||
418-
this.extContext.settings.runMode.config.deferred !== updatedSettings.runMode.config.deferred
419-
) {
420-
this.updateOutputSetting(updatedSettings);
421-
}
418+
this.updateOutputSetting(updatedSettings);
422419

423420
// TestResultProvider
424421
this.testResultProvider.options = this.testResultProviderOptions(updatedSettings);

src/JestExt/helper.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import {
99
TestExplorerConfig,
1010
NodeEnv,
1111
MonitorLongRun,
12-
TestExplorerConfigLegacy,
1312
JestExtAutoRunSetting,
14-
AutoRevealOutputType,
1513
createJestSettingGetter,
1614
JestRunModeType,
1715
JestRunMode,
@@ -82,52 +80,23 @@ export const createJestExtContext = (
8280
};
8381
};
8482

85-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
86-
const isTestExplorerConfigLegacy = (arg: any): arg is TestExplorerConfigLegacy =>
87-
typeof arg.enabled === 'boolean';
88-
89-
const DefaultTestExplorerSetting: TestExplorerConfig = {};
90-
const adaptTestExplorer = (
91-
setting?: TestExplorerConfig | TestExplorerConfigLegacy
92-
): TestExplorerConfig => {
93-
if (!setting) {
94-
return DefaultTestExplorerSetting;
95-
}
96-
97-
if (isTestExplorerConfigLegacy(setting)) {
98-
if (setting.enabled === false || setting.showClassicStatus === true) {
99-
const message = `Invalid TestExplorer setting: please check README to upgrade. Will use the default setting instead`;
100-
console.error(message);
101-
vscode.window.showWarningMessage(message);
102-
return DefaultTestExplorerSetting;
103-
}
104-
return { showInlineError: setting.showInlineError };
105-
}
106-
107-
return setting;
108-
};
109-
11083
export const getExtensionResourceSettings = (
11184
workspaceFolder: vscode.WorkspaceFolder
11285
): PluginResourceSettings => {
11386
const getSetting = createJestSettingGetter(workspaceFolder);
11487

11588
const deprecatedSettings: DeprecatedPluginResourceSettings = {
11689
showCoverageOnLoad: getSetting<boolean>('showCoverageOnLoad') ?? false,
117-
autoRevealOutput: getSetting<AutoRevealOutputType>('autoRevealOutput') ?? 'on-run',
11890
autoRun: getSetting<JestExtAutoRunSetting | null>('autoRun'),
91+
testExplorer: getSetting<TestExplorerConfig>('testExplorer'),
11992
};
12093

12194
return {
12295
jestCommandLine: getSetting<string>('jestCommandLine'),
123-
autoClearTerminal: getSetting<boolean>('autoClearTerminal') ?? false,
12496
rootPath: toAbsoluteRootPath(workspaceFolder, getSetting<string>('rootPath')),
12597
coverageFormatter: getSetting<string>('coverageFormatter') ?? 'DefaultFormatter',
12698
debugMode: getSetting<boolean>('debugMode'),
12799
coverageColors: getSetting<CoverageColors>('coverageColors'),
128-
testExplorer: adaptTestExplorer(
129-
getSetting<TestExplorerConfig | TestExplorerConfigLegacy>('testExplorer')
130-
),
131100
nodeEnv: getSetting<NodeEnv | null>('nodeEnv') ?? undefined,
132101
shell: new RunShell(getSetting<string | LoginShell>('shell')),
133102
monitorLongRun: getSetting<MonitorLongRun>('monitorLongRun') ?? undefined,

src/JestExt/output-terminal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import { ExtErrorDef } from '../errors';
3+
import { outputManager } from '../output-manager';
34

45
/**
56
* This class write out Jest run output to vscode.Terminal
@@ -118,7 +119,7 @@ export class ExtOutputTerminal implements JestExtOutput {
118119
this.appendRaw(text);
119120

120121
if (isErrorOutputType(opt) && (this.enabled || this.revealOnError)) {
121-
this.show();
122+
outputManager.showOutputOn('exec-error', this);
122123
}
123124
return text;
124125
}

0 commit comments

Comments
 (0)