Skip to content

Commit

Permalink
Merge 8bc8e79 into 3dae02a
Browse files Browse the repository at this point in the history
  • Loading branch information
escaton committed Sep 19, 2018
2 parents 3dae02a + 8bc8e79 commit 61a53a1
Show file tree
Hide file tree
Showing 18 changed files with 659 additions and 216 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_jest-editor/
.vscode/symbols.json
coverage/
/coverage/
integrations/create-react-example/node_modules
node_modules/
out/
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Bug-fixes within the same version aren't needed
-->

### 2.10.0

* Support multi-root workspaces - escaton

### 2.9.1

* Prevent ANSI escape codes from appearing in test messages - seanpoulter
Expand Down
43 changes: 29 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"color": "#ca461a"
},
"categories": ["Other"],
"keywords": ["multi-root ready"],
"activationEvents": [
"workspaceContains:jest.config.js",
"workspaceContains:jest.json",
Expand Down Expand Up @@ -51,77 +52,91 @@
"jest.autoEnable": {
"description": "Automatically start Jest for this project",
"type": "boolean",
"default": true
"default": true,
"scope": "resource"
},
"jest.pathToJest": {
"description":
"The path to the Jest binary, or an npm command to run tests prefixed with `--` e.g. `node_modules/.bin/jest` or `npm test --`",
"type": "string",
"default": null
"default": null,
"scope": "resource"
},
"jest.pathToConfig": {
"description": "The path to your Jest configuration file",
"type": "string",
"default": ""
"default": "",
"scope": "resource"
},
"jest.rootPath": {
"description": "The path to your frontend src folder",
"type": "string",
"default": ""
"default": "",
"scope": "resource"
},
"jest.enableInlineErrorMessages": {
"description": "Whether errors should be reported inline on a file",
"type": "boolean",
"default": true
"default": true,
"scope": "resource"
},
"jest.enableSnapshotUpdateMessages": {
"description": "Whether snapshot update messages should show",
"type": "boolean",
"default": true
"default": true,
"scope": "resource"
},
"jest.runAllTestsFirst": {
"description": "Run all tests before starting Jest in watch mode",
"type": "boolean",
"default": true
"default": true,
"scope": "resource"
},
"jest.showCoverageOnLoad": {
"description": "Show code coverage when extension starts (if collected)",
"type": "boolean",
"default": false
"default": false,
"scope": "resource"
},
"jest.coverageFormatter": {
"description": "Coverage formatter to use",
"type": "string",
"enum": ["DefaultFormatter", "GutterFormatter"],
"default": "DefaultFormatter"
"default": "DefaultFormatter",
"scope": "resource"
},
"jest.enableCodeLens": {
"description": "Whether codelens for debugging should show",
"type": "boolean",
"default": true
"default": true,
"scope": "window"
},
"jest.debugCodeLens.showWhenTestStateIn": {
"description": "Show the debug CodeLens when the it/test block state is in this collection",
"type": "array",
"items": {
"enum": ["fail", "pass", "skip", "unknown"]
},
"default": ["fail", "unknown"]
"default": ["fail", "unknown"],
"scope": "window"
},
"jest.enableSnapshotPreviews": {
"description": "Whether snapshot previews should show",
"type": "boolean",
"default": true
"default": true,
"scope": "window"
},
"jest.restartJestOnSnapshotUpdate": {
"description": "Restart Jest runner after updating the snapshots",
"type": "boolean",
"default": false
"default": false,
"scope": "resource"
},
"jest.debugMode": {
"description": "Enable debug mode to diagnose plugin issues. (see developer console)",
"type": "boolean",
"default": false
"default": false,
"scope": "resource"
}
}
},
Expand Down
19 changes: 5 additions & 14 deletions src/Coverage/CoverageCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@ import * as vscode from 'vscode'

import { JestExt } from '../JestExt'

export function registerCoverageCodeLens(jestExt: JestExt) {
return [
vscode.languages.registerCodeLensProvider(
{ pattern: '**/*.{ts,tsx,js,jsx}' },
new CoverageCodeLensProvider(jestExt)
),
]
}

