Skip to content

Commit

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

Support showing inline pass
  • Loading branch information
legend authored Oct 30, 2016
2 parents 031232e + 3bbacff commit 4738175
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 31 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

This is a WIP, this README represents what I want, not what it is yet.

It is kind of blocked on https://github.com/facebook/jest/issues/1900 for the moment

## The Aim

A comprehensive experience when using Jest with a project.

* Useful Feedback
* Session based test watching

---

### Feedback

* Inline information
Expand All @@ -25,4 +21,9 @@ A comprehensive experience when using Jest with a project.
### Session based watching

* Opening a project with Jest should start to run the tests by default, you should be able to opt out
* Should be able to declare what the command to run jest should look like
* Closing a project, should close the tests

## Keep your eye on

If we need more metadata, then look at - https://github.com/facebook/jest/issues/1900
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-jest",
"displayName": "vscode-jest",
"description": "Improve your Jest testing workflow in VS Code.",
"version": "0.0.1",
"version": "0.0.2",
"publisher": "Orta",
"engines": {
"vscode": "^1.5.0"
Expand Down
47 changes: 47 additions & 0 deletions src/decorations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

import * as vscode from 'vscode';

export function unknownItName() {
return vscode.window.createTextEditorDecorationType({
borderWidth: '1px',
borderStyle: 'solid',
light: {
// this color will be used in light color themes
borderColor: 'black'
},
dark: {
// this color will be used in dark color themes
borderColor: 'black'
},
before: {
contentText: "F",
border: "white",
backgroundColor: "black",
width: "20"
}
});
}

export function failingItName() {
return vscode.window.createTextEditorDecorationType({
overviewRulerColor: 'red',
overviewRulerLane: vscode.OverviewRulerLane.Left,
before: {
color: "green",
contentText: "●",
}
});
}

export function passingItName() {
return vscode.window.createTextEditorDecorationType({
overviewRulerColor: 'green',
overviewRulerLane: vscode.OverviewRulerLane.Left,
before: {
color: "green",
contentText: "●",
}
});
}

106 changes: 88 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,53 @@ import * as childProcess from 'child_process';
import {basename, dirname} from 'path';
import * as path from 'path';
import {JestRunner} from './jest_runner'
import {TestFileParser, ItBlock} from './test_file_parser'
import * as decorations from './decorations'

var extensionInstance: JestExt;

export function activate(context: vscode.ExtensionContext) {
console.log('Hello world, "vscode-jest" is now active!')

let disposable = vscode.commands.registerCommand('extension.jest.startJest', () => {
vscode.window.showInformationMessage('Hello World!');
})
// commands.registerCommand('eslint.showOutputChannel', () => { client.outputChannel.show(); }),
let channel = vscode.window.createOutputChannel("Jest")

// if (shouldStartOnActivate()) {
console.log("Starting")
extensionInstance = new JestExt(channel, )
extensionInstance.startProcess()
// }

context.subscriptions.push(disposable)
console.log("Starting")
extensionInstance = new JestExt(channel, context.subscriptions)
extensionInstance.startProcess()

// Setup the file change watchers
var activeEditor = vscode.window.activeTextEditor;
if (activeEditor) {
extensionInstance.triggerUpdateDecorations(activeEditor);
}

vscode.window.onDidChangeActiveTextEditor(editor => {
activeEditor = editor;
if (editor) {
extensionInstance.triggerUpdateDecorations(activeEditor);
}
}, null, context.subscriptions);

vscode.workspace.onDidChangeTextDocument(event => {
if (activeEditor && event.document === activeEditor.document) {
extensionInstance.triggerUpdateDecorations(activeEditor);
}
}, null, context.subscriptions);
}

class JestExt {
private jestProcess: JestRunner;
private channel: vscode.OutputChannel;
private jestProcess: JestRunner
private parser: TestFileParser
private channel: vscode.OutputChannel
private workspaceDisposal: { dispose(): any }[]
private perFileDisposals: { dispose(): any }[]

public constructor(outputChannel: vscode.OutputChannel) {
private passingItStyle: vscode.TextEditorDecorationType
private failingItStyle: vscode.TextEditorDecorationType

public constructor(outputChannel: vscode.OutputChannel, disposal: { dispose(): any }[]) {
this.channel = outputChannel
this.workspaceDisposal = disposal
this.perFileDisposals = []
this.parser = new TestFileParser()
}

startProcess() {
Expand All @@ -41,14 +61,16 @@ class JestExt {
this.jestProcess.on('debuggerComplete', () => {
console.log("Closed")
}).on('executableJSON', (data: any) => {
console.log("JSON ] " + JSON.stringify(data))
console.log("JSON ] ", data)
this.updateWithData(data)

}).on('executableOutput', (output: string) => {
console.log("Output] " + output)

if (!output.includes("Watch Usage")){
this.channel.appendLine(output)
}

}).on('executableStdErr', (error: Buffer) => {
this.channel.appendLine(error.toString())
}).on('nonTerminalError', (error: string) => {
Expand All @@ -58,6 +80,47 @@ class JestExt {
}).on('terminalError', (error: string) => {
console.log("\nException raised: " + error);
});

this.setupDecorators()
}

async triggerUpdateDecorations(editor: vscode.TextEditor) {
try {
await this.parser.run(editor.document.uri.fsPath)
let decorators = this.generateDecoratorsForJustIt(this.parser.itBlocks, editor)
editor.setDecorations(this.passingItStyle,decorators)
} catch(e) {
return;
}
}

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

updateWithData(data: any) {
}

generateDecoratorsForJustIt(blocks: ItBlock[], editor: vscode.TextEditor): vscode.DecorationOptions[] {
return blocks.map((it)=> {
return {
// VS Code is 1 based, babylon is 0 based
range: new vscode.Range(it.start.line - 1, it.start.column, it.start.line - 1, it.start.column + 2),
hoverMessage: it.name,
}
})
}


generateDecoratorsForWholeItBlocks(blocks: ItBlock[], editor: vscode.TextEditor): vscode.DecorationOptions[] {
return blocks.map((it)=> {
return {
// VS Code is 1 based, babylon is 0 based
range: new vscode.Range(it.start.line - 1, it.start.column, it.end.line - 1, it.end.column),
hoverMessage: it.name,
}
})
}

recievedResults(results: any) {
Expand All @@ -67,6 +130,13 @@ class JestExt {
console.log("Failed")
}
}

deactivate() {

}
}

export function deactivate() {}
export function deactivate() {
extensionInstance.deactivate()

}
6 changes: 3 additions & 3 deletions src/jest_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export class JestRunner extends EventEmitter {
this.debugprocess = childProcess.spawn(runtimeExecutable, runtimeArgs, {cwd: processCwd, env: processEnv});

this.debugprocess.stdout.on('data', (data: Buffer) => {
let stringValue = data.toString()
// verify last char too?
if (stringValue.charAt(0) == "{") {
// Convert to JSON and strip any trailing newlines
let stringValue = data.toString().replace(/\n$/, "")
if (stringValue.substr(0, 1) === "{" && stringValue.substr(-1, 1) === "}") {
this.emit('executableJSON', JSON.parse(stringValue));
} else {
this.emit('executableOutput', stringValue);
Expand Down
2 changes: 1 addition & 1 deletion src/test_file_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ItBlock {
}
}

export default class TestFileParser {
export class TestFileParser {

itBlocks: ItBlock[]

Expand Down
Empty file added src/test_reconciler.ts
Empty file.
Loading

0 comments on commit 4738175

Please sign in to comment.