Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show skipped test information #138

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 28 additions & 34 deletions src/JestExt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class JestExt {

private passingItStyle: vscode.TextEditorDecorationType
private failingItStyle: vscode.TextEditorDecorationType
private skipItStyle: vscode.TextEditorDecorationType
private unknownItStyle: vscode.TextEditorDecorationType

private parsingTestFile = false
Expand Down Expand Up @@ -187,9 +188,10 @@ export class JestExt {
this.parsingTestFile = true

// This makes it cheaper later down the line
let successes: Array<ItBlock> = []
const successes: Array<ItBlock> = []
const fails: Array<ItBlock> = []
let unknowns: Array<ItBlock> = []
const skips: Array<ItBlock> = []
const unknowns: Array<ItBlock> = []

// Parse the current JS file
const path = editor.document.uri.fsPath
Expand All @@ -203,45 +205,34 @@ export class JestExt {
// Loop through our it/test references, then ask the reconciler ( the thing
// that reads the JSON from Jest ) whether it has passed/failed/not ran.
const filePath = editor.document.uri.fsPath
const fileState = this.reconciler.stateForTestFile(filePath)
switch (fileState) {
// If the file failed, then it can contain passes, fails and unknowns
case TestReconciliationState.KnownFail:
itBlocks.forEach(it => {
const state = this.reconciler.stateForTestAssertion(filePath, it.name)
if (state !== null) {
switch (state.status) {
case TestReconciliationState.KnownSuccess:
successes.push(it)
break
case TestReconciliationState.KnownFail:
fails.push(it)
break
case TestReconciliationState.Unknown:
unknowns.push(it)
break
}
} else {
itBlocks.forEach(it => {
const state = this.reconciler.stateForTestAssertion(filePath, it.name)
if (state !== null) {
switch (state.status) {
case TestReconciliationState.KnownSuccess:
successes.push(it)
break
case TestReconciliationState.KnownFail:
fails.push(it)
break
case TestReconciliationState.KnownSkip:
skips.push(it)
break
case TestReconciliationState.Unknown:
unknowns.push(it)
}
})
break
// Test passed, all it's must be green
case TestReconciliationState.KnownSuccess:
successes = itBlocks
break

// We don't know, not ran probably
case TestReconciliationState.Unknown:
unknowns = itBlocks
break
}
break
}
} else {
unknowns.push(it)
}
})

// Create a map for the states and styles to show inline.
// Note that this specifically is only for dots.
const styleMap = [
{ data: successes, decorationType: this.passingItStyle, state: TestReconciliationState.KnownSuccess },
{ data: fails, decorationType: this.failingItStyle, state: TestReconciliationState.KnownFail },
{ data: skips, decorationType: this.skipItStyle, state: TestReconciliationState.KnownSkip },
{ data: unknowns, decorationType: this.unknownItStyle, state: TestReconciliationState.Unknown },
]
styleMap.forEach(style => {
Expand Down Expand Up @@ -351,6 +342,7 @@ export class JestExt {
private setupDecorators() {
this.passingItStyle = decorations.passingItName()
this.failingItStyle = decorations.failingItName()
this.skipItStyle = decorations.skipItName()
this.unknownItStyle = decorations.notRanItName()
}

Expand Down Expand Up @@ -381,6 +373,8 @@ export class JestExt {
return 'Passed'
case TestReconciliationState.KnownFail:
return 'Failed'
case TestReconciliationState.KnownSkip:
return 'Skipped'
case TestReconciliationState.Unknown:
return 'Test has not run yet, due to Jest only running tests related to changes.'
}
Expand Down
3 changes: 2 additions & 1 deletion src/TestReconciliationState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type TestReconciliationState = 'Unknown' | 'KnownSuccess' | 'KnownFail'
export type TestReconciliationState = 'Unknown' | 'KnownSuccess' | 'KnownFail' | 'KnownSkip'
export const TestReconciliationState = {
Unknown: 'Unknown' as TestReconciliationState,
KnownSuccess: 'KnownSuccess' as TestReconciliationState,
KnownFail: 'KnownFail' as TestReconciliationState,
KnownSkip: 'KnownSkip' as TestReconciliationState,
}
19 changes: 19 additions & 0 deletions src/decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ export function failingItName() {
})
}

export function skipItName() {
return window.createTextEditorDecorationType({
overviewRulerColor: 'yellow',
overviewRulerLane: OverviewRulerLane.Left,
light: {
before: {
color: '#fed37f',
contentText: '○',
},
},
dark: {
before: {
color: '#fed37f',
contentText: '○',
},
},
})
}

export function passingItName() {
return window.createTextEditorDecorationType({
overviewRulerColor: 'green',
Expand Down
3 changes: 2 additions & 1 deletion tests/JestExt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('JestExt', () => {
const getConfiguration = workspace.getConfiguration as jest.Mock<any>
let projectWorkspace: ProjectWorkspace
const channelStub = { appendLine: () => {} } as any
const mockShowErrorMessage = window.showErrorMessage as jest.Mock<any>

beforeEach(() => {
jest.resetAllMocks()
Expand All @@ -24,7 +25,7 @@ describe('JestExt', () => {
jestVersionMajor: 17,
}))
new JestExt(projectWorkspace, channelStub, {})
expect(window.showErrorMessage.mock.calls).toMatchSnapshot()
expect(mockShowErrorMessage.mock.calls).toMatchSnapshot()
})

it.skip('should not show error message if jest version is 20', () => {
Expand Down