@@ -8,54 +8,33 @@ import reportIssue from '../../../src/shared/reportIssue';
8
8
import { FakeMonoResolver , fakeMonoInfo } from '../../omnisharpUnitTests/fakes/fakeMonoResolver' ;
9
9
import { FakeDotnetResolver } from '../../omnisharpUnitTests/fakes/fakeDotnetResolver' ;
10
10
import { DotnetInfo } from '../../../src/shared/utils/dotnetInfo' ;
11
- import { getFakeVsCode } from '../../../test/unitTests/fakes' ;
12
-
13
- jest . resetAllMocks ( ) ;
14
- jest . mock ( 'vscode' , ( ) => ( {
15
- workspace : {
16
- getConfiguration : jest . fn ( ( _ ) => {
17
- return {
18
- get : jest . fn ( ( _ ) => {
19
- console . log ( 'test1' ) ;
20
- return undefined ;
21
- } ) ,
22
- } ;
23
- } ) ,
24
- executeCommand : jest . fn ( ( command : string , ...rest : any [ ] ) => {
25
- console . log ( 'test2' ) ;
26
- return undefined ;
27
- } ) ,
28
- } ,
29
- extensions : {
30
- all : [
31
- {
32
- packageJSON : {
33
- name : 'name1' ,
34
- publisher : 'publisher1' ,
35
- version : 'version1' ,
36
- isBuiltin : true ,
37
- } ,
38
- id : 'id1' ,
39
- extensionPath : 'c:/extensions/abc-x64' ,
40
- } ,
41
- {
42
- packageJSON : {
43
- name : 'name2' ,
44
- publisher : 'publisher2' ,
45
- version : 'version2' ,
46
- isBuiltin : false ,
47
- } ,
48
- id : 'id2' ,
49
- extensionPath : 'c:/extensions/xyz-x64' ,
50
- } ,
51
- ] ,
52
- } ,
53
- } ) ) ;
11
+ import { jest , describe , test , expect , beforeEach } from '@jest/globals' ;
54
12
55
13
describe ( `${ reportIssue . name } ` , ( ) => {
56
14
const vscodeVersion = 'myVersion' ;
57
15
const csharpExtVersion = 'csharpExtVersion' ;
58
16
const isValidForMono = true ;
17
+ const extension1 = {
18
+ packageJSON : {
19
+ name : 'name1' ,
20
+ publisher : 'publisher1' ,
21
+ version : 'version1' ,
22
+ isBuiltin : true ,
23
+ } ,
24
+ id : 'id1' ,
25
+ extensionPath : 'c:/extensions/abc-x64' ,
26
+ } as vscode . Extension < any > ;
27
+
28
+ const extension2 = {
29
+ packageJSON : {
30
+ name : 'name2' ,
31
+ publisher : 'publisher2' ,
32
+ version : 'version2' ,
33
+ isBuiltin : false ,
34
+ } ,
35
+ id : 'id2' ,
36
+ extensionPath : 'c:/extensions/xyz-x64' ,
37
+ } as vscode . Extension < any > ;
59
38
60
39
const fakeDotnetInfo : DotnetInfo = {
61
40
FullInfo : 'myDotnetInfo' ,
@@ -70,134 +49,69 @@ describe(`${reportIssue.name}`, () => {
70
49
let issueBody : string ;
71
50
72
51
beforeEach ( ( ) => {
73
- //jest.resetAllMocks();
74
- // jest.mock('vscode', () => ({
75
- // workspace: {
76
- // getConfiguration: jest.fn((_) => {
77
- // return {
78
- // get: jest.fn((_) => {
79
- // console.log('test1');
80
- // return undefined;
81
- // }),
82
- // };
83
- // }),
84
- // executeCommand: jest.fn((command: string, ...rest: any[]) => {
85
- // issueBody = rest[0].issueBody;
86
- // return undefined;
87
- // }),
88
- // },
89
- // extensions: {
90
- // all: [
91
- // {
92
- // packageJSON: {
93
- // name: 'name1',
94
- // publisher: 'publisher1',
95
- // version: 'version1',
96
- // isBuiltin: true,
97
- // },
98
- // id: 'id1',
99
- // extensionPath: 'c:/extensions/abc-x64',
100
- // },
101
- // {
102
- // packageJSON: {
103
- // name: 'name2',
104
- // publisher: 'publisher2',
105
- // version: 'version2',
106
- // isBuiltin: false,
107
- // },
108
- // id: 'id2',
109
- // extensionPath: 'c:/extensions/xyz-x64',
110
- // },
111
- // ],
112
- // },
113
- // }));
52
+ jest . spyOn ( vscode . workspace , 'getConfiguration' ) . mockReturnValue ( {
53
+ get : jest . fn ( ( _config : string ) => {
54
+ return undefined ;
55
+ } ) ,
56
+ has : jest . fn ( ) ,
57
+ inspect : jest . fn ( ) ,
58
+ update : jest . fn ( ) ,
59
+ } as vscode . WorkspaceConfiguration ) ;
60
+
61
+ jest . spyOn ( vscode . commands , 'executeCommand' ) . mockImplementation ( async ( command : string , ...rest : any [ ] ) => {
62
+ issueBody = rest [ 0 ] . issueBody ;
63
+ return { } as any ;
64
+ } ) ;
65
+ jest . replaceProperty ( vscode , 'extensions' , {
66
+ all : [ extension1 , extension2 ] ,
67
+ getExtension : jest . fn ( ) ,
68
+ onDidChange : jest . fn ( ) ,
69
+ } as typeof vscode . extensions ) ;
114
70
115
71
fakeMonoResolver = new FakeMonoResolver ( ) ;
116
72
fakeDotnetResolver = new FakeDotnetResolver ( ) ;
117
73
} ) ;
118
74
119
75
describe ( 'The body is passed to the vscode clipboard and' , ( ) => {
120
76
test ( 'it contains the vscode version' , async ( ) => {
121
- await reportIssue (
122
- vscode ,
123
- csharpExtVersion ,
124
- getDotnetInfo ,
125
- isValidForMono ,
126
- fakeDotnetResolver ,
127
- fakeMonoResolver
128
- ) ;
77
+ await reportIssue ( csharpExtVersion , getDotnetInfo , isValidForMono , fakeDotnetResolver , fakeMonoResolver ) ;
129
78
expect ( issueBody ) . toContain ( `**VSCode version**: ${ vscodeVersion } ` ) ;
130
79
} ) ;
131
80
132
81
test ( 'it contains the csharp extension version' , async ( ) => {
133
- await reportIssue (
134
- vscode ,
135
- csharpExtVersion ,
136
- getDotnetInfo ,
137
- isValidForMono ,
138
- fakeDotnetResolver ,
139
- fakeMonoResolver
140
- ) ;
82
+ await reportIssue ( csharpExtVersion , getDotnetInfo , isValidForMono , fakeDotnetResolver , fakeMonoResolver ) ;
141
83
expect ( issueBody ) . toContain ( `**C# Extension**: ${ csharpExtVersion } ` ) ;
142
84
} ) ;
143
85
144
86
test ( 'it contains dotnet info' , async ( ) => {
145
- await reportIssue (
146
- vscode ,
147
- csharpExtVersion ,
148
- getDotnetInfo ,
149
- isValidForMono ,
150
- fakeDotnetResolver ,
151
- fakeMonoResolver
152
- ) ;
87
+ await reportIssue ( csharpExtVersion , getDotnetInfo , isValidForMono , fakeDotnetResolver , fakeMonoResolver ) ;
153
88
expect ( issueBody ) . toContain ( fakeDotnetInfo . FullInfo ) ;
154
89
} ) ;
155
90
156
91
test ( 'mono information is obtained when it is a valid mono platform' , async ( ) => {
157
- await reportIssue (
158
- vscode ,
159
- csharpExtVersion ,
160
- getDotnetInfo ,
161
- isValidForMono ,
162
- fakeDotnetResolver ,
163
- fakeMonoResolver
164
- ) ;
92
+ await reportIssue ( csharpExtVersion , getDotnetInfo , isValidForMono , fakeDotnetResolver , fakeMonoResolver ) ;
165
93
expect ( fakeMonoResolver . getMonoCalled ) . toEqual ( true ) ;
166
94
} ) ;
167
95
168
96
test ( 'mono version is put in the body when it is a valid mono platform' , async ( ) => {
169
- await reportIssue (
170
- vscode ,
171
- csharpExtVersion ,
172
- getDotnetInfo ,
173
- isValidForMono ,
174
- fakeDotnetResolver ,
175
- fakeMonoResolver
176
- ) ;
97
+ await reportIssue ( csharpExtVersion , getDotnetInfo , isValidForMono , fakeDotnetResolver , fakeMonoResolver ) ;
177
98
expect ( fakeMonoResolver . getMonoCalled ) . toEqual ( true ) ;
178
- expect ( issueBody ) . toEqual ( fakeMonoInfo . version ) ;
99
+ expect ( issueBody ) . toContain ( fakeMonoInfo . version ) ;
179
100
} ) ;
180
101
181
102
test ( 'mono information is not obtained when it is not a valid mono platform' , async ( ) => {
182
- await reportIssue ( vscode , csharpExtVersion , getDotnetInfo , false , fakeDotnetResolver , fakeMonoResolver ) ;
103
+ await reportIssue ( csharpExtVersion , getDotnetInfo , false , fakeDotnetResolver , fakeMonoResolver ) ;
183
104
expect ( fakeMonoResolver . getMonoCalled ) . toEqual ( false ) ;
184
105
} ) ;
185
106
186
107
test ( 'The url contains the name, publisher and version for all the extensions that are not builtin' , async ( ) => {
187
- await reportIssue (
188
- vscode ,
189
- csharpExtVersion ,
190
- getDotnetInfo ,
191
- isValidForMono ,
192
- fakeDotnetResolver ,
193
- fakeMonoResolver
194
- ) ;
195
- expect ( issueBody ) . toContain ( getFakeVsCode ( ) . extensions . all [ 2 ] . packageJSON . name ) ;
196
- expect ( issueBody ) . toContain ( getFakeVsCode ( ) . extensions . all [ 2 ] . packageJSON . publisher ) ;
197
- expect ( issueBody ) . toContain ( getFakeVsCode ( ) . extensions . all [ 2 ] . packageJSON . version ) ;
198
- expect ( issueBody ) . toContain ( getFakeVsCode ( ) . extensions . all [ 1 ] . packageJSON . name ) ;
199
- expect ( issueBody ) . toContain ( getFakeVsCode ( ) . extensions . all [ 1 ] . packageJSON . publisher ) ;
200
- expect ( issueBody ) . toContain ( getFakeVsCode ( ) . extensions . all [ 1 ] . packageJSON . version ) ;
108
+ await reportIssue ( csharpExtVersion , getDotnetInfo , isValidForMono , fakeDotnetResolver , fakeMonoResolver ) ;
109
+ expect ( issueBody ) . toContain ( extension2 . packageJSON . name ) ;
110
+ expect ( issueBody ) . toContain ( extension2 . packageJSON . publisher ) ;
111
+ expect ( issueBody ) . toContain ( extension2 . packageJSON . version ) ;
112
+ expect ( issueBody ) . not . toContain ( extension1 . packageJSON . name ) ;
113
+ expect ( issueBody ) . not . toContain ( extension1 . packageJSON . publisher ) ;
114
+ expect ( issueBody ) . not . toContain ( extension1 . packageJSON . version ) ;
201
115
} ) ;
202
116
} ) ;
203
117
} ) ;
0 commit comments