forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestFiles.unit.test.ts
More file actions
157 lines (148 loc) · 6.77 KB
/
testFiles.unit.test.ts
File metadata and controls
157 lines (148 loc) · 6.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// 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: Uri.file('path/to/document2').fsPath
};
const tests = {
testFiles: [
{
fullPath: Uri.file('path/to/document1').fsPath
},
testFile2
]
};
workspaceService
.setup((w) => w.getWorkspaceFolder(typemoq.It.isValue(document.uri)))
.returns(() => workspace as any)
.verifiable(typemoq.Times.once());
testCollectionStorage
.setup((w) => w.getTests(typemoq.It.isValue(workspaceUri)))
.returns(() => tests as any)
.verifiable(typemoq.Times.once());
fileSystem
.setup((f) => f.arePathsSame(Uri.file('/path/to/document1').fsPath, Uri.file('/path/to/document2').fsPath))
.returns(() => false);
fileSystem
.setup((f) => f.arePathsSame(Uri.file('/path/to/document2').fsPath, Uri.file('/path/to/document2').fsPath))
.returns(() => true);
const files = codeLensProvider.getTestFileWhichNeedsCodeLens(document as any);
assert.deepEqual(files, testFile2 as any);
workspaceService.verifyAll();
testCollectionStorage.verifyAll();
});
});