Skip to content

Commit

Permalink
consolidate output and clean up legacy code and settings (#910)
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz committed Sep 26, 2022
1 parent 32b58df commit c567e4e
Show file tree
Hide file tree
Showing 34 changed files with 2,730 additions and 1,124 deletions.
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "vscode-jest",
"displayName": "Jest",
"description": "Use Facebook's Jest With Pleasure.",
"version": "4.7.0",
"version": "5.0.0",
"publisher": "Orta",
"engines": {
"vscode": "^1.63.0"
"vscode": "^1.68.1"
},
"author": {
"name": "Orta Therox, ConnectDotz & Sean Poulter",
Expand Down Expand Up @@ -72,7 +72,7 @@
"title": "Jest",
"properties": {
"jest.showTerminalOnLaunch": {
"description": "Automatically open test explorer's terminal upon launch",
"description": "(deprecated) Automatically open test explorer's terminal upon launch",
"type": "boolean",
"default": true,
"scope": "window"
Expand Down Expand Up @@ -220,9 +220,7 @@
"jest.testExplorer": {
"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": {
"enabled": true
},
"default": null,
"scope": "resource"
},
"jest.monitorLongRun": {
Expand Down Expand Up @@ -464,8 +462,7 @@
"dependencies": {
"istanbul-lib-coverage": "^3.0.0",
"istanbul-lib-source-maps": "^4.0.0",
"jest-editor-support": "^30.1.0",
"vscode-codicons": "^0.0.4"
"jest-editor-support": "^30.2.0"
},
"devDependencies": {
"@types/istanbul-lib-coverage": "^2.0.2",
Expand Down
128 changes: 26 additions & 102 deletions src/JestExt/core.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import * as vscode from 'vscode';
import { JestTotalResults } from 'jest-editor-support';

import { TestStatus } from '../decorations/test-status';
import { statusBar, StatusBar, Mode, StatusBarUpdate, SBTestStats } from '../StatusBar';
import {
TestReconciliationState,
TestResultProvider,
TestResult,
resultsWithLowerCaseWindowsDriveLetters,
SortedTestResults,
TestResultStatusInfo,
TestReconciliationStateType,
} from '../TestResults';
import { testIdString, IdStringType, escapeRegExp, emptyTestStats } from '../helpers';
import { CoverageMapProvider, CoverageCodeLensProvider } from '../Coverage';
import { updateDiagnostics, updateCurrentDiagnostics, resetDiagnostics } from '../diagnostics';
import { DebugCodeLensProvider, DebugTestIdentifier } from '../DebugCodeLens';
import { DebugConfigurationProvider } from '../DebugConfigurationProvider';
import { DecorationOptions, TestStats } from '../types';
import { TestStats } from '../types';
import { CoverageOverlay } from '../Coverage/CoverageOverlay';
import { resultsWithoutAnsiEscapeSequence } from '../TestResults/TestResult';
import { CoverageMapData } from 'istanbul-lib-coverage';
Expand All @@ -34,6 +29,7 @@ import { JestTestProvider } from '../test-provider';
import { JestProcessInfo } from '../JestProcessManagement';
import { addFolderToDisabledWorkspaceFolders } from '../extensionManager';
import { MessageAction } from '../messaging';
import { getExitErrorDef } from '../errors';

interface RunTestPickItem extends vscode.QuickPickItem {
id: DebugTestIdentifier;
Expand All @@ -51,11 +47,6 @@ export class JestExt {
debugConfigurationProvider: DebugConfigurationProvider;
coverageCodeLensProvider: CoverageCodeLensProvider;

// So you can read what's going on
channel: vscode.OutputChannel;

private decorations: TestStatus;

// The ability to show fails in the problems section
private failDiagnostics: vscode.DiagnosticCollection;

Expand Down Expand Up @@ -84,7 +75,6 @@ export class JestExt {
this.extContext = createJestExtContext(workspaceFolder, pluginSettings);
this.logging = this.extContext.loggingFactory.create('JestExt');

this.channel = vscode.window.createOutputChannel(`Jest (${workspaceFolder.name})`);
this.failDiagnostics = vscode.languages.createDiagnosticCollection(
`Jest (${workspaceFolder.name})`
);
Expand Down Expand Up @@ -117,8 +107,6 @@ export class JestExt {

this.status = statusBar.bind(workspaceFolder.name);

// The theme stuff
this.decorations = new TestStatus(vscodeContext);
// reset the jest diagnostics
resetDiagnostics(this.failDiagnostics);

Expand All @@ -127,6 +115,10 @@ export class JestExt {
this.setupStatusBar();
}

public showOutput(): void {
this.extContext.output.show();
}

private getExtExplorerContext(): JestExtExplorerContext {
return {
...this.extContext,
Expand Down Expand Up @@ -168,34 +160,23 @@ export class JestExt {

private setupRunEvents(events: JestSessionEvents): void {
events.onRunEvent.event((event: JestRunEvent) => {
// only process the test running event
if (event.process.request.type === 'not-test') {
return;
}
// console.log(
// `[core.onRunEvent] "${this.extContext.workspace.name}" event:${event.type} process:${event.process.id}`
// );
switch (event.type) {
case 'scheduled':
this.channel.appendLine(`${event.process.id} is scheduled`);
break;
case 'data':
if (event.newLine) {
this.channel.appendLine(event.text);
} else {
this.channel.append(event.text);
}
if (event.isError) {
this.channel.show();
}
break;
case 'start':
this.updateStatusBar({ state: 'running' });
this.channel.clear();
break;
case 'end':
this.updateStatusBar({ state: 'done' });
break;
case 'exit':
if (event.error) {
this.updateStatusBar({ state: 'stopped' });
const msg = `${event.error}\n see troubleshooting: ${messaging.TROUBLESHOOTING_URL}`;
this.channel.appendLine(msg);
this.channel.show();

messaging.systemErrorMessage(
prefixWorkspace(this.extContext, event.error),
...this.buildMessageActions(['help', 'wizard', 'disable-folder'])
Expand Down Expand Up @@ -262,26 +243,20 @@ export class JestExt {
if (newSession) {
await this.processSession.stop();
this.processSession = this.createProcessSession();
this.channel.appendLine('Starting a new Jest Process Session');
} else {
this.channel.appendLine('Starting Jest Session');
}

this.testProvider?.dispose();
if (this.extContext.settings.testExplorer.enabled) {
this.testProvider = new JestTestProvider(this.getExtExplorerContext());
}
this.testProvider = new JestTestProvider(this.getExtExplorerContext());

await this.processSession.start();

this.events.onTestSessionStarted.fire({ ...this.extContext, session: this.processSession });

this.updateTestFileList();
this.channel.appendLine('Jest Session Started');
} catch (e) {
const msg = prefixWorkspace(this.extContext, 'Failed to start jest session');
this.logging('error', `${msg}:`, e);
this.channel.appendLine('Failed to start jest session');
this.extContext.output.write('Failed to start jest session', 'error');
messaging.systemErrorMessage(
`${msg}...`,
...this.buildMessageActions(['help', 'wizard', 'disable-folder'])
Expand All @@ -291,20 +266,18 @@ export class JestExt {

public async stopSession(): Promise<void> {
try {
this.channel.appendLine('Stopping Jest Session');
await this.processSession.stop();

this.testProvider?.dispose();
this.testProvider = undefined;

this.events.onTestSessionStopped.fire();

this.channel.appendLine('Jest Session Stopped');
this.updateStatusBar({ state: 'stopped' });
} catch (e) {
const msg = prefixWorkspace(this.extContext, 'Failed to stop jest session');
this.logging('error', `${msg}:`, e);
this.channel.appendLine('Failed to stop jest session');
this.extContext.output.write('Failed to stop jest session', 'error');
messaging.systemErrorMessage('${msg}...', ...this.buildMessageActions(['help']));
}
}
Expand All @@ -324,7 +297,7 @@ export class JestExt {
try {
sortedResults = this.testResultProvider.getSortedResults(filePath);
} catch (e) {
this.channel.appendLine(`${filePath}: failed to parse test results: ${e}`);
this.extContext.output.write(`${filePath}: failed to parse test results: ${e}`, 'error');
// assign an empty result so we can clear the outdated decorators/diagnostics etc
sortedResults = {
fail: [],
Expand All @@ -338,7 +311,7 @@ export class JestExt {
return;
}

this.updateDecorators(sortedResults, editor);
this.updateDecorators();
updateCurrentDiagnostics(sortedResults.fail, this.failDiagnostics, editor);
}

Expand Down Expand Up @@ -375,41 +348,7 @@ export class JestExt {
return this.startSession(true);
}

updateDecorators(testResults: SortedTestResults, editor: vscode.TextEditor): void {
if (
this.extContext.settings.testExplorer.enabled === false ||
this.extContext.settings.testExplorer.showClassicStatus
) {
// Status indicators (gutter icons)
const styleMap = [
{
data: testResults.success,
decorationType: this.decorations.passing,
state: TestReconciliationState.KnownSuccess,
},
{
data: testResults.fail,
decorationType: this.decorations.failing,
state: TestReconciliationState.KnownFail,
},
{
data: testResults.skip,
decorationType: this.decorations.skip,
state: TestReconciliationState.KnownSkip,
},
{
data: testResults.unknown,
decorationType: this.decorations.unknown,
state: TestReconciliationState.Unknown,
},
];

styleMap.forEach((style) => {
const decorators = this.generateDotsForItBlocks(style.data, style.state);
editor.setDecorations(style.decorationType, decorators);
});
}

updateDecorators(): void {
// Debug CodeLens
this.debugCodeLensProvider.didChange();
}
Expand Down Expand Up @@ -447,7 +386,7 @@ export class JestExt {
}
public deactivate(): void {
this.stopSession();
this.channel.dispose();
this.extContext.output.dispose();

this.testResultProvider.dispose();
this.testProvider?.dispose();
Expand Down Expand Up @@ -647,20 +586,16 @@ export class JestExt {
private updateTestFileList(): void {
this.processSession.scheduleProcess({
type: 'list-test-files',
onResult: (files, error) => {
onResult: (files, error, exitCode) => {
this.setTestFiles(files);
this.logging('debug', `found ${files?.length} testFiles`);
if (error) {
const msg = prefixWorkspace(
this.extContext,
'Failed to obtain test file list, something might not be setup right?'
);
const msg =
'failed to retrieve test file list. TestExplorer might show incomplete test items';
this.extContext.output.write(error, 'new-line');
const errorType = getExitErrorDef(exitCode) ?? 'error';
this.extContext.output.write(msg, errorType);
this.logging('error', msg, error);
//fire this warning message could risk reporting error multiple times for the given workspace folder
//therefore garding the warning message with the debugMode
if (this.extContext.settings.debugMode) {
messaging.systemWarningMessage(msg, ...this.buildMessageActions(['help', 'wizard']));
}
}
},
});
Expand Down Expand Up @@ -717,15 +652,4 @@ export class JestExt {

this.refreshDocumentChange();
}

private generateDotsForItBlocks(
blocks: TestResult[],
state: TestReconciliationStateType
): DecorationOptions[] {
return blocks.map((it) => ({
range: new vscode.Range(it.start.line, it.start.column, it.start.line, it.start.column + 1),
hoverMessage: TestResultStatusInfo[state].desc,
identifier: it.name,
}));
}
}
Loading

0 comments on commit c567e4e

Please sign in to comment.