Skip to content

Commit

Permalink
Merge pull request jest-community#4 from orta/support_showing_inline_…
Browse files Browse the repository at this point in the history
…pass

Support showing status bar, and in the problems section
  • Loading branch information
legend authored Nov 5, 2016
2 parents 4738175 + 4ec72c3 commit b35ae52
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
58 changes: 57 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ import * as decorations from './decorations'

var extensionInstance: JestExt;

interface JestFileResults {
name: string
summary: string
message: string
status: "failed" | "passed"
startTime:number
endTime:number
}

interface JestTotalResults {
success:boolean
startTime:number
numTotalTests:number
numTotalTestSuites:number
numRuntimeErrorTestSuites:number
numPassedTests:number
numFailedTests:number
numPendingTests:number
testResults: JestFileResults[]
}

export function activate(context: vscode.ExtensionContext) {
let channel = vscode.window.createOutputChannel("Jest")

Expand Down Expand Up @@ -41,9 +62,18 @@ export function activate(context: vscode.ExtensionContext) {
class JestExt {
private jestProcess: JestRunner
private parser: TestFileParser

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

// Memory management
private workspaceDisposal: { dispose(): any }[]
private perFileDisposals: { dispose(): any }[]

// The bottom status bar
private statusBarItem: vscode.StatusBarItem;
// The ability to show fails in the problems section
private failDiagnostics: vscode.DiagnosticCollection;

private passingItStyle: vscode.TextEditorDecorationType
private failingItStyle: vscode.TextEditorDecorationType
Expand All @@ -53,6 +83,8 @@ class JestExt {
this.workspaceDisposal = disposal
this.perFileDisposals = []
this.parser = new TestFileParser()
this.statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left)
this.failDiagnostics = vscode.languages.createDiagnosticCollection("Jest")
}

startProcess() {
Expand Down Expand Up @@ -82,6 +114,7 @@ class JestExt {
});

this.setupDecorators()
this.setupStatusBar()
}

async triggerUpdateDecorations(editor: vscode.TextEditor) {
Expand All @@ -94,12 +127,35 @@ class JestExt {
}
}

setupStatusBar() {
this.statusBarItem.text = "Jest: Running"
this.statusBarItem.show()
}

setupDecorators() {
this.passingItStyle = decorations.passingItName()
this.failingItStyle = decorations.failingItName();
}

updateWithData(data: any) {
updateWithData(data: JestTotalResults) {
if (data.success) {
this.statusBarItem.text = "Jest: Passed"
} else {
this.statusBarItem.text = "Jest: Failed"
this.statusBarItem.color = "red"

this.failDiagnostics.clear()
const fails = data.testResults.filter((file) => file.status === "failed")
fails.forEach( (failed) => {
const daig = new vscode.Diagnostic(
new vscode.Range(0, 0, 0, 0),
failed.message,
vscode.DiagnosticSeverity.Error
)
const uri = vscode.Uri.file(failed.name)
this.failDiagnostics.set(uri, [daig])
})
}
}

generateDecoratorsForJustIt(blocks: ItBlock[], editor: vscode.TextEditor): vscode.DecorationOptions[] {
Expand Down
4 changes: 0 additions & 4 deletions src/test_file_parser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict'

import fs = require('fs');

import {basename, dirname} from 'path';
import * as path from 'path';

// var esprima = require('esprima');
import * as babylon from 'babylon'

interface Location {
Expand Down

0 comments on commit b35ae52

Please sign in to comment.