@@ -7,7 +7,7 @@ import * as path from 'path';
7
7
import * as protocol from '../../src/omnisharp/protocol' ;
8
8
import * as vscode from 'vscode' ;
9
9
import * as jsonc from 'jsonc-parser' ;
10
- // import { FormattingOptions } from 'jsonc-parser';
10
+ // import { FormattingOptions } from 'jsonc-parser';
11
11
12
12
import { AssetGenerator , ProgramLaunchType , replaceCommentPropertiesWithComments , updateJsonWithComments } from '../../src/assets' ;
13
13
import { parse } from 'jsonc-parser' ;
@@ -29,24 +29,52 @@ suite("Asset generation: csproj", () => {
29
29
segments . should . deep . equal ( [ '${workspaceFolder}' , 'testApp.csproj' ] ) ;
30
30
} ) ;
31
31
32
- test ( "Generated tasks.json has the property GenerateFullPaths set to true " , ( ) => {
32
+ test ( "Generated 'build' and 'publish' tasks have the property GenerateFullPaths set to true " , ( ) => {
33
33
let rootPath = path . resolve ( 'testRoot' ) ;
34
34
let info = createMSBuildWorkspaceInformation ( path . join ( rootPath , 'testApp.csproj' ) , 'testApp' , 'netcoreapp1.0' ) ;
35
35
let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
36
36
generator . setStartupProject ( 0 ) ;
37
37
let tasksJson = generator . createTasksConfiguration ( ) ;
38
38
39
- tasksJson . tasks . forEach ( task => task . args . should . contain ( "/property:GenerateFullPaths=true" ) ) ;
39
+ // We do not check the watch task since this parameter can break hot reload scenarios.
40
+ tasksJson . tasks
41
+ . filter ( task => task . label !== "watch" )
42
+ . forEach ( task => task . args . should . contain ( "/property:GenerateFullPaths=true" ) ) ;
40
43
} ) ;
41
44
42
- test ( "Generated tasks.json has the consoleloggerparameters argument set to NoSummary" , ( ) => {
45
+ test ( "Generated 'build' and 'publish' tasks have the consoleloggerparameters argument set to NoSummary" , ( ) => {
43
46
let rootPath = path . resolve ( 'testRoot' ) ;
44
47
let info = createMSBuildWorkspaceInformation ( path . join ( rootPath , 'testApp.csproj' ) , 'testApp' , 'netcoreapp1.0' ) ;
45
48
let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
46
49
generator . setStartupProject ( 0 ) ;
47
50
let tasksJson = generator . createTasksConfiguration ( ) ;
48
51
49
- tasksJson . tasks . forEach ( task => task . args . should . contain ( "/consoleloggerparameters:NoSummary" ) ) ;
52
+ // We do not check the watch task since this parameter can break hot reload scenarios.
53
+ tasksJson . tasks
54
+ . filter ( task => task . label !== "watch" )
55
+ . forEach ( task => task . args . should . contain ( "/consoleloggerparameters:NoSummary" ) ) ;
56
+ } ) ;
57
+
58
+ test ( "Generated 'watch' task does not have the property GenerateFullPaths set to true " , ( ) => {
59
+ let rootPath = path . resolve ( 'testRoot' ) ;
60
+ let info = createMSBuildWorkspaceInformation ( path . join ( rootPath , 'testApp.csproj' ) , 'testApp' , 'netcoreapp1.0' ) ;
61
+ let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
62
+ generator . setStartupProject ( 0 ) ;
63
+ let tasksJson = generator . createTasksConfiguration ( ) ;
64
+
65
+ const watchTask = tasksJson . tasks . find ( task => task . label === "watch" ) ;
66
+ watchTask . args . should . not . contain ( "/property:GenerateFullPaths=true" ) ;
67
+ } ) ;
68
+
69
+ test ( "Generated 'watch' task does not have the consoleloggerparameters argument set to NoSummary" , ( ) => {
70
+ let rootPath = path . resolve ( 'testRoot' ) ;
71
+ let info = createMSBuildWorkspaceInformation ( path . join ( rootPath , 'testApp.csproj' ) , 'testApp' , 'netcoreapp1.0' ) ;
72
+ let generator = new AssetGenerator ( info , createMockWorkspaceFolder ( rootPath ) ) ;
73
+ generator . setStartupProject ( 0 ) ;
74
+ let tasksJson = generator . createTasksConfiguration ( ) ;
75
+
76
+ const watchTask = tasksJson . tasks . find ( task => task . label === "watch" ) ;
77
+ watchTask . args . should . not . contain ( "/consoleloggerparameters:NoSummary" ) ;
50
78
} ) ;
51
79
52
80
test ( "Create tasks.json for nested project opened in workspace" , ( ) => {
@@ -205,80 +233,80 @@ suite("Asset generation: csproj", () => {
205
233
206
234
test ( "Add a new item to JSON" , ( ) => {
207
235
const existingItem = { name : 'existing-item' } ;
208
- const original = {
236
+ const original = {
209
237
configurations : [
210
238
existingItem
211
239
]
212
240
} ;
213
241
214
- const newItem = { name : 'new-item' } ;
242
+ const newItem = { name : 'new-item' } ;
215
243
const updated = updateJsonWithComments ( JSON . stringify ( original ) , [ newItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ) ;
216
244
const parsed = jsonc . parse ( updated ) ;
217
245
const configurations = parsed . configurations ;
218
246
219
- const expected = [ existingItem , newItem ] ;
247
+ const expected = [ existingItem , newItem ] ;
220
248
configurations . should . deep . equal ( expected ) ;
221
249
} ) ;
222
250
223
251
test ( "Update item in JSON" , ( ) => {
224
252
const existingItem = { name : 'existing-item' , command : 'cmd' } ;
225
- const original = {
253
+ const original = {
226
254
configurations : [
227
255
// this should update to have command dotnet, because the name is the same as our updated item
228
256
{ name : 'build' , command : 'old value' } ,
229
257
existingItem
230
258
]
231
259
} ;
232
260
233
- const updatedItem = { name : 'build' , command : 'dotnet' } ;
234
-
261
+ const updatedItem = { name : 'build' , command : 'dotnet' } ;
262
+
235
263
const updated = updateJsonWithComments ( JSON . stringify ( original ) , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ) ;
236
264
const parsed = jsonc . parse ( updated ) ;
237
265
const configurations = parsed . configurations ;
238
266
239
- const expected = [ updatedItem , existingItem ] ;
267
+ const expected = [ updatedItem , existingItem ] ;
240
268
configurations . should . deep . equal ( expected ) ;
241
269
} ) ;
242
270
243
271
test ( "Update JSON and preserve all comments" , ( ) => {
244
272
const original = `
245
273
// user comment in file
246
- {
274
+ {
247
275
"configurations": [
248
276
{ "name": "build", "command": "old value" },
249
- {
277
+ {
250
278
// user comment in their configuration
251
- "name": "existing-item",
252
- "command": "cmd"
279
+ "name": "existing-item",
280
+ "command": "cmd"
253
281
}
254
282
]
255
283
}` ;
256
284
257
- const updatedItem = { name : 'build' , command : 'dotnet' } ;
258
-
285
+ const updatedItem = { name : 'build' , command : 'dotnet' } ;
286
+
259
287
const updated = updateJsonWithComments ( original , [ updatedItem ] , 'configurations' , 'name' , /*formattingOptions*/ null ) ;
260
288
const lines = updated . trim ( ) . split ( '\n' ) ;
261
-
289
+
262
290
lines [ 0 ] . trim ( ) . should . equal ( '// user comment in file' ) ;
263
291
lines [ 5 ] . trim ( ) . should . equal ( '// user comment in their configuration' ) ;
264
292
} ) ;
265
293
266
294
test ( "Replace items named OS-COMMENTxxx with JSON comment syntax" , ( ) => {
267
295
const original = `
268
- {
296
+ {
269
297
"configurations": [
270
- {
271
- "name": "build",
298
+ {
299
+ "name": "build",
272
300
"OS-COMMENT": "This is a dotnet build command",
273
301
"OS-COMMENT2": "this is the default command.",
274
- "command": "dotnet build"
302
+ "command": "dotnet build"
275
303
},
276
304
]
277
305
}` ;
278
306
279
307
let updated = replaceCommentPropertiesWithComments ( original ) ;
280
308
let lines = updated . trim ( ) . split ( '\n' ) ;
281
-
309
+
282
310
lines [ 4 ] . trim ( ) . should . equal ( '// This is a dotnet build command' ) ;
283
311
lines [ 5 ] . trim ( ) . should . equal ( '// this is the default command.' ) ;
284
312
} ) ;
0 commit comments