Skip to content

Commit

Permalink
Merge 790f33d into 7964a9d
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRooney committed May 11, 2018
2 parents 7964a9d + 790f33d commit cb4a628
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Bug-fixes within the same version aren't needed

## Master

* Highlight the full line of the jest error, not just the first 6 characters - ThomasRooney

### 2.7.0

* Add the ability to configure debugging of tests - stephtr, connectdotz
Expand Down
11 changes: 9 additions & 2 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ export function updateDiagnostics(testResults: TestFileAssertionStatus[], diagno
`received invalid line number '${assertion.line}' for '${uri.toString()}'. (most likely due to unexpected test results... you can help fix the root cause by logging an issue with a sample project to reproduce this warning)`
)
}
const start = 0
let startColumn = 0
let endColumn = Number.MAX_SAFE_INTEGER
const associatedTextEditor = vscode.window.visibleTextEditors.find(e => e.document.uri.fsPath === uri.fsPath)
if (associatedTextEditor) {
const textLine = associatedTextEditor.document.lineAt(line)
startColumn = textLine.firstNonWhitespaceCharacterIndex
endColumn = textLine.text.length
}
const diag = new vscode.Diagnostic(
new vscode.Range(line, start, line, start + 6),
new vscode.Range(line, startColumn, line, endColumn),
assertion.terseMessage || assertion.shortMessage || assertion.message,
vscode.DiagnosticSeverity.Error
)
Expand Down
24 changes: 23 additions & 1 deletion tests/diagnostics.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
jest.unmock('../src/diagnostics')

import { updateDiagnostics, resetDiagnostics, failedSuiteCount } from '../src/diagnostics'
import * as vscode from 'vscode'
import { TestFileAssertionStatus, TestReconcilationState, TestAssertionStatus } from 'jest-editor-support'
Expand All @@ -15,6 +14,8 @@ class MockDiagnosticCollection implements vscode.DiagnosticCollection {
dispose = jest.fn()
}

vscode.window.visibleTextEditors = []

describe('test diagnostics', () => {
describe('resetDiagnostics', () => {
it('will clear given diagnostics', () => {
Expand Down Expand Up @@ -164,5 +165,26 @@ describe('test diagnostics', () => {
validateRange(rangeCalls[0], 0, 0)
})
})

it('should highlight the full line', () => {
const mockDiagnostics = new MockDiagnosticCollection()
const assertion = createAssertion('a', 'KnownFail')
const tests = [createTestResult('f', [assertion])]
vscode.Uri.file = jest.fn(() => ({ fsPath: 'f' }))
vscode.window.visibleTextEditors = [
{
document: {
lineAt: jest.fn(() => ({
firstNonWhitespaceCharacterIndex: 2,
text: ' text',
})),
uri: { fsPath: 'f' },
},
},
] as any[]
updateDiagnostics(tests, mockDiagnostics)
expect(vscode.window.visibleTextEditors[0].document.lineAt).toHaveBeenCalled()
expect(vscode.Range).toHaveBeenCalledWith(assertion.line - 1, 2, assertion.line - 1, 6)
})
})
})

0 comments on commit cb4a628

Please sign in to comment.