Skip to content

Commit

Permalink
introduce interactive mode and new process model (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz committed Apr 3, 2021
1 parent c175f0d commit d50d127
Show file tree
Hide file tree
Showing 63 changed files with 6,075 additions and 3,913 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ Please add your own contribution below inside the Master section
Bug-fixes within the same version aren't needed
## Master
* Introducing a new interactive mode, in addition to the current "watch" mode, to run jest tests. Use the new `jest.autoRun` settings to control when and what tests should be run automatically, or not. - @connectdotz (#674)
* refactor jest process management to adopt queue-based model with promise-based process execution. - @connectdotz (#674)
* enhance statusBar to display autoRun and workspace stats - @connectdotz (#674)
* added new commands, context menu, keybinding to better support interactive mode. - @connectdotz (#674)
* added ability to update snapshot without restarting jest. - @connectdotz (#674)
* added ability to get jest metadata such as all test files. - @connectdotz (#674)
* change editor decorators to reflect when tests are changed but tests have not been run (which might be common in the new interactive mode) - @connectdotz (#674)
-->

### 4.0.0-alpha.4
Expand Down
414 changes: 317 additions & 97 deletions README.md

Large diffs are not rendered by default.

30 changes: 17 additions & 13 deletions __mocks__/vscode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const languages = {
createDiagnosticCollection: jest.fn(),
registerCodeLensProvider: jest.fn(),
}
};

const StatusBarAlignment = { Left: 1, Right: 2 }
const StatusBarAlignment = { Left: 1, Right: 2 };

const window = {
createStatusBarItem: jest.fn(() => ({
Expand All @@ -17,7 +17,7 @@ const window = {
showWorkspaceFolderPick: jest.fn(),
onDidChangeActiveTextEditor: jest.fn(),
showInformationMessage: jest.fn(),
}
};

const workspace = {
getConfiguration: jest.fn(),
Expand All @@ -27,32 +27,36 @@ const workspace = {
onDidChangeConfiguration: jest.fn(),
onDidChangeTextDocument: jest.fn(),
onDidChangeWorkspaceFolders: jest.fn(),
}
onDidCreateFiles: jest.fn(),
onDidDeleteFiles: jest.fn(),
onDidRenameFiles: jest.fn(),
};

const OverviewRulerLane = {
Left: null,
}
};

const Uri = {
file: (f) => f,
parse: jest.fn(),
}
const Range = jest.fn()
const Diagnostic = jest.fn()
const DiagnosticSeverity = { Error: 0, Warning: 1, Information: 2, Hint: 3 }
};
const Range = jest.fn();
const Diagnostic = jest.fn();
const DiagnosticSeverity = { Error: 0, Warning: 1, Information: 2, Hint: 3 };

const debug = {
onDidTerminateDebugSession: jest.fn(),
startDebugging: jest.fn(),
registerDebugConfigurationProvider: jest.fn(),
}
};

const commands = {
executeCommand: jest.fn(),
registerCommand: jest.fn(),
}
registerTextEditorCommand: jest.fn(),
};

const CodeLens = function CodeLens() {}
const CodeLens = function CodeLens() {};

export {
CodeLens,
Expand All @@ -67,4 +71,4 @@ export {
DiagnosticSeverity,
debug,
commands,
}
};
Binary file added images/coverage-screen-shot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/debug-screen-shot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/status-bar-manual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/status-bar-modes.png
Binary file not shown.
Binary file added images/status-bar-save-all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/status-bar-save-test-unsync.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/status-bar-save-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/status-bar-watch-coverage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/status-bar-watch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 108 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"description": "Automatically start Jest for this project",
"type": "boolean",
"default": true,
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: please use `#jest.autoRun#` instead."
},
"jest.jestCommandLine": {
"description": "The command line to start jest tests. It should be the same command line users run jest tests from a terminal/shell, with ability to append extra arguments (by the extension at runtime)",
Expand All @@ -80,13 +81,15 @@
"description": "(deprecated) The path to the Jest binary, or an npm command to run tests suffixed with `--` e.g. `node_modules/.bin/jest` or `npm test --`",
"type": "string",
"default": null,
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: please use `#jest.jestCommandLine#` instead."
},
"jest.pathToConfig": {
"description": "(deprecated) The path to your Jest configuration file",
"type": "string",
"default": "",
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: please use `#jest.jestCommandLine#` instead."
},
"jest.rootPath": {
"description": "The path to your frontend src folder",
Expand All @@ -98,7 +101,8 @@
"description": "Whether errors should be reported inline on a file",
"type": "boolean",
"default": false,
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: in favor of vscode hovering message"
},
"jest.enableSnapshotUpdateMessages": {
"description": "Whether snapshot update messages should show",
Expand All @@ -110,7 +114,8 @@
"description": "Run all tests before starting Jest in watch mode",
"type": "boolean",
"default": true,
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: in favor of `#jest.autoRun#`"
},
"jest.showCoverageOnLoad": {
"description": "Show code coverage when extension starts (if collected)",
Expand All @@ -129,8 +134,9 @@
"scope": "resource"
},
"jest.coverageColors": {
"description": "Coverage indicator color override",
"markdownDescription": "Coverage indicator color override. See [Coverage Colors](https://github.com/jest-community/vscode-jest/blob/master/README.md#coverageColors) for details and examples",
"type": "object",
"default": null,
"scope": "resource"
},
"jest.enableCodeLens": {
Expand Down Expand Up @@ -166,7 +172,8 @@
"description": "Restart Jest runner after updating the snapshots",
"type": "boolean",
"default": false,
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: no need to restart jest after snapshot update"
},
"jest.debugMode": {
"description": "Enable debug mode to diagnose plugin issues. (see developer console)",
Expand All @@ -180,29 +187,110 @@
"items": "string",
"default": [],
"scope": "window"
},
"jest.autoRun": {
"markdownDescription": "Control when jest should run (changed) tests. It supports multiple models, such as fully automated, fully manual and onSave... See [AutoRun](https://github.com/jest-community/vscode-jest/blob/master/README.md#how-to-trigger-the-test-run) for details and examples",
"type": "object",
"default": null,
"scope": "resource"
}
}
},
"commands": [
{
"command": "io.orta.jest.start",
"title": "Jest: Start Runner"
"title": "Jest: Start All Runners"
},
{
"command": "io.orta.jest.stop",
"title": "Jest: Stop Runner"
"title": "Jest: Stop All Runners"
},
{
"command": "io.orta.jest.toggle-coverage",
"title": "Jest: Toggle Coverage"
},
{
"command": "io.orta.jest.workspace.start",
"title": "Jest: Start Runner (Select Workspace)"
},
{
"command": "io.orta.jest.workspace.stop",
"title": "Jest: Stop Runner (Select Workspace)"
},
{
"command": "io.orta.jest.workspace.toggle-coverage",
"title": "Jest: Toggle Coverage (Select Workspace)"
},
{
"command": "io.orta.jest.workspace.run-all-tests",
"title": "Jest: Run All Tests (Select Workspace)"
},
{
"command": "io.orta.jest.run-all-tests",
"title": "Jest: Run All Tests"
},
{
"command": "io.orta.jest.restart",
"title": "Jest: Restart Runner"
"command": "io.orta.jest.editor.workspace.run-all-tests",
"title": "Jest: Run All Tests in Current Workspace"
},
{
"command": "io.orta.jest.show-channel",
"title": "Jest: Show Test Output Channel"
"command": "io.orta.jest.editor.run-all-tests",
"title": "Jest: Run Related Tests"
},
{
"command": "io.orta.jest.coverage.toggle",
"title": "Jest: Toggle Coverage Overlay"
"command": "io.orta.jest.editor.workspace.toggle-coverage",
"title": "Jest: Toggle Coverage for Current Workspace"
}
],
"menus": {
"commandPalette": [
{
"command": "io.orta.jest.workspace.start",
"when": "workspaceFolderCount > 1"
},
{
"command": "io.orta.jest.workspace.stop",
"when": "workspaceFolderCount > 1"
},
{
"command": "io.orta.jest.workspace.toggle-coverage",
"when": "workspaceFolderCount > 1"
},
{
"command": "io.orta.jest.editor.workspace.toggle-coverage",
"when": "workspaceFolderCount > 1"
},
{
"command": "io.orta.jest.workspace.run-all-tests",
"when": "jest:run.interactive && workspaceFolderCount > 1"
},
{
"command": "io.orta.jest.run-all-tests",
"when": "jest:run.interactive"
},
{
"command": "io.orta.jest.editor.workspace.run-all-tests",
"when": "jest:run.interactive && workspaceFolderCount > 1"
},
{
"command": "io.orta.jest.editor.run-all-tests",
"when": "jest:never"
}
],
"editor/context": [
{
"when": "jest:run.interactive && editorLangId =~ /(javascript|javascriptreact|typescript|typescriptreact)/ ",
"command": "io.orta.jest.editor.run-all-tests",
"group": "Jest"
}
]
},
"keybindings": [
{
"command": "io.orta.jest.editor.run-all-tests",
"key": "ctrl+t",
"mac": "cmd+t",
"when": "jest:run.interactive && editorLangId =~ /(javascript|javascriptreact|typescript|typescriptreact)/ "
}
],
"debuggers": [
Expand Down Expand Up @@ -287,12 +375,13 @@
"watch": "webpack --mode development --watch --info-verbosity verbose",
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" \"*.json\" \"*.js\" ",
"test": "jest",
"watch-test": "yarn test -- --watch"
"watch-test": "yarn test -- --watch",
"tsc": "tsc --noEmit"
},
"dependencies": {
"istanbul-lib-coverage": "^3.0.0",
"istanbul-lib-source-maps": "^4.0.0",
"jest-editor-support": "^28.1.0",
"jest-editor-support": "^28.2.0",
"jest-snapshot": "^25.5.0",
"vscode-codicons": "^0.0.4"
},
Expand All @@ -318,9 +407,9 @@
"prettier": "^2.2.1",
"raw-loader": "^4.0.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.4.4",
"ts-jest": "^26.5.2",
"ts-loader": "^7.0.1",
"typescript": "^4.1.2",
"typescript": "^4.2.2",
"vscode-test": "^1.3.0",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
Expand Down
3 changes: 0 additions & 3 deletions src/DebugCodeLens/DebugCodeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { TestIdentifier } from '../TestResults';

export type DebugTestIdentifier = string | TestIdentifier;
export class DebugCodeLens extends vscode.CodeLens {
readonly fileName: string;
readonly testIds: DebugTestIdentifier[];
readonly document: vscode.TextDocument;

Expand All @@ -19,12 +18,10 @@ export class DebugCodeLens extends vscode.CodeLens {
constructor(
document: vscode.TextDocument,
range: vscode.Range,
fileName: string,
...testIds: DebugTestIdentifier[]
) {
super(range);
this.document = document;
this.fileName = fileName;
this.testIds = testIds;
}
}
17 changes: 11 additions & 6 deletions src/DebugCodeLens/DebugCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as vscode from 'vscode';
import { extensionName } from '../appGlobals';
import { basename } from 'path';
import { DebugCodeLens } from './DebugCodeLens';
import { TestReconciliationStateType } from '../TestResults';
import { TestState, TestStateByTestReconciliationState } from './TestState';
Expand Down Expand Up @@ -31,6 +30,10 @@ export class DebugCodeLensProvider implements vscode.CodeLensProvider {
}

provideCodeLenses(document: vscode.TextDocument, _: vscode.CancellationToken): DebugCodeLens[] {
if (document.isDirty) {
return [];
}

const result: DebugCodeLens[] = [];
const ext = this.getJestExt(document.uri);
if (!ext || this._showWhenTestStateIn.length === 0 || document.isUntitled) {
Expand All @@ -39,7 +42,9 @@ export class DebugCodeLensProvider implements vscode.CodeLensProvider {

const filePath = document.fileName;
const testResults = ext.testResultProvider.getResults(filePath);
const fileName = basename(document.fileName);
if (!testResults) {
return result;
}

for (const test of testResults) {
const results = test.multiResults ? [test, ...test.multiResults] : [test];
Expand All @@ -53,7 +58,7 @@ export class DebugCodeLensProvider implements vscode.CodeLensProvider {
const end = new vscode.Position(test.end.line, test.start.column + 5);
const range = new vscode.Range(start, end);

result.push(new DebugCodeLens(document, range, fileName, ...allIds));
result.push(new DebugCodeLens(document, range, ...allIds));
}

return result;
Expand All @@ -70,9 +75,9 @@ export class DebugCodeLensProvider implements vscode.CodeLensProvider {
): vscode.ProviderResult<vscode.CodeLens> {
if (codeLens instanceof DebugCodeLens) {
codeLens.command = {
arguments: [codeLens.document, codeLens.fileName, ...codeLens.testIds],
command: `${extensionName}.run-test`,
title: codeLens.testIds.length > 1 ? `Debug(${codeLens.testIds.length})` : 'Debug',
arguments: [...codeLens.testIds],
command: `${extensionName}.editor.debug-tests`,
title: codeLens.testIds.length > 1 ? `Debug (${codeLens.testIds.length})` : 'Debug',
};
}

Expand Down
11 changes: 0 additions & 11 deletions src/Jest/index.ts

This file was deleted.

Loading

0 comments on commit d50d127

Please sign in to comment.