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

Add a setting for collecting coverage #330

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Bug-fixes within the same version aren't needed

## Master

* Add a setting for collecting coverage - stephtr
* Adds a setting to control when the debug CodeLens appears - seanpoulter
* Support the "Jest: Start/Stop" and "Show output" commands without an active
text editor - seanpoulter
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"type": "boolean",
"default": true
},
"jest.coverageCollect": {
"description": "Wheter jest should collect test coverage information",
"type": "boolean",
"default": null
},
"jest.showCoverageOnLoad": {
"description": "Show code coverage when extension starts (if collected)",
"type": "boolean",
Expand Down Expand Up @@ -232,7 +237,7 @@
"elegant-spinner": "^1.0.1",
"istanbul-lib-coverage": "^1.1.1",
"istanbul-lib-source-maps": "^1.1.0",
"jest-editor-support": "22.4.0",
"jest-editor-support": "23.0.0-charlie.2",
"jest-snapshot": "^22.1.2",
"jest-test-typescript-parser": "^22.1.3",
"micromatch": "^2.3.11"
Expand Down
1 change: 1 addition & 0 deletions src/IPluginSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IPluginSettings {
restartJestOnSnapshotUpdate?: boolean
rootPath?: string
runAllTestsFirst?: boolean
coverageCollect: boolean
showCoverageOnLoad: boolean
coverageFormatter: string
}
6 changes: 6 additions & 0 deletions src/JestExt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export class JestExt {
this.workspace.rootPath = updatedSettings.rootPath
this.workspace.pathToJest = pathToJest(updatedSettings)
this.workspace.pathToConfig = pathToConfig(updatedSettings)
this.workspace.collectCoverage = updatedSettings.coverageCollect

this.jestSettings = new Settings(this.workspace)

Expand Down Expand Up @@ -549,5 +550,10 @@ export class JestExt {

toggleCoverageOverlay() {
this.coverageOverlay.toggleVisibility()
if (this.coverageOverlay.enabled && !this.workspace.collectCoverage) {
vscode.window.showWarningMessage(
'In order to view the coverage overlay, collectingCoverage has to be enabled in your settings.'
)
}
}
}
3 changes: 2 additions & 1 deletion src/SnapshotCodeLens/SnapshotCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function registerSnapshotCodeLens(enableSnapshotPreviews: boolean) {

class SnapshotCodeLensProvider implements vscode.CodeLensProvider {
public provideCodeLenses(document: vscode.TextDocument, _token: vscode.CancellationToken) {
const snapshots = new Snapshot()
// temporarily use `undefined` as parser argument, until Jest/#6212 is published
const snapshots = new Snapshot(undefined)
return snapshots.getMetadata(document.uri.fsPath).map(snapshot => {
const { line } = snapshot.node.loc.start
const range = new vscode.Range(line - 1, 0, line - 1, 0)
Expand Down
4 changes: 2 additions & 2 deletions src/TestResults/TestResultProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestReconciler, FormattedTestResults } from 'jest-editor-support'
import { TestReconciler, JestTotalResults } from 'jest-editor-support'
import { TestFileAssertionStatus } from 'jest-editor-support'
import { TestReconciliationState } from './TestReconciliationState'
import { TestResult } from './TestResult'
Expand Down Expand Up @@ -99,7 +99,7 @@ export class TestResultProvider {
return result
}

updateTestResults(data: FormattedTestResults): TestFileAssertionStatus[] {
updateTestResults(data: JestTotalResults): TestFileAssertionStatus[] {
this.resetCache()
return this.reconciler.updateFileWithJestStatus(data)
}
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function getExtensionSettings(): IPluginSettings {
restartJestOnSnapshotUpdate: config.get<boolean>('restartJestOnSnapshotUpdate'),
rootPath: path.join(vscode.workspace.rootPath, config.get<string>('rootPath')),
runAllTestsFirst: config.get<boolean>('runAllTestsFirst'),
coverageCollect: config.get<boolean>('coverageCollect'),
showCoverageOnLoad: config.get<boolean>('showCoverageOnLoad'),
coverageFormatter: config.get<string>('coverageFormatter'),
}
Expand Down
1 change: 1 addition & 0 deletions tests/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe('Extension', () => {

expect(getExtensionSettings()).toEqual({
autoEnable: true,
coverageCollect: null,
coverageFormatter: 'DefaultFormatter',
debugCodeLens: {
enabled: true,
Expand Down
41 changes: 0 additions & 41 deletions typings/jest-editor-support.d.ts

This file was deleted.