Repository navigation
Fix code lens bug #6755
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
Merged
Merged
Fix code lens bug #6755
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| Fix code lenses shown for pytest |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,158 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // tslint:disable:no-any | ||
|
|
||
| import { assert, expect } from 'chai'; | ||
| import { mock } from 'ts-mockito'; | ||
| import * as typemoq from 'typemoq'; | ||
| import { DocumentSymbolProvider, EventEmitter, Uri } from 'vscode'; | ||
| import { IWorkspaceService } from '../../../client/common/application/types'; | ||
| import { IFileSystem } from '../../../client/common/platform/types'; | ||
| import { IServiceContainer } from '../../../client/ioc/types'; | ||
| import { LanguageServerSymbolProvider } from '../../../client/providers/symbolProvider'; | ||
| import { TestFileCodeLensProvider } from '../../../client/testing/codeLenses/testFiles'; | ||
| import { ITestCollectionStorageService } from '../../../client/testing/common/types'; | ||
|
|
||
| // tslint:disable-next-line: max-func-body-length | ||
| suite('Code lenses - Test files', () => { | ||
| let testCollectionStorage: typemoq.IMock<ITestCollectionStorageService>; | ||
| let workspaceService: typemoq.IMock<IWorkspaceService>; | ||
| let fileSystem: typemoq.IMock<IFileSystem>; | ||
| let serviceContainer: typemoq.IMock<IServiceContainer>; | ||
| let symbolProvider: DocumentSymbolProvider; | ||
| let onDidChange: EventEmitter<void>; | ||
| let codeLensProvider: TestFileCodeLensProvider; | ||
| setup(() => { | ||
| workspaceService = typemoq.Mock.ofType<IWorkspaceService>(); | ||
| fileSystem = typemoq.Mock.ofType<IFileSystem>(); | ||
| testCollectionStorage = typemoq.Mock.ofType<ITestCollectionStorageService>(); | ||
| serviceContainer = typemoq.Mock.ofType<IServiceContainer>(); | ||
| symbolProvider = mock(LanguageServerSymbolProvider); | ||
| onDidChange = new EventEmitter<void>(); | ||
| serviceContainer | ||
| .setup(c => c.get(typemoq.It.isValue(IWorkspaceService))) | ||
| .returns(() => workspaceService.object); | ||
| serviceContainer | ||
| .setup(c => c.get(typemoq.It.isValue(IFileSystem))) | ||
| .returns(() => fileSystem.object); | ||
| codeLensProvider = new TestFileCodeLensProvider(onDidChange, symbolProvider, testCollectionStorage.object, serviceContainer.object); | ||
| }); | ||
|
|
||
| teardown(() => { | ||
| onDidChange.dispose(); | ||
| }); | ||
|
|
||
| test('Function getTestFileWhichNeedsCodeLens() returns `undefined` if there are no workspace corresponding to document', async () => { | ||
| const document = { | ||
| uri: Uri.file('path/to/document') | ||
| }; | ||
| workspaceService | ||
| .setup(w => w.getWorkspaceFolder(document.uri)) | ||
| .returns(() => undefined) | ||
| .verifiable(typemoq.Times.once()); | ||
| testCollectionStorage | ||
| .setup(w => w.getTests(typemoq.It.isAny())) | ||
| .returns(() => undefined) | ||
| .verifiable(typemoq.Times.never()); | ||
| const files = codeLensProvider.getTestFileWhichNeedsCodeLens(document as any); | ||
| expect(files).to.equal(undefined, 'No files should be returned'); | ||
| workspaceService.verifyAll(); | ||
| testCollectionStorage.verifyAll(); | ||
| }); | ||
|
|
||
| test('Function getTestFileWhichNeedsCodeLens() returns `undefined` if test storage is empty', async () => { | ||
| const document = { | ||
| uri: Uri.file('path/to/document') | ||
| }; | ||
| const workspaceUri = Uri.file('path/to/workspace'); | ||
| const workspace = { uri: workspaceUri }; | ||
| workspaceService | ||
| .setup(w => w.getWorkspaceFolder(document.uri)) | ||
| .returns(() => workspace as any) | ||
| .verifiable(typemoq.Times.once()); | ||
| testCollectionStorage | ||
| .setup(w => w.getTests(workspaceUri)) | ||
| .returns(() => undefined) | ||
| .verifiable(typemoq.Times.once()); | ||
| const files = codeLensProvider.getTestFileWhichNeedsCodeLens(document as any); | ||
| expect(files).to.equal(undefined, 'No files should be returned'); | ||
| workspaceService.verifyAll(); | ||
| testCollectionStorage.verifyAll(); | ||
| }); | ||
|
|
||
| test('Function getTestFileWhichNeedsCodeLens() returns `undefined` if tests returned from storage does not contain document', async () => { | ||
| const document = { | ||
| uri: Uri.file('path/to/document5') | ||
| }; | ||
| const workspaceUri = Uri.file('path/to/workspace'); | ||
| const workspace = { uri: workspaceUri }; | ||
| const tests = { | ||
| testFiles: [ | ||
| { | ||
| fullPath: 'path/to/document1' | ||
| }, | ||
| { | ||
| fullPath: 'path/to/document2' | ||
| } | ||
| ] | ||
| }; | ||
| workspaceService | ||
| .setup(w => w.getWorkspaceFolder(document.uri)) | ||
| .returns(() => workspace as any) | ||
| .verifiable(typemoq.Times.once()); | ||
| testCollectionStorage | ||
| .setup(w => w.getTests(workspaceUri)) | ||
| .returns(() => tests as any) | ||
| .verifiable(typemoq.Times.once()); | ||
| fileSystem | ||
| .setup(f => f.arePathsSame('path/to/document1', 'path/to/document5')) | ||
| .returns(() => false); | ||
| fileSystem | ||
| .setup(f => f.arePathsSame('path/to/document2', 'path/to/document5')) | ||
| .returns(() => false); | ||
| const files = codeLensProvider.getTestFileWhichNeedsCodeLens(document as any); | ||
| expect(files).to.equal(undefined, 'No files should be returned'); | ||
| workspaceService.verifyAll(); | ||
| testCollectionStorage.verifyAll(); | ||
| }); | ||
|
|
||
| test('Function getTestFileWhichNeedsCodeLens() returns test file if tests returned from storage contains document', async () => { | ||
| const document = { | ||
| uri: Uri.file('path/to/document2') | ||
| }; | ||
| const workspaceUri = Uri.file('path/to/workspace'); | ||
| const workspace = { uri: workspaceUri }; | ||
| const testFile2 = { | ||
| fullPath: 'path/to/document2' | ||
| }; | ||
| const tests = { | ||
| testFiles: [ | ||
| { | ||
| fullPath: 'path/to/document1' | ||
| }, | ||
| testFile2 | ||
| ] | ||
| }; | ||
| workspaceService | ||
| .setup(w => w.getWorkspaceFolder(document.uri)) | ||
| .returns(() => workspace as any) | ||
| .verifiable(typemoq.Times.once()); | ||
| testCollectionStorage | ||
| .setup(w => w.getTests(workspaceUri)) | ||
| .returns(() => tests as any) | ||
| .verifiable(typemoq.Times.once()); | ||
| fileSystem | ||
| .setup(f => f.arePathsSame('path/to/document1', 'path/to/document2')) | ||
| .returns(() => false); | ||
| fileSystem | ||
| .setup(f => f.arePathsSame('path/to/document2', 'path/to/document2')) | ||
| .returns(() => true); | ||
| const files = codeLensProvider.getTestFileWhichNeedsCodeLens(document as any); | ||
| assert.deepEqual(files, testFile2 as any); | ||
| workspaceService.verifyAll(); | ||
| testCollectionStorage.verifyAll(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.