@@ -233,6 +233,165 @@ test("Happy path with VS Code debugging disabled", () => {
233
233
expect ( { entryPoints, files : fs . __getMockWrittenFiles ( ) } ) . toMatchSnapshot ( ) ;
234
234
} ) ;
235
235
236
+ const vscodeLaunchJson1 = `{
237
+ "version": "0.2.0",
238
+ "configurations": [
239
+ {
240
+ "name": "CustomLambda",
241
+ "type": "node",
242
+ "request": "attach",
243
+ "address": "localhost",
244
+ "port": 5858,
245
+ "localRoot": "\${workspaceFolder}/.aws-sam/build/CustomLambda",
246
+ "remoteRoot": "/var/task",
247
+ "protocol": "inspector",
248
+ "stopOnEntry": false,
249
+ "outFiles": [
250
+ "\${workspaceFolder}/.aws-sam/build/CustomLambda/**/*.js"
251
+ ],
252
+ "sourceMaps": true,
253
+ "skipFiles": [
254
+ "/var/runtime/**/*.js",
255
+ "<node_internals>/**/*.js"
256
+ ]
257
+ }
258
+ ]
259
+ }` ;
260
+ const vscodeLaunchJson2 = `{
261
+ "version": "0.2.0",
262
+ "configurations": [
263
+ {
264
+ "name": "CustomLambda",
265
+ "type": "node",
266
+ "request": "attach",
267
+ "address": "localhost",
268
+ "port": 5858,
269
+ "localRoot": "\${workspaceFolder}/.aws-sam/build/CustomLambda",
270
+ "remoteRoot": "/var/task",
271
+ "protocol": "inspector",
272
+ "stopOnEntry": false,
273
+ "outFiles": [
274
+ "\${workspaceFolder}/.aws-sam/build/CustomLambda/**/*.js"
275
+ ],
276
+ "sourceMaps": true,
277
+ "skipFiles": [
278
+ "/var/runtime/**/*.js",
279
+ "<node_internals>/**/*.js"
280
+ ]
281
+ },
282
+ // BEGIN AwsSamPlugin
283
+ {
284
+ "name": "OldLambda",
285
+ "type": "node",
286
+ "request": "attach",
287
+ "address": "localhost",
288
+ "port": 5858,
289
+ "localRoot": "\${workspaceFolder}/.aws-sam/build/OldLambda",
290
+ "remoteRoot": "/var/task",
291
+ "protocol": "inspector",
292
+ "stopOnEntry": false,
293
+ "outFiles": [
294
+ "\${workspaceFolder}/.aws-sam/build/OldLambda/**/*.js"
295
+ ],
296
+ "sourceMaps": true,
297
+ "skipFiles": [
298
+ "/var/runtime/**/*.js",
299
+ "<node_internals>/**/*.js"
300
+ ]
301
+ }
302
+ // END AwsSamPlugin
303
+ ]
304
+ }` ;
305
+ const vscodeLaunchJsonTest = `{
306
+ "version": "0.2.0",
307
+ "configurations": [
308
+ {
309
+ "name": "CustomLambda",
310
+ "type": "node",
311
+ "request": "attach",
312
+ "address": "localhost",
313
+ "port": 5858,
314
+ "localRoot": "\${workspaceFolder}/.aws-sam/build/CustomLambda",
315
+ "remoteRoot": "/var/task",
316
+ "protocol": "inspector",
317
+ "stopOnEntry": false,
318
+ "outFiles": [
319
+ "\${workspaceFolder}/.aws-sam/build/CustomLambda/**/*.js"
320
+ ],
321
+ "sourceMaps": true,
322
+ "skipFiles": [
323
+ "/var/runtime/**/*.js",
324
+ "<node_internals>/**/*.js"
325
+ ]
326
+ },
327
+ // BEGIN AwsSamPlugin
328
+ {
329
+ "name": "MyLambda",
330
+ "type": "node",
331
+ "request": "attach",
332
+ "address": "localhost",
333
+ "port": 5858,
334
+ "localRoot": "\${workspaceFolder}/.aws-sam/build/MyLambda",
335
+ "remoteRoot": "/var/task",
336
+ "protocol": "inspector",
337
+ "stopOnEntry": false,
338
+ "outFiles": [
339
+ "\${workspaceFolder}/.aws-sam/build/MyLambda/**/*.js"
340
+ ],
341
+ "sourceMaps": true,
342
+ "skipFiles": [
343
+ "/var/runtime/**/*.js",
344
+ "<node_internals>/**/*.js"
345
+ ]
346
+ }
347
+ // END AwsSamPlugin
348
+ ]
349
+ }` ;
350
+
351
+ test . each ( [
352
+ [ vscodeLaunchJson1 , vscodeLaunchJsonTest ] ,
353
+ [ vscodeLaunchJson2 , vscodeLaunchJsonTest ] ,
354
+ ] ) ( "Happy build launch.json with replace old content" , ( srcData , testData ) => {
355
+ const plugin = new SamPlugin ( { vscodeDebug : true } ) ;
356
+
357
+ // @ts -ignore
358
+ fs . __clearMocks ( ) ;
359
+ // @ts -ignore
360
+ fs . __setMockDirs ( [ "." ] ) ;
361
+ // @ts -ignore
362
+ fs . __setMockFiles ( { "./template.yaml" : samTemplate , ".vscode/launch.json" : srcData } ) ;
363
+
364
+ // @ts -ignore
365
+ path . __clearMocks ( ) ;
366
+ // @ts -ignore
367
+ path . __setMockBasenames ( { "./template.yaml" : "template.yaml" } ) ;
368
+ // @ts -ignore
369
+ path . __setMockDirnames ( { "./template.yaml" : "." } ) ;
370
+ // @ts -ignore
371
+ path . __setMockRelatives ( { ".#." : "" } ) ;
372
+
373
+ const entryPoints = plugin . entry ( ) ;
374
+
375
+ let afterEmit : ( _compilation : any ) => void ;
376
+
377
+ plugin . apply ( {
378
+ hooks : {
379
+ afterEmit : {
380
+ tap : ( n : string , f : ( _compilation : any ) => void ) => {
381
+ afterEmit = f ;
382
+ } ,
383
+ } ,
384
+ } ,
385
+ } ) ;
386
+ // @ts -ignore
387
+ afterEmit ( null ) ;
388
+
389
+ // @ts -ignore
390
+ const vscodeLaunchJsonContent = fs . __getMockWrittenFiles ( ) [ ".vscode/launch.json" ] ;
391
+
392
+ expect ( vscodeLaunchJsonContent ) . toEqual ( testData ) ;
393
+ } ) ;
394
+
236
395
test ( "Happy path with multiple projects works" , ( ) => {
237
396
const plugin = new SamPlugin ( { projects : { a : "project-a" , b : "project-b" } } ) ;
238
397
0 commit comments