Skip to content

Commit

Permalink
supports test-results panel and refactor output settings (#1087)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
connectdotz committed Nov 2, 2023
1 parent 1f33012 commit 15b61f5
Show file tree
Hide file tree
Showing 45 changed files with 3,796 additions and 2,566 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
"cSpell.words": [
"unmock"
],
"testing.openTesting": "neverOpen",
"jest.outputConfig": {
"clearOnRun": "terminal"
}
}
154 changes: 135 additions & 19 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
'debug',
'@babel/template',
'graceful-fs',
'@babel/core',
'@babel/types',
],
moduleNameMapper: {
'\\.(svg)$': '<rootDir>/tests/fileMock.ts',
Expand Down
115 changes: 98 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-jest",
"displayName": "Jest",
"description": "Use Facebook's Jest With Pleasure.",
"version": "6.0.2",
"version": "6.1.0",
"publisher": "Orta",
"engines": {
"vscode": "^1.68.1"
Expand Down Expand Up @@ -81,7 +81,9 @@
"jest.autoClearTerminal": {
"description": "Clear the terminal output at the start of any new test run.",
"type": "boolean",
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: Please use [outputConfig](https://github.com/jest-community/vscode-jest#outputconfig) instead.",
"deprecationMessage": "Deprecated: Please use jest.outputConfig instead."
},
"jest.rootPath": {
"description": "The path to your frontend src folder",
Expand Down Expand Up @@ -156,7 +158,9 @@
"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",
"type": "object",
"default": null,
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: Please use [runMode](https://github.com/jest-community/vscode-jest/blob/master/README.md#runmode) instead.",
"deprecationMessage": "Deprecated: Please use jest.runMode instead."
},
"jest.monitorLongRun": {
"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",
Expand All @@ -182,11 +186,11 @@
"disable auto show test output"
],
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: Please use [runMode](https://github.com/jest-community/vscode-jest/blob/master/README.md#runmode) instead.",
"deprecationMessage": "Deprecated: Please use jest.runMode instead."
"markdownDeprecationMessage": "**Deprecated**: Please use [outputConfig](https://github.com/jest-community/vscode-jest#outputconfig) instead.",
"deprecationMessage": "Deprecated: Please use jest.outputConfig instead."
},
"jest.parserPluginOptions": {
"markdownDescription": "Configure babel parser plugins. See valid [format](https://github.com/jest-community/vscode-jest/blob/master/README.md#parserpluginoptions)",
"markdownDescription": "Configure babel parser plugins. See valid [format](https://github.com/jest-community/vscode-jest#parserpluginoptions)",
"type": "object",
"default": null,
"scope": "resource"
Expand All @@ -208,6 +212,84 @@
"type": "object"
}
},
"jest.outputConfig": {
"scope": "window",
"type": [
"string",
"object"
],
"markdownDescription": "Control jest output preference. See details in [outputConfig](https://github.com/jest-community/vscode-jest#outputconfig).",
"default": null,
"oneOf": [
{
"type": "string",
"enum": [
"neutral",
"terminal-based",
"test-results-based"
],
"enumDescriptions": [
"A passive and neutral config, will not automatically change active panel nor clear output.",
"Switch to terminal panel when running tests.",
"Switch to test-results panel when running tests."
],
"description": "Specifies the predefined common outputConfig in a string form."
},
{
"type": "object",
"properties": {
"revealOn": {
"type": "string",
"enum": [
"run",
"error",
"demand"
],
"enumDescriptions": [
"Reveal the output upon test run.",
"Reveal the output upon test error.",
"Reveal the output on demand."
],
"default": "run",
"description": "Determines when to reveal the test run output. Default is 'run'."
},
"revealWithFocus": {
"type": "string",
"enum": [
"none",
"terminal",
"test-results"
],
"enumDescriptions": [
"Do not change focus when revealing output.",
"Switch to terminal when revealing output.",
"Switch to test-results panel when revealing output."
],
"default": "none",
"description": "Specifies which output panel, if any, to switch focus to when revealing. Default is 'none'."
},
"clearOnRun": {
"type": "string",
"enum": [
"none",
"both",
"terminal",
"test-results"
],
"enumDescriptions": [
"Do not automatically clear the output before each run.",
"Clear both the terminal and test results output before each run.",
"Clear the terminal output before each run.",
"Clear the test results output before each run."
],
"default": "none",
"description": "Specifies which output, if any, to be cleared before each run. Default is 'none'."
}
},
"description": "Specifies a custom output config in an object form."
}
]
},
"jest.runMode": {
"markdownDescription": "Control when to run jest tests and present the results. See details in [runMode](https://github.com/jest-community/vscode-jest#runmode)",
"default": null,
Expand Down Expand Up @@ -243,14 +325,9 @@
"type": "boolean",
"description": "Specifies whether to collect and report coverage information."
},
"revealOutput": {
"type": "string",
"enum": [
"on-run",
"on-exec-error",
"on-demand"
],
"description": "Determines when to reveal the test run output."
"showInlineError": {
"type": "boolean",
"description": "Specify if to enable inline error display in test file editor"
},
"deferred": {
"type": "boolean",
Expand Down Expand Up @@ -325,6 +402,10 @@
"command": "io.orta.jest.workspace.save-run-mode",
"title": "Jest: Save Current RunMode"
},
{
"command": "io.orta.jest.save-output-config",
"title": "Jest: Save Current Output Config"
},
{
"command": "io.orta.jest.run-all-tests",
"title": "Jest: Run All Tests"
Expand Down Expand Up @@ -582,13 +663,13 @@
"dependencies": {
"istanbul-lib-coverage": "^3.2.0",
"istanbul-lib-source-maps": "^4.0.1",
"jest-editor-support": "^31.1.1"
"jest-editor-support": "^31.1.2"
},
"devDependencies": {
"@types/fs-extra": "^11.0.2",
"@types/istanbul-lib-coverage": "^2.0.4",
"@types/istanbul-lib-source-maps": "^4.0.1",
"@types/jest": "^29.2.5",
"@types/jest": "^29.5.6",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.48.1",
Expand All @@ -600,7 +681,7 @@
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^4.2.1",
"fs-extra": "^11.1.1",
"jest": "^29.3.1",
"jest": "^29.7",
"jest-snapshot": "^27.2.0",
"prettier": "^2.8.2",
"raw-loader": "^4.0.1",
Expand Down
39 changes: 18 additions & 21 deletions src/JestExt/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { WorkspaceManager, isInFolder } from '../workspace-manager';
import { ansiEsc, JestOutputTerminal } from './output-terminal';
import { QuickFixActionType } from '../quick-fix';
import { executableTerminalLinkProvider } from '../terminal-link-provider';
import { outputManager } from '../output-manager';

interface RunTestPickItem extends vscode.QuickPickItem {
id: DebugTestIdentifier;
Expand Down Expand Up @@ -195,12 +196,7 @@ export class JestExt {
}

private enableOutputOnRun(): void {
if (
!this.extContext.settings.runMode.config.revealOutput ||
this.extContext.settings.runMode.config.revealOutput === 'on-run'
) {
this.output.enable();
}
outputManager.showOutputOn('run', this.output);
}
private setupRunEvents(events: JestSessionEvents): void {
events.onRunEvent.event((event: JestRunEvent) => {
Expand All @@ -223,14 +219,14 @@ export class JestExt {
case 'exit':
if (event.error) {
this.updateStatusBar({ state: 'exec-error' });
if (!event.process.userData?.errorReported) {
if (!event.process.userData?.execError) {
this.outputActionMessages(
`Jest process exited unexpectedly: ${event.error}`,
['wizard', 'defer', 'disable-folder', 'help'],
true,
event.error
);
event.process.userData = { ...(event.process.userData ?? {}), errorReported: true };
event.process.userData = { ...(event.process.userData ?? {}), execError: true };
}
} else {
this.updateStatusBar({ state: 'done' });
Expand All @@ -242,6 +238,13 @@ export class JestExt {
}
break;
}
case 'test-error': {
if (!event.process.userData?.testError) {
outputManager.showOutputOn('test-error', this.output);
event.process.userData = { ...(event.process.userData ?? {}), testError: true };
}
break;
}
case 'long-run': {
this.outputActionMessages(this.longRunMessage(event), ['help-long-run'], false);
break;
Expand Down Expand Up @@ -298,10 +301,6 @@ export class JestExt {
});
return;
}
const readyState = await this.validateJestCommandLine();
if (readyState !== 'pass') {
return;
}

this.dirtyFiles.clear();
this.resetStatusBar();
Expand All @@ -315,6 +314,11 @@ export class JestExt {
this.testProvider?.dispose();
this.testProvider = new JestTestProvider(this.getExtExplorerContext());

const readyState = await this.validateJestCommandLine();
if (readyState !== 'pass') {
return;
}

await this.processSession.start();

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

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

// output
if (
this.extContext.settings.runMode.config.revealOutput !==
updatedSettings.runMode.config.revealOutput ||
this.extContext.settings.runMode.config.deferred !== updatedSettings.runMode.config.deferred
) {
this.updateOutputSetting(updatedSettings);
}
this.updateOutputSetting(updatedSettings);

// TestResultProvider
this.testResultProvider.options = this.testResultProviderOptions(updatedSettings);
Expand Down
33 changes: 1 addition & 32 deletions src/JestExt/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import {
TestExplorerConfig,
NodeEnv,
MonitorLongRun,
TestExplorerConfigLegacy,
JestExtAutoRunSetting,
AutoRevealOutputType,
createJestSettingGetter,
JestRunModeType,
JestRunMode,
Expand Down Expand Up @@ -82,52 +80,23 @@ export const createJestExtContext = (
};
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isTestExplorerConfigLegacy = (arg: any): arg is TestExplorerConfigLegacy =>
typeof arg.enabled === 'boolean';

const DefaultTestExplorerSetting: TestExplorerConfig = {};
const adaptTestExplorer = (
setting?: TestExplorerConfig | TestExplorerConfigLegacy
): TestExplorerConfig => {
if (!setting) {
return DefaultTestExplorerSetting;
}

if (isTestExplorerConfigLegacy(setting)) {
if (setting.enabled === false || setting.showClassicStatus === true) {
const message = `Invalid TestExplorer setting: please check README to upgrade. Will use the default setting instead`;
console.error(message);
vscode.window.showWarningMessage(message);
return DefaultTestExplorerSetting;
}
return { showInlineError: setting.showInlineError };
}

return setting;
};

export const getExtensionResourceSettings = (
workspaceFolder: vscode.WorkspaceFolder
): PluginResourceSettings => {
const getSetting = createJestSettingGetter(workspaceFolder);

const deprecatedSettings: DeprecatedPluginResourceSettings = {
showCoverageOnLoad: getSetting<boolean>('showCoverageOnLoad') ?? false,
autoRevealOutput: getSetting<AutoRevealOutputType>('autoRevealOutput') ?? 'on-run',
autoRun: getSetting<JestExtAutoRunSetting | null>('autoRun'),
testExplorer: getSetting<TestExplorerConfig>('testExplorer'),
};

return {
jestCommandLine: getSetting<string>('jestCommandLine'),
autoClearTerminal: getSetting<boolean>('autoClearTerminal') ?? false,
rootPath: toAbsoluteRootPath(workspaceFolder, getSetting<string>('rootPath')),
coverageFormatter: getSetting<string>('coverageFormatter') ?? 'DefaultFormatter',
debugMode: getSetting<boolean>('debugMode'),
coverageColors: getSetting<CoverageColors>('coverageColors'),
testExplorer: adaptTestExplorer(
getSetting<TestExplorerConfig | TestExplorerConfigLegacy>('testExplorer')
),
nodeEnv: getSetting<NodeEnv | null>('nodeEnv') ?? undefined,
shell: new RunShell(getSetting<string | LoginShell>('shell')),
monitorLongRun: getSetting<MonitorLongRun>('monitorLongRun') ?? undefined,
Expand Down
3 changes: 2 additions & 1 deletion src/JestExt/output-terminal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { ExtErrorDef } from '../errors';
import { outputManager } from '../output-manager';

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

if (isErrorOutputType(opt) && (this.enabled || this.revealOnError)) {
this.show();
outputManager.showOutputOn('exec-error', this);
}
return text;
}
Expand Down

0 comments on commit 15b61f5

Please sign in to comment.