@@ -12,6 +12,7 @@ import * as jsonc from 'jsonc-parser';
12
12
import { AssetGenerator , ProgramLaunchType , replaceCommentPropertiesWithComments , updateJsonWithComments } from '../../src/assets' ;
13
13
import { parse } from 'jsonc-parser' ;
14
14
import { use as chaiUse , should } from 'chai' ;
15
+ import { isNotNull } from '../testUtil' ;
15
16
16
17
chaiUse ( require ( 'chai-string' ) ) ;
17
18
@@ -24,6 +25,8 @@ suite("Asset generation: csproj", () => {
24
25
let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
25
26
generator . setStartupProject ( 0 ) ;
26
27
let tasksJson = generator . createTasksConfiguration ( ) ;
28
+ isNotNull ( tasksJson . tasks ) ;
29
+ isNotNull ( tasksJson . tasks [ 0 ] . args ) ;
27
30
let buildPath = tasksJson . tasks [ 0 ] . args [ 1 ] ;
28
31
29
32
// ${workspaceFolder}/project.json
@@ -37,11 +40,12 @@ suite("Asset generation: csproj", () => {
37
40
let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
38
41
generator . setStartupProject ( 0 ) ;
39
42
let tasksJson = generator . createTasksConfiguration ( ) ;
43
+ isNotNull ( tasksJson . tasks ) ;
40
44
41
45
// We do not check the watch task since this parameter can break hot reload scenarios.
42
46
tasksJson . tasks
43
47
. filter ( task => task . label !== "watch" )
44
- . forEach ( task => task . args . should . contain ( "/property:GenerateFullPaths=true" ) ) ;
48
+ . forEach ( task => task . args ! . should . contain ( "/property:GenerateFullPaths=true" ) ) ;
45
49
} ) ;
46
50
47
51
test ( "Generated 'build' and 'publish' tasks have the consoleloggerparameters argument set to NoSummary" , ( ) => {
@@ -50,11 +54,12 @@ suite("Asset generation: csproj", () => {
50
54
let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
51
55
generator . setStartupProject ( 0 ) ;
52
56
let tasksJson = generator . createTasksConfiguration ( ) ;
57
+ isNotNull ( tasksJson . tasks ) ;
53
58
54
59
// We do not check the watch task since this parameter can break hot reload scenarios.
55
60
tasksJson . tasks
56
61
. filter ( task => task . label !== "watch" )
57
- . forEach ( task => task . args . should . contain ( "/consoleloggerparameters:NoSummary" ) ) ;
62
+ . forEach ( task => task . args ! . should . contain ( "/consoleloggerparameters:NoSummary" ) ) ;
58
63
} ) ;
59
64
60
65
test ( "Generated 'watch' task does not have the property GenerateFullPaths set to true " , ( ) => {
@@ -63,8 +68,10 @@ suite("Asset generation: csproj", () => {
63
68
let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
64
69
generator . setStartupProject ( 0 ) ;
65
70
let tasksJson = generator . createTasksConfiguration ( ) ;
71
+ isNotNull ( tasksJson . tasks ) ;
66
72
67
73
const watchTask = tasksJson . tasks . find ( task => task . label === "watch" ) ;
74
+ isNotNull ( watchTask ?. args ) ;
68
75
watchTask . args . should . not . contain ( "/property:GenerateFullPaths=true" ) ;
69
76
} ) ;
70
77
@@ -75,7 +82,8 @@ suite("Asset generation: csproj", () => {
75
82
generator . setStartupProject ( 0 ) ;
76
83
let tasksJson = generator . createTasksConfiguration ( ) ;
77
84
78
- const watchTask = tasksJson . tasks . find ( task => task . label === "watch" ) ;
85
+ const watchTask = tasksJson . tasks ! . find ( task => task . label === "watch" ) ;
86
+ isNotNull ( watchTask ?. args ) ;
79
87
watchTask . args . should . not . contain ( "/consoleloggerparameters:NoSummary" ) ;
80
88
} ) ;
81
89
@@ -85,6 +93,8 @@ suite("Asset generation: csproj", () => {
85
93
let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
86
94
generator . setStartupProject ( 0 ) ;
87
95
let tasksJson = generator . createTasksConfiguration ( ) ;
96
+ isNotNull ( tasksJson . tasks ) ;
97
+ isNotNull ( tasksJson . tasks [ 0 ] . args ) ;
88
98
let buildPath = tasksJson . tasks [ 0 ] . args [ 1 ] ;
89
99
90
100
// ${workspaceFolder}/nested/project.json
@@ -100,7 +110,7 @@ suite("Asset generation: csproj", () => {
100
110
let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Console ) , undefined , { disallowComments : true } ) ;
101
111
let programPath : string = launchJson [ 0 ] . program ;
102
112
103
- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
113
+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
104
114
} ) ;
105
115
106
116
[ 5 , 6 , 7 , 8 , 9 ] . forEach ( version => {
@@ -114,7 +124,7 @@ suite("Asset generation: csproj", () => {
114
124
let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Console ) , undefined , { disallowComments : true } ) ;
115
125
let programPath : string = launchJson [ 0 ] . program ;
116
126
117
- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
127
+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
118
128
} ) ;
119
129
} ) ;
120
130
@@ -126,7 +136,7 @@ suite("Asset generation: csproj", () => {
126
136
let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Console ) , undefined , { disallowComments : true } ) ;
127
137
let programPath : string = launchJson [ 0 ] . program ;
128
138
129
- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
139
+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
130
140
} ) ;
131
141
132
142
test ( "Create launch.json for project opened in workspace with non-relative output path" , function ( ) {
@@ -142,7 +152,7 @@ suite("Asset generation: csproj", () => {
142
152
let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Console ) , undefined , { disallowComments : true } ) ;
143
153
let programPath : string = launchJson [ 0 ] . program ;
144
154
145
- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
155
+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
146
156
} ) ;
147
157
148
158
test ( "Create launch.json for Blazor web assembly standalone project opened in workspace" , ( ) => {
@@ -180,7 +190,7 @@ suite("Asset generation: csproj", () => {
180
190
const cwd = hostedBlazorLaunchConfig . cwd ;
181
191
const hosted = hostedBlazorLaunchConfig . hosted ;
182
192
183
- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
193
+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
184
194
185
195
cwd . should . equal ( '${workspaceFolder}' ) ;
186
196
hosted . should . equal ( true ) ;
@@ -197,7 +207,7 @@ suite("Asset generation: csproj", () => {
197
207
const cwd = hostedBlazorLaunchConfig . cwd ;
198
208
const hosted = hostedBlazorLaunchConfig . hosted ;
199
209
200
- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
210
+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
201
211
202
212
cwd . should . equal ( '${workspaceFolder}/nested' ) ;
203
213
hosted . should . equal ( true ) ;
@@ -211,7 +221,7 @@ suite("Asset generation: csproj", () => {
211
221
let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Web ) , undefined , { disallowComments : true } ) ;
212
222
let programPath : string = launchJson [ 0 ] . program ;
213
223
214
- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
224
+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
215
225
} ) ;
216
226
217
227
test ( "Create launch.json for nested web project opened in workspace" , ( ) => {
@@ -222,7 +232,7 @@ suite("Asset generation: csproj", () => {
222
232
let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Web ) , undefined , { disallowComments : true } ) ;
223
233
let programPath : string = launchJson [ 0 ] . program ;
224
234
225
- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
235
+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
226
236
} ) ;
227
237
228
238
test ( "Add a new item to JSON" , ( ) => {
@@ -234,7 +244,7 @@ suite("Asset generation: csproj", () => {
234
244
} ;
235
245
236
246
const newItem = { name : 'new-item' } ;
237
- const updated = updateJsonWithComments ( JSON . stringify ( original ) , [ newItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ) ;
247
+ const updated = updateJsonWithComments ( JSON . stringify ( original ) , [ newItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ! ) ;
238
248
const parsed = jsonc . parse ( updated ) ;
239
249
const configurations = parsed . configurations ;
240
250
@@ -254,7 +264,7 @@ suite("Asset generation: csproj", () => {
254
264
255
265
const updatedItem = { name : 'build' , command : 'dotnet' } ;
256
266
257
- const updated = updateJsonWithComments ( JSON . stringify ( original ) , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ) ;
267
+ const updated = updateJsonWithComments ( JSON . stringify ( original ) , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ! ) ;
258
268
const parsed = jsonc . parse ( updated ) ;
259
269
const configurations = parsed . configurations ;
260
270
@@ -278,7 +288,7 @@ suite("Asset generation: csproj", () => {
278
288
279
289
const updatedItem = { name : 'build' , command : 'dotnet' } ;
280
290
281
- const updated = updateJsonWithComments ( original , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ) ;
291
+ const updated = updateJsonWithComments ( original , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ! ) ;
282
292
const lines = updated . trim ( ) . split ( '\n' ) ;
283
293
284
294
lines [ 0 ] . trim ( ) . should . equal ( '// user comment in file' ) ;
@@ -336,12 +346,12 @@ function checkProgramPath(rootPath: string, programPath: string, targetPath: str
336
346
function createMockWorkspaceFolder ( rootPath : string ) : vscode . WorkspaceFolder {
337
347
return {
338
348
uri : vscode . Uri . file ( rootPath ) ,
339
- name : undefined ,
340
- index : undefined
349
+ name : '' ,
350
+ index : - 1
341
351
} ;
342
352
}
343
353
344
- function createMSBuildWorkspaceInformation ( projectPath : string , assemblyName : string , targetFrameworkShortName : string , targetPath : string = undefined , isExe : boolean = true , isWebProject : boolean = false , isBlazorWebAssemblyStandalone : boolean = false , isBlazorWebAssemblyHosted : boolean = false ) : protocol . WorkspaceInformationResponse {
354
+ function createMSBuildWorkspaceInformation ( projectPath : string , assemblyName : string , targetFrameworkShortName : string , targetPath : string | undefined = undefined , isExe : boolean = true , isWebProject : boolean = false , isBlazorWebAssemblyStandalone : boolean = false , isBlazorWebAssemblyHosted : boolean = false ) : protocol . WorkspaceInformationResponse {
345
355
return {
346
356
MsBuild : {
347
357
SolutionPath : '' ,
0 commit comments