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

supports test-results panel and refactor output settings #1087

Merged
merged 13 commits into from
Nov 2, 2023
Prev Previous commit
Next Next commit
adding predefined outputConfig enum types
  • Loading branch information
connectdotz committed Oct 24, 2023
commit 8090c0659da37c3e1711ed545e3bf2c5a2669b40
123 changes: 73 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
"description": "Clear the terminal output at the start of any new test run.",
"type": "boolean",
"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.rootPath": {
"description": "The path to your frontend src folder",
Expand Down Expand Up @@ -186,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 @@ -213,59 +213,82 @@
}
},
"jest.outputConfig": {
"type": "object",
"default": null,
"scope": "window",
"markdownDescription": "Control jest output preference. See details in [output](https://github.com/jest-community/vscode-jest#output)",
"properties": {
"revalOn": {
"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",
"object"
],
"markdownDescription": "Control jest output preference. See details in [outputConfig](https://github.com/jest-community/vscode-jest#outputconfig).",
"default": null,
"oneOf": [
{
"type": "string",
"enum": [
"none",
"terminal",
"test-results"
"neutral",
"terminal-based",
"test-results-based"
],
"enumDescriptions": [
"Do not change focus when revealing output.",
"Reveal terminal with focus.",
"Reveal test results panel with focus."
"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."
],
"default": "none",
"description": "Specifies which output panel, if any, to shift focus to when revealing. Default is 'none'."
"description": "Specifies the predefined common outputConfig in a string form."
},
"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'."
{
"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 the complete 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)",
Expand Down
6 changes: 4 additions & 2 deletions src/Settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ export type JestRunModeType = JestRunMode['type'];
export type JestPredefinedRunModeType = JestRunModeType | 'deferred';
export type JestRunModeSetting = JestRunMode | JestPredefinedRunModeType;

export interface JestOutputSetting {
export interface JestRawOutputSetting {
revealWithFocus?: 'terminal' | 'test-results' | 'none';
revalOn?: 'run' | 'error' | 'demand';
revealOn?: 'run' | 'error' | 'demand';
clearOnRun?: 'both' | 'terminal' | 'test-results' | 'none';
}
export type JestPredefinedOutputSetting = 'neutral' | 'terminal-based' | 'test-results-based';
export type JestOutputSetting = JestPredefinedOutputSetting | JestRawOutputSetting;

export type TestExplorerConfigLegacy =
| { enabled: false }
Expand Down
56 changes: 43 additions & 13 deletions src/output-manager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as vscode from 'vscode';
import { AutoRevealOutputType, JestOutputSetting } from './Settings/types';
import { AutoRevealOutputType, JestOutputSetting, JestRawOutputSetting } from './Settings/types';
import { ExtOutputTerminal } from './JestExt/output-terminal';

type OutputConfig = Required<JestOutputSetting>;
type OutputConfig = Required<JestRawOutputSetting>;
const DefaultJestOutputSetting: OutputConfig = {
revalOn: 'run',
revealOn: 'run',
revealWithFocus: 'none',
clearOnRun: 'none',
};
Expand All @@ -20,11 +20,40 @@ export class OutputManager {

private getConfig(): OutputConfig {
const config = vscode.workspace.getConfiguration('jest').get<JestOutputSetting>('outputConfig');
return { ...DefaultJestOutputSetting, ...(config ?? this.fromLegacySettings()) };
return config
? this.resolveSetting(config)
: { ...DefaultJestOutputSetting, ...this.fromLegacySettings() };
}

public get revealOn(): JestOutputSetting['revalOn'] {
return this.config.revalOn;
private resolveSetting(setting: JestOutputSetting): OutputConfig {
if (typeof setting === 'string') {
switch (setting) {
case 'neutral':
return DefaultJestOutputSetting;
case 'terminal-based':
return {
revealOn: 'run',
revealWithFocus: 'terminal',
clearOnRun: 'none',
};
case 'test-results-based':
return {
revealOn: 'run',
revealWithFocus: 'test-results',
clearOnRun: 'none',
};
}
throw new Error(`Unknown predefined output setting: ${setting}`);
}

return { ...DefaultJestOutputSetting, ...setting };
}

// private asPredefinedSetting(): JestPredefinedOutputSetting | undefined {
// }

public get revealOn(): JestRawOutputSetting['revealOn'] {
return this.config.revealOn;
}

public showOutputOn(
Expand All @@ -34,17 +63,17 @@ export class OutputManager {
// will not reveal output for the following cases:
switch (type) {
case 'run':
if (this.config.revalOn !== 'run') {
if (this.config.revealOn !== 'run') {
return;
}
break;
case 'test-error':
if (this.config.revalOn !== 'error') {
if (this.config.revealOn !== 'error') {
return;
}
break;
case 'exec-error':
if (this.config.revalOn === 'demand') {
if (this.config.revealOn === 'demand') {
return;
}
break;
Expand Down Expand Up @@ -171,6 +200,7 @@ export class OutputManager {
switch (item) {
case items.fixTestResults:
await this.updateTestResultsSettings();
await this.save();
return true;
case items.fixOutputConfig:
this.config.revealWithFocus = 'test-results';
Expand All @@ -196,20 +226,20 @@ export class OutputManager {
}
}

private fromLegacySettings(scope?: vscode.ConfigurationScope): JestOutputSetting {
private fromLegacySettings(scope?: vscode.ConfigurationScope): JestRawOutputSetting {
const vscodeConfig = vscode.workspace.getConfiguration('jest', scope);
const autoClearTerminal = vscodeConfig.get<boolean>('autoClearTerminal');
const autoRevealOutput = vscodeConfig.get<AutoRevealOutputType>('autoRevealOutput');

const config = {} as JestOutputSetting;
const config = {} as JestRawOutputSetting;
switch (autoRevealOutput) {
case undefined:
case 'on-run':
case 'on-exec-error':
config.revalOn = 'run';
config.revealOn = 'run';
break;
case 'off':
config.revalOn = 'demand';
config.revealOn = 'demand';
break;
}
config.clearOnRun = autoClearTerminal ? 'terminal' : 'none';
Expand Down
Loading