@@ -12,6 +12,7 @@ import * as jsonc from 'jsonc-parser';
1212import { AssetGenerator , ProgramLaunchType , replaceCommentPropertiesWithComments , updateJsonWithComments } from '../../src/assets' ;
1313import { parse } from 'jsonc-parser' ;
1414import { use as chaiUse , should } from 'chai' ;
15+ import { isNotNull } from '../testUtil' ;
1516
1617chaiUse ( require ( 'chai-string' ) ) ;
1718
@@ -24,6 +25,8 @@ suite("Asset generation: csproj", () => {
2425 let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
2526 generator . setStartupProject ( 0 ) ;
2627 let tasksJson = generator . createTasksConfiguration ( ) ;
28+ isNotNull ( tasksJson . tasks ) ;
29+ isNotNull ( tasksJson . tasks [ 0 ] . args ) ;
2730 let buildPath = tasksJson . tasks [ 0 ] . args [ 1 ] ;
2831
2932 // ${workspaceFolder}/project.json
@@ -37,11 +40,12 @@ suite("Asset generation: csproj", () => {
3740 let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
3841 generator . setStartupProject ( 0 ) ;
3942 let tasksJson = generator . createTasksConfiguration ( ) ;
43+ isNotNull ( tasksJson . tasks ) ;
4044
4145 // We do not check the watch task since this parameter can break hot reload scenarios.
4246 tasksJson . tasks
4347 . 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" ) ) ;
4549 } ) ;
4650
4751 test ( "Generated 'build' and 'publish' tasks have the consoleloggerparameters argument set to NoSummary" , ( ) => {
@@ -50,11 +54,12 @@ suite("Asset generation: csproj", () => {
5054 let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
5155 generator . setStartupProject ( 0 ) ;
5256 let tasksJson = generator . createTasksConfiguration ( ) ;
57+ isNotNull ( tasksJson . tasks ) ;
5358
5459 // We do not check the watch task since this parameter can break hot reload scenarios.
5560 tasksJson . tasks
5661 . filter ( task => task . label !== "watch" )
57- . forEach ( task => task . args . should . contain ( "/consoleloggerparameters:NoSummary" ) ) ;
62+ . forEach ( task => task . args ! . should . contain ( "/consoleloggerparameters:NoSummary" ) ) ;
5863 } ) ;
5964
6065 test ( "Generated 'watch' task does not have the property GenerateFullPaths set to true " , ( ) => {
@@ -63,8 +68,10 @@ suite("Asset generation: csproj", () => {
6368 let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
6469 generator . setStartupProject ( 0 ) ;
6570 let tasksJson = generator . createTasksConfiguration ( ) ;
71+ isNotNull ( tasksJson . tasks ) ;
6672
6773 const watchTask = tasksJson . tasks . find ( task => task . label === "watch" ) ;
74+ isNotNull ( watchTask ?. args ) ;
6875 watchTask . args . should . not . contain ( "/property:GenerateFullPaths=true" ) ;
6976 } ) ;
7077
@@ -75,7 +82,8 @@ suite("Asset generation: csproj", () => {
7582 generator . setStartupProject ( 0 ) ;
7683 let tasksJson = generator . createTasksConfiguration ( ) ;
7784
78- const watchTask = tasksJson . tasks . find ( task => task . label === "watch" ) ;
85+ const watchTask = tasksJson . tasks ! . find ( task => task . label === "watch" ) ;
86+ isNotNull ( watchTask ?. args ) ;
7987 watchTask . args . should . not . contain ( "/consoleloggerparameters:NoSummary" ) ;
8088 } ) ;
8189
@@ -85,6 +93,8 @@ suite("Asset generation: csproj", () => {
8593 let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
8694 generator . setStartupProject ( 0 ) ;
8795 let tasksJson = generator . createTasksConfiguration ( ) ;
96+ isNotNull ( tasksJson . tasks ) ;
97+ isNotNull ( tasksJson . tasks [ 0 ] . args ) ;
8898 let buildPath = tasksJson . tasks [ 0 ] . args [ 1 ] ;
8999
90100 // ${workspaceFolder}/nested/project.json
@@ -100,7 +110,7 @@ suite("Asset generation: csproj", () => {
100110 let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Console ) , undefined , { disallowComments : true } ) ;
101111 let programPath : string = launchJson [ 0 ] . program ;
102112
103- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
113+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
104114 } ) ;
105115
106116 [ 5 , 6 , 7 , 8 , 9 ] . forEach ( version => {
@@ -114,7 +124,7 @@ suite("Asset generation: csproj", () => {
114124 let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Console ) , undefined , { disallowComments : true } ) ;
115125 let programPath : string = launchJson [ 0 ] . program ;
116126
117- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
127+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
118128 } ) ;
119129 } ) ;
120130
@@ -126,7 +136,7 @@ suite("Asset generation: csproj", () => {
126136 let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Console ) , undefined , { disallowComments : true } ) ;
127137 let programPath : string = launchJson [ 0 ] . program ;
128138
129- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
139+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
130140 } ) ;
131141
132142 test ( "Create launch.json for project opened in workspace with non-relative output path" , function ( ) {
@@ -142,7 +152,7 @@ suite("Asset generation: csproj", () => {
142152 let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Console ) , undefined , { disallowComments : true } ) ;
143153 let programPath : string = launchJson [ 0 ] . program ;
144154
145- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
155+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
146156 } ) ;
147157
148158 test ( "Create launch.json for Blazor web assembly standalone project opened in workspace" , ( ) => {
@@ -180,7 +190,7 @@ suite("Asset generation: csproj", () => {
180190 const cwd = hostedBlazorLaunchConfig . cwd ;
181191 const hosted = hostedBlazorLaunchConfig . hosted ;
182192
183- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
193+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
184194
185195 cwd . should . equal ( '${workspaceFolder}' ) ;
186196 hosted . should . equal ( true ) ;
@@ -197,7 +207,7 @@ suite("Asset generation: csproj", () => {
197207 const cwd = hostedBlazorLaunchConfig . cwd ;
198208 const hosted = hostedBlazorLaunchConfig . hosted ;
199209
200- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
210+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
201211
202212 cwd . should . equal ( '${workspaceFolder}/nested' ) ;
203213 hosted . should . equal ( true ) ;
@@ -211,7 +221,7 @@ suite("Asset generation: csproj", () => {
211221 let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Web ) , undefined , { disallowComments : true } ) ;
212222 let programPath : string = launchJson [ 0 ] . program ;
213223
214- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
224+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
215225 } ) ;
216226
217227 test ( "Create launch.json for nested web project opened in workspace" , ( ) => {
@@ -222,7 +232,7 @@ suite("Asset generation: csproj", () => {
222232 let launchJson = parse ( generator . createLaunchJsonConfigurations ( ProgramLaunchType . Web ) , undefined , { disallowComments : true } ) ;
223233 let programPath : string = launchJson [ 0 ] . program ;
224234
225- checkProgramPath ( rootPath , programPath , info . MsBuild . Projects [ 0 ] . TargetPath ) ;
235+ checkProgramPath ( rootPath , programPath , info . MsBuild ! . Projects [ 0 ] . TargetPath ) ;
226236 } ) ;
227237
228238 test ( "Add a new item to JSON" , ( ) => {
@@ -234,7 +244,7 @@ suite("Asset generation: csproj", () => {
234244 } ;
235245
236246 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 ! ) ;
238248 const parsed = jsonc . parse ( updated ) ;
239249 const configurations = parsed . configurations ;
240250
@@ -254,7 +264,7 @@ suite("Asset generation: csproj", () => {
254264
255265 const updatedItem = { name : 'build' , command : 'dotnet' } ;
256266
257- const updated = updateJsonWithComments ( JSON . stringify ( original ) , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ) ;
267+ const updated = updateJsonWithComments ( JSON . stringify ( original ) , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ! ) ;
258268 const parsed = jsonc . parse ( updated ) ;
259269 const configurations = parsed . configurations ;
260270
@@ -278,7 +288,7 @@ suite("Asset generation: csproj", () => {
278288
279289 const updatedItem = { name : 'build' , command : 'dotnet' } ;
280290
281- const updated = updateJsonWithComments ( original , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ) ;
291+ const updated = updateJsonWithComments ( original , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ! ) ;
282292 const lines = updated . trim ( ) . split ( '\n' ) ;
283293
284294 lines [ 0 ] . trim ( ) . should . equal ( '// user comment in file' ) ;
@@ -336,12 +346,12 @@ function checkProgramPath(rootPath: string, programPath: string, targetPath: str
336346function createMockWorkspaceFolder ( rootPath : string ) : vscode . WorkspaceFolder {
337347 return {
338348 uri : vscode . Uri . file ( rootPath ) ,
339- name : undefined ,
340- index : undefined
349+ name : '' ,
350+ index : - 1
341351 } ;
342352}
343353
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 {
345355 return {
346356 MsBuild : {
347357 SolutionPath : '' ,
0 commit comments