Skip to content

Commit

Permalink
Merge cd3b6cf into f380f7f
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz committed May 1, 2022
2 parents f380f7f + cd3b6cf commit fdc92b3
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 12 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

---
## Release Notes<!-- omit in toc -->
### Latest: [v4.4.0](https://github.com/jest-community/vscode-jest/releases/tag/v4.4.0) <!-- omit in toc -->
### Pre-Release: [v4.5.0](https://github.com/jest-community/vscode-jest/releases/tag/v4.5.0) <!-- omit in toc -->

<details>

<summary>features</summary>

- adding a new setting `jest.showTerminalOnLaunch` to control if test explorer terminal should be automatically opened upon launch. Default is true.

</details>

### Stable: [v4.4.0](https://github.com/jest-community/vscode-jest/releases/tag/v4.4.0) <!-- omit in toc -->

Interactive run has been extended to watch mode in v4.4.0. Users in watch mode can now run any test/folder/workspace interactively just like with non-watch mode.

Expand Down Expand Up @@ -357,6 +367,7 @@ Users can use the following settings to tailor the extension for their environme
|**Misc**|
|debugMode|Enable debug mode to diagnose plugin issues. (see developer console)|false|`"jest.debugMode": true`|
|disabledWorkspaceFolders 💼|Disabled workspace folders names in multiroot environment|[]|`"jest.disabledWorkspaceFolders": ["package-a", "package-b"]`|
|showTerminalOnLaunch 💼|automatically open test explorer terminal on launch (>= v4.5)|true|`"jest.showTerminalOnLaunch": false`|

#### Details
##### jestCommandLine
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
"type": "object",
"title": "Jest",
"properties": {
"jest.showTerminalOnLaunch": {
"description": "Automatically open test explorer's terminal upon launch",
"type": "boolean",
"default": true,
"scope": "window"
},
"jest.autoEnable": {
"description": "Automatically start Jest for this project",
"type": "boolean",
Expand Down
1 change: 1 addition & 0 deletions src/JestExt/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const createJestExtContext = (
export const getExtensionResourceSettings = (uri: vscode.Uri): PluginResourceSettings => {
const config = vscode.workspace.getConfiguration('jest', uri);
return {
showTerminalOnLaunch: config.get<boolean>('showTerminalOnLaunch') ?? true,
autoEnable: config.get<boolean>('autoEnable'),
enableSnapshotUpdateMessages: config.get<boolean>('enableSnapshotUpdateMessages'),
pathToConfig: config.get<string>('pathToConfig'),
Expand Down
1 change: 1 addition & 0 deletions src/Settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type TestExplorerConfig =
| { enabled: true; showClassicStatus?: boolean; showInlineError?: boolean };
export type NodeEnv = ProjectWorkspace['nodeEnv'];
export interface PluginResourceSettings {
showTerminalOnLaunch?: boolean;
autoEnable?: boolean;
enableSnapshotUpdateMessages?: boolean;
jestCommandLine?: string;
Expand Down
25 changes: 15 additions & 10 deletions src/test-provider/test-provider-context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as vscode from 'vscode';
import { JestExtExplorerContext, TestItemData } from './types';

let showTerminal = true;
export const _resetShowTerminal = (): void => {
showTerminal = true;
};

/**
* provide context information from JestExt and test provider state:
* 1. TestData <-> TestItem
Expand All @@ -17,6 +22,7 @@ const COLORS = {
['end']: '\x1b[0m',
};
export type TagIdType = 'run' | 'debug';

export class JestTestProviderContext {
private testItemData: WeakMap<vscode.TestItem, TestItemData>;

Expand Down Expand Up @@ -88,19 +94,18 @@ export class JestTestProviderContext {
text = `${COLORS[color]}${text}${COLORS['end']}`;
}
run.appendOutput(`${text}${newLine ? '\r\n' : ''}`);
showTestExplorerTerminal();
this.showTestExplorerTerminal();
};

/** show TestExplorer Terminal on first invocation only */
showTestExplorerTerminal = (): void => {
if (showTerminal && this.ext.settings.showTerminalOnLaunch !== false) {
showTerminal = false;
vscode.commands.executeCommand('testing.showMostRecentOutput');
}
};

// tags
getTag = (tagId: TagIdType): vscode.TestTag | undefined =>
this.profiles.find((p) => p.tag?.id === tagId)?.tag;
}

/** show TestExplorer Terminal on first invocation only */
let showTerminal = true;
const showTestExplorerTerminal = () => {
if (showTerminal) {
showTerminal = false;
vscode.commands.executeCommand('testing.showMostRecentOutput');
}
};
1 change: 1 addition & 0 deletions tests/JestExt/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ describe('getExtensionResourceSettings()', () => {
coverageColors: null,
autoRun: null,
testExplorer: { enabled: true },
showTerminalOnLaunch: true,
});
});
it('can read user settings', () => {
Expand Down
25 changes: 24 additions & 1 deletion tests/test-provider/test-item-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import {
WorkspaceRoot,
} from '../../src/test-provider/test-item-data';
import * as helper from '../test-helper';
import { JestTestProviderContext } from '../../src/test-provider/test-provider-context';
import {
JestTestProviderContext,
_resetShowTerminal,
} from '../../src/test-provider/test-provider-context';
import {
buildAssertionContainer,
buildSourceContainer,
Expand Down Expand Up @@ -82,6 +85,8 @@ describe('test-item-data', () => {
.fn()
.mockImplementation((uri, p) => ({ fsPath: `${uri.fsPath}/${p}` }));
vscode.Uri.file = jest.fn().mockImplementation((f) => ({ fsPath: f }));

_resetShowTerminal();
});
describe('show TestExplorer Terminal', () => {
it('show TestExplorer Terminal on first run output only', () => {
Expand All @@ -92,6 +97,24 @@ describe('test-item-data', () => {
context.appendOutput('subsequent calls will not open terminal again', runMock);
expect(vscode.commands.executeCommand).toBeCalledTimes(1);
});
it.each`
showTerminalOnLaunch | callTimes
${undefined} | ${1}
${true} | ${1}
${false} | ${0}
`(
'controlled by showTerminalOnLaunch($showTerminalOnLaunch) => callTimes($callTimes)',
({ showTerminalOnLaunch, callTimes }) => {
context.ext.settings.showTerminalOnLaunch = showTerminalOnLaunch;
(vscode.commands.executeCommand as jest.Mocked<any>).mockClear();

context.appendOutput('first time should open terminal', runMock);
expect(vscode.commands.executeCommand).toBeCalledTimes(callTimes);

context.appendOutput('subsequent calls will not open terminal again', runMock);
expect(vscode.commands.executeCommand).toBeCalledTimes(callTimes);
}
);
});
describe('discover children', () => {
describe('WorkspaceRoot', () => {
Expand Down

0 comments on commit fdc92b3

Please sign in to comment.