Skip to content

Commit

Permalink
Merge 23ec6ff into 70c6668
Browse files Browse the repository at this point in the history
  • Loading branch information
seanpoulter committed Apr 1, 2018
2 parents 70c6668 + 23ec6ff commit 8b2740a
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 64 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ Bug-fixes within the same version aren't needed
## Master
* [your thing] - [you]
* Adds a setting to control when the debug CodeLens appears - seanpoulter
-->

## Master

### 2.6.4

* Fixes debugging of tasks on Windows (bug introduced in 2.6.2) - stephtr
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@
"type": "boolean",
"default": true
},
"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"]
},
"jest.enableSnapshotPreviews": {
"description": "Whether snapshot previews should show",
"type": "boolean",
Expand Down
25 changes: 16 additions & 9 deletions src/DebugCodeLens/DebugCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import { escapeRegExp } from '../helpers'
import { basename } from 'path'
import { DebugCodeLens } from './DebugCodeLens'
import { TestReconciliationState, TestResultProvider } from '../TestResults'
import { TestState, TestStateByTestReconciliationState } from './TestState'

export class DebugCodeLensProvider implements vscode.CodeLensProvider {
private _enabled: boolean
private _showWhenTestStateIn: TestState[]
onDidChange: vscode.EventEmitter<void>
testResultProvider: TestResultProvider

constructor(testResultProvider: TestResultProvider, enabled: boolean) {
constructor(testResultProvider: TestResultProvider, showWhenTestStateIn: TestState[]) {
this.testResultProvider = testResultProvider
this._enabled = enabled
this._showWhenTestStateIn = showWhenTestStateIn
this.onDidChange = new vscode.EventEmitter()
}

get enabled() {
return this._enabled
get showWhenTestStateIn() {
return this._showWhenTestStateIn
}

set enabled(value: boolean) {
this._enabled = value
set showWhenTestStateIn(value: TestState[]) {
this._showWhenTestStateIn = value
this.onDidChange.fire()
}

Expand All @@ -32,15 +33,16 @@ export class DebugCodeLensProvider implements vscode.CodeLensProvider {
provideCodeLenses(document: vscode.TextDocument, _: vscode.CancellationToken): vscode.CodeLens[] {
const result = []

if (!this._enabled || document.isUntitled) {
if (this._showWhenTestStateIn.length === 0 || document.isUntitled) {
return result
}

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

for (const test of testResults) {
if (test.status === TestReconciliationState.KnownSuccess || test.status === TestReconciliationState.KnownSkip) {
if (!this.showCodeLensAboveTest(test)) {
continue
}

Expand All @@ -53,6 +55,11 @@ export class DebugCodeLensProvider implements vscode.CodeLensProvider {
return result
}

showCodeLensAboveTest(test: { status: TestReconciliationState }) {
const state = TestStateByTestReconciliationState[test.status]
return this._showWhenTestStateIn.includes(state)
}

resolveCodeLens(codeLens: vscode.CodeLens, _: vscode.CancellationToken): vscode.ProviderResult<vscode.CodeLens> {
if (codeLens instanceof DebugCodeLens) {
codeLens.command = {
Expand Down
15 changes: 15 additions & 0 deletions src/DebugCodeLens/TestState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { TestReconciliationState } from '../TestResults'

export enum TestState {
Fail = 'fail',
Pass = 'pass',
Skip = 'skip',
Unknown = 'unknown',
}

export const TestStateByTestReconciliationState = {
[TestReconciliationState.KnownFail]: TestState.Fail,
[TestReconciliationState.KnownSkip]: TestState.Skip,
[TestReconciliationState.KnownSuccess]: TestState.Pass,
[TestReconciliationState.Unknown]: TestState.Unknown,
}
1 change: 1 addition & 0 deletions src/DebugCodeLens/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { DebugCodeLensProvider } from './DebugCodeLensProvider'
export { TestState } from './TestState'
11 changes: 8 additions & 3 deletions src/IPluginSettings.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { TestState } from './DebugCodeLens'

export interface IPluginSettings {
autoEnable?: boolean
enableCodeLens?: boolean
debugCodeLens: {
enabled: boolean
showWhenTestStateIn: TestState[]
}
enableInlineErrorMessages?: boolean
enableSnapshotPreviews?: boolean
enableSnapshotUpdateMessages?: boolean
pathToJest?: string
pathToConfig?: string
pathToJest?: string
restartJestOnSnapshotUpdate?: boolean
rootPath?: string
runAllTestsFirst?: boolean
showCoverageOnLoad: boolean
restartJestOnSnapshotUpdate?: boolean
}
10 changes: 8 additions & 2 deletions src/JestExt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export class JestExt {
this.coverageOverlay = new CoverageOverlay(this.coverageMapProvider, pluginSettings.showCoverageOnLoad)

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

this.jestProcessManager = new JestProcessManager({
projectWorkspace: workspace,
Expand Down Expand Up @@ -242,7 +245,10 @@ export class JestExt {
this.jestSettings = new Settings(this.workspace)

this.coverageOverlay.enabled = updatedSettings.showCoverageOnLoad
this.debugCodeLensProvider.enabled = updatedSettings.enableCodeLens

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

this.stopProcess()

Expand Down
14 changes: 9 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IPluginSettings } from './IPluginSettings'
import { registerStatusBar } from './statusBar'
import { registerSnapshotCodeLens, registerSnapshotPreview } from './SnapshotCodeLens'
import { registerCoverageCodeLens } from './Coverage'
import { TestState } from './DebugCodeLens'

let extensionInstance: JestExt

Expand Down Expand Up @@ -72,19 +73,22 @@ export function deactivate() {
extensionInstance.deactivate()
}

function getExtensionSettings(): IPluginSettings {
export function getExtensionSettings(): IPluginSettings {
const config = vscode.workspace.getConfiguration('jest')
return {
autoEnable: config.get<boolean>('autoEnable'),
pathToConfig: config.get<string>('pathToConfig'),
pathToJest: config.get<string>('pathToJest'),
enableCodeLens: config.get<boolean>('enableCodeLens'),
debugCodeLens: {
enabled: config.get<boolean>('enableCodeLens'),
showWhenTestStateIn: config.get<TestState[]>('debugCodeLens.showWhenTestStateIn'),
},
enableInlineErrorMessages: config.get<boolean>('enableInlineErrorMessages'),
enableSnapshotPreviews: config.get<boolean>('enableSnapshotPreviews'),
enableSnapshotUpdateMessages: config.get<boolean>('enableSnapshotUpdateMessages'),
pathToConfig: config.get<string>('pathToConfig'),
pathToJest: config.get<string>('pathToJest'),
restartJestOnSnapshotUpdate: config.get<boolean>('restartJestOnSnapshotUpdate'),
rootPath: path.join(vscode.workspace.rootPath, config.get<string>('rootPath')),
runAllTestsFirst: config.get<boolean>('runAllTestsFirst'),
showCoverageOnLoad: config.get<boolean>('showCoverageOnLoad'),
restartJestOnSnapshotUpdate: config.get<boolean>('restartJestOnSnapshotUpdate'),
}
}

0 comments on commit 8b2740a

Please sign in to comment.