class CoverageCodeLensProvider implements vscode.CodeLensProvider {
private jestExt: JestExt
export class CoverageCodeLensProvider implements vscode.CodeLensProvider {
private getJestExt: (uri: vscode.Uri) => JestExt

constructor(jestExt: JestExt) {
this.jestExt = jestExt
constructor(getJestExt: (uri: vscode.Uri) => JestExt) {
this.getJestExt = getJestExt
}

public provideCodeLenses(document: vscode.TextDocument, _token: vscode.CancellationToken) {
const coverage = this.jestExt.coverageMapProvider.getFileCoverage(document.fileName)
const coverage = this.getJestExt(document.uri).coverageMapProvider.getFileCoverage(document.fileName)
if (!coverage) {
return
}
Expand Down
4 changes: 3 additions & 1 deletion src/DebugCodeLens/DebugCodeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import * as vscode from 'vscode'
export class DebugCodeLens extends vscode.CodeLens {
readonly fileName: string
readonly testName: string
readonly document: vscode.TextDocument

constructor(range: vscode.Range, fileName: string, testName: string) {
constructor(document: vscode.TextDocument, range: vscode.Range, fileName: string, testName: string) {
super(range)
this.document = document
this.fileName = fileName
this.testName = testName
}
Expand Down
15 changes: 8 additions & 7 deletions src/DebugCodeLens/DebugCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { extensionName } from '../appGlobals'
import { escapeRegExp } from '../helpers'
import { basename } from 'path'
import { DebugCodeLens } from './DebugCodeLens'
import { TestReconciliationState, TestResultProvider } from '../TestResults'
import { TestReconciliationState } from '../TestResults'
import { TestState, TestStateByTestReconciliationState } from './TestState'
import { JestExt } from '../JestExt'

export class DebugCodeLensProvider implements vscode.CodeLensProvider {
private _showWhenTestStateIn: TestState[]
private getJestExt: (uri: vscode.Uri) => JestExt
onDidChange: vscode.EventEmitter<void>
testResultProvider: TestResultProvider

constructor(testResultProvider: TestResultProvider, showWhenTestStateIn: TestState[]) {
this.testResultProvider = testResultProvider
constructor(getJestExt: (uri: vscode.Uri) => JestExt, showWhenTestStateIn: TestState[]) {
this.getJestExt = getJestExt
this._showWhenTestStateIn = showWhenTestStateIn
this.onDidChange = new vscode.EventEmitter()
}
Expand All @@ -38,7 +39,7 @@ export class DebugCodeLensProvider implements vscode.CodeLensProvider {
}

const filePath = document.fileName
const testResults = this.testResultProvider.getResults(filePath)
const testResults = this.getJestExt(document.uri).testResultProvider.getResults(filePath)
const fileName = basename(document.fileName)

for (const test of testResults) {
Expand All @@ -49,7 +50,7 @@ export class DebugCodeLensProvider implements vscode.CodeLensProvider {
const start = new vscode.Position(test.start.line, test.start.column)
const end = new vscode.Position(test.end.line, test.start.column + 5)
const range = new vscode.Range(start, end)
result.push(new DebugCodeLens(range, fileName, test.name))
result.push(new DebugCodeLens(document, range, fileName, test.name))
}

return result
Expand All @@ -63,7 +64,7 @@ export class DebugCodeLensProvider implements vscode.CodeLensProvider {
resolveCodeLens(codeLens: vscode.CodeLens, _: vscode.CancellationToken): vscode.ProviderResult<vscode.CodeLens> {
if (codeLens instanceof DebugCodeLens) {
codeLens.command = {
arguments: [codeLens.fileName, escapeRegExp(codeLens.testName)],
arguments: [codeLens.document, codeLens.fileName, escapeRegExp(codeLens.testName)],
command: `${extensionName}.run-test`,
title: 'Debug',
}
Expand Down
34 changes: 12 additions & 22 deletions src/JestExt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode'
import { ProjectWorkspace, JestTotalResults } from 'jest-editor-support'

import * as decorations from './decorations'
import { IPluginSettings } from './Settings'
import { IPluginResourceSettings } from './Settings'
import * as status from './statusBar'
import {
TestReconciliationState,
Expand All @@ -17,25 +17,25 @@ import { updateDiagnostics, updateCurrentDiagnostics, resetDiagnostics, failedSu
import { DebugCodeLensProvider } from './DebugCodeLens'
import { DebugConfigurationProvider } from './DebugConfigurationProvider'
import { DecorationOptions } from './types'
import { hasDocument, isOpenInMultipleEditors } from './editor'
import { isOpenInMultipleEditors } from './editor'
import { CoverageOverlay } from './Coverage/CoverageOverlay'
import { JestProcess, JestProcessManager } from './JestProcessManagement'
import { isWatchNotSupported, WatchMode } from './Jest'
import * as messaging from './messaging'

export class JestExt {
private workspace: ProjectWorkspace
private pluginSettings: IPluginSettings
private pluginSettings: IPluginResourceSettings

coverageMapProvider: CoverageMapProvider
coverageOverlay: CoverageOverlay

testResultProvider: TestResultProvider
public debugCodeLensProvider: DebugCodeLensProvider
debugCodeLensProvider: DebugCodeLensProvider
debugConfigurationProvider: DebugConfigurationProvider

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

// The ability to show fails in the problems section
private failDiagnostics: vscode.DiagnosticCollection
Expand All @@ -59,14 +59,17 @@ export class JestExt {
context: vscode.ExtensionContext,
workspace: ProjectWorkspace,
outputChannel: vscode.OutputChannel,
pluginSettings: IPluginSettings
pluginSettings: IPluginResourceSettings,
debugCodeLensProvider: DebugCodeLensProvider,
debugConfigurationProvider: DebugConfigurationProvider
) {
this.workspace = workspace
this.channel = outputChannel
this.failingAssertionDecorators = {}
this.failDiagnostics = vscode.languages.createDiagnosticCollection('Jest')
this.clearOnNextInput = true
this.pluginSettings = pluginSettings
this.debugCodeLensProvider = debugCodeLensProvider

this.coverageMapProvider = new CoverageMapProvider()
this.coverageOverlay = new CoverageOverlay(
Expand All @@ -77,11 +80,7 @@ export class JestExt {
)

this.testResultProvider = new TestResultProvider()
this.debugCodeLensProvider = new DebugCodeLensProvider(
this.testResultProvider,
pluginSettings.debugCodeLens.enabled ? pluginSettings.debugCodeLens.showWhenTestStateIn : []
)
this.debugConfigurationProvider = new DebugConfigurationProvider()
this.debugConfigurationProvider = debugConfigurationProvider

this.jestProcessManager = new JestProcessManager({
projectWorkspace: workspace,
Expand Down Expand Up @@ -241,7 +240,7 @@ export class JestExt {
this.parsingTestFile = false
}

public triggerUpdateSettings(updatedSettings: IPluginSettings) {
public triggerUpdateSettings(updatedSettings: IPluginResourceSettings) {
this.pluginSettings = updatedSettings

this.workspace.rootPath = updatedSettings.rootPath
Expand All @@ -251,10 +250,6 @@ export class JestExt {

this.coverageOverlay.enabled = updatedSettings.showCoverageOnLoad

this.debugCodeLensProvider.showWhenTestStateIn = updatedSettings.debugCodeLens.enabled
? updatedSettings.debugCodeLens.showWhenTestStateIn
: []

this.stopProcess()

setTimeout(() => {
Expand Down Expand Up @@ -398,7 +393,7 @@ export class JestExt {
this.jestProcessManager.stopAll()
}

public runTest = async (fileName: string, identifier: string) => {
public runTest = async (workspaceFolder: vscode.WorkspaceFolder, fileName: string, identifier: string) => {
const restart = this.jestProcessManager.numberOfProcesses > 0
this.jestProcessManager.stopAll()

Expand All @@ -411,7 +406,6 @@ export class JestExt {
}
})

const workspaceFolder = vscode.workspace.workspaceFolders[0]
try {
// try to run the debug configuration from launch.json
await vscode.debug.startDebugging(workspaceFolder, 'vscode-jest-tests')
Expand Down Expand Up @@ -446,10 +440,6 @@ export class JestExt {
}

onDidChangeActiveTextEditor(editor: vscode.TextEditor) {
if (!hasDocument(editor)) {
return
}

this.triggerUpdateActiveEditor(editor)
}

Expand Down
15 changes: 9 additions & 6 deletions src/Settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { TestState } from '../DebugCodeLens'

export interface IPluginSettings {
export interface IPluginResourceSettings {
autoEnable?: boolean
debugCodeLens: {
enabled: boolean
showWhenTestStateIn: TestState[]
}
enableInlineErrorMessages?: boolean
enableSnapshotPreviews?: boolean
enableSnapshotUpdateMessages?: boolean
pathToConfig?: string
pathToJest?: string
Expand All @@ -19,6 +14,14 @@ export interface IPluginSettings {
debugMode?: boolean
}

export interface IPluginWindowSettings {
debugCodeLens: {
enabled: boolean
showWhenTestStateIn: TestState[]
}
enableSnapshotPreviews?: boolean
}

export function isDefaultPathToJest(str) {
return str === null || str === ''
}
Expand Down

0 comments on commit 61a53a1

Please sign in to comment.