-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f4631f
commit 77d19a8
Showing
5 changed files
with
110 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
jest.unmock('../../src/Coverage/CoverageCodeLensProvider') | ||
|
||
// tslint:disable max-classes-per-file | ||
const rangeConstructor = jest.fn() | ||
jest.mock('vscode', () => { | ||
class CodeLens { | ||
range: any | ||
command: any | ||
|
||
constructor(range, command) { | ||
this.range = range | ||
this.command = command | ||
} | ||
} | ||
|
||
// class EventEmitter { | ||
// fire() {} | ||
// } | ||
|
||
class Position { | ||
lineNumber: string | ||
character: string | ||
|
||
constructor(lineNumber, character) { | ||
this.lineNumber = lineNumber | ||
this.character = character | ||
} | ||
} | ||
|
||
class Range { | ||
start: Position | ||
end: Position | ||
|
||
constructor(start, end) { | ||
rangeConstructor(...arguments) | ||
this.start = start | ||
this.end = end | ||
} | ||
} | ||
|
||
return { | ||
CodeLens, | ||
Position, | ||
Range, | ||
} | ||
}) | ||
|
||
import { CoverageCodeLensProvider } from '../../src/Coverage/CoverageCodeLensProvider' | ||
|
||
// import * as vscode from 'vscode' | ||
|
||
describe('CoverageCodeLensProvider', () => { | ||
let mockJestExt | ||
let provider | ||
|
||
beforeEach(() => { | ||
mockJestExt = { | ||
coverageMapProvider: { getFileCoverage: jest.fn() }, | ||
} | ||
const mockGetExt = jest.fn().mockReturnValue(mockJestExt) | ||
provider = new CoverageCodeLensProvider(mockGetExt) | ||
}) | ||
describe('provideCodeLenses', () => { | ||
const doc = { fileName: 'file.js' } | ||
|
||
test('do nothing when no coverage', () => { | ||
mockJestExt.coverageMapProvider.getFileCoverage = () => null | ||
const result = provider.provideCodeLenses(doc) | ||
expect(result).toBeUndefined() | ||
}) | ||
|
||
test('can summarize', () => { | ||
const coverage = { | ||
toSummary: () => ({ | ||
toJSON: () => ({ | ||
branches: { pct: 10 }, | ||
lines: { pct: 46.15 }, | ||
}), | ||
}), | ||
} | ||
mockJestExt.coverageMapProvider.getFileCoverage = () => coverage | ||
const result = provider.provideCodeLenses(doc) | ||
expect(result).toHaveLength(1) | ||
expect(result[0].command.title).toEqual('branches: 10%, lines: 46.15%') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters