@@ -189,6 +189,165 @@ test("Happy path with VS Code debugging disabled", () => {
189189 expect ( { entryPoints, files : fs . __getMockWrittenFiles ( ) } ) . toMatchSnapshot ( ) ;
190190} ) ;
191191
192+ const vscodeLaunchJson1 = `{
193+ "version": "0.2.0",
194+ "configurations": [
195+ {
196+ "name": "CustomLambda",
197+ "type": "node",
198+ "request": "attach",
199+ "address": "localhost",
200+ "port": 5858,
201+ "localRoot": "\${workspaceFolder}/.aws-sam/build/CustomLambda",
202+ "remoteRoot": "/var/task",
203+ "protocol": "inspector",
204+ "stopOnEntry": false,
205+ "outFiles": [
206+ "\${workspaceFolder}/.aws-sam/build/CustomLambda/**/*.js"
207+ ],
208+ "sourceMaps": true,
209+ "skipFiles": [
210+ "/var/runtime/**/*.js",
211+ "<node_internals>/**/*.js"
212+ ]
213+ }
214+ ]
215+ }` ;
216+ const vscodeLaunchJson2 = `{
217+ "version": "0.2.0",
218+ "configurations": [
219+ {
220+ "name": "CustomLambda",
221+ "type": "node",
222+ "request": "attach",
223+ "address": "localhost",
224+ "port": 5858,
225+ "localRoot": "\${workspaceFolder}/.aws-sam/build/CustomLambda",
226+ "remoteRoot": "/var/task",
227+ "protocol": "inspector",
228+ "stopOnEntry": false,
229+ "outFiles": [
230+ "\${workspaceFolder}/.aws-sam/build/CustomLambda/**/*.js"
231+ ],
232+ "sourceMaps": true,
233+ "skipFiles": [
234+ "/var/runtime/**/*.js",
235+ "<node_internals>/**/*.js"
236+ ]
237+ },
238+ // BEGIN AwsSamPlugin
239+ {
240+ "name": "OldLambda",
241+ "type": "node",
242+ "request": "attach",
243+ "address": "localhost",
244+ "port": 5858,
245+ "localRoot": "\${workspaceFolder}/.aws-sam/build/OldLambda",
246+ "remoteRoot": "/var/task",
247+ "protocol": "inspector",
248+ "stopOnEntry": false,
249+ "outFiles": [
250+ "\${workspaceFolder}/.aws-sam/build/OldLambda/**/*.js"
251+ ],
252+ "sourceMaps": true,
253+ "skipFiles": [
254+ "/var/runtime/**/*.js",
255+ "<node_internals>/**/*.js"
256+ ]
257+ }
258+ // END AwsSamPlugin
259+ ]
260+ }` ;
261+ const vscodeLaunchJsonTest = `{
262+ "version": "0.2.0",
263+ "configurations": [
264+ {
265+ "name": "CustomLambda",
266+ "type": "node",
267+ "request": "attach",
268+ "address": "localhost",
269+ "port": 5858,
270+ "localRoot": "\${workspaceFolder}/.aws-sam/build/CustomLambda",
271+ "remoteRoot": "/var/task",
272+ "protocol": "inspector",
273+ "stopOnEntry": false,
274+ "outFiles": [
275+ "\${workspaceFolder}/.aws-sam/build/CustomLambda/**/*.js"
276+ ],
277+ "sourceMaps": true,
278+ "skipFiles": [
279+ "/var/runtime/**/*.js",
280+ "<node_internals>/**/*.js"
281+ ]
282+ },
283+ // BEGIN AwsSamPlugin
284+ {
285+ "name": "MyLambda",
286+ "type": "node",
287+ "request": "attach",
288+ "address": "localhost",
289+ "port": 5858,
290+ "localRoot": "\${workspaceFolder}/.aws-sam/build/MyLambda",
291+ "remoteRoot": "/var/task",
292+ "protocol": "inspector",
293+ "stopOnEntry": false,
294+ "outFiles": [
295+ "\${workspaceFolder}/.aws-sam/build/MyLambda/**/*.js"
296+ ],
297+ "sourceMaps": true,
298+ "skipFiles": [
299+ "/var/runtime/**/*.js",
300+ "<node_internals>/**/*.js"
301+ ]
302+ }
303+ // END AwsSamPlugin
304+ ]
305+ }` ;
306+
307+ test . each ( [
308+ [ vscodeLaunchJson1 , vscodeLaunchJsonTest ] ,
309+ [ vscodeLaunchJson2 , vscodeLaunchJsonTest ] ,
310+ ] ) ( "Happy build launch.json with replace old content" , ( srcData , testData ) => {
311+ const plugin = new SamPlugin ( { vscodeDebug : true } ) ;
312+
313+ // @ts -ignore
314+ fs . __clearMocks ( ) ;
315+ // @ts -ignore
316+ fs . __setMockDirs ( [ "." ] ) ;
317+ // @ts -ignore
318+ fs . __setMockFiles ( { "./template.yaml" : samTemplate , ".vscode/launch.json" : srcData } ) ;
319+
320+ // @ts -ignore
321+ path . __clearMocks ( ) ;
322+ // @ts -ignore
323+ path . __setMockBasenames ( { "./template.yaml" : "template.yaml" } ) ;
324+ // @ts -ignore
325+ path . __setMockDirnames ( { "./template.yaml" : "." } ) ;
326+ // @ts -ignore
327+ path . __setMockRelatives ( { ".#." : "" } ) ;
328+
329+ const entryPoints = plugin . entry ( ) ;
330+
331+ let afterEmit : ( _compilation : any ) => void ;
332+
333+ plugin . apply ( {
334+ hooks : {
335+ afterEmit : {
336+ tap : ( n : string , f : ( _compilation : any ) => void ) => {
337+ afterEmit = f ;
338+ } ,
339+ } ,
340+ } ,
341+ } ) ;
342+ // @ts -ignore
343+ afterEmit ( null ) ;
344+
345+ // @ts -ignore
346+ const vscodeLaunchJsonContent = fs . __getMockWrittenFiles ( ) [ ".vscode/launch.json" ] ;
347+
348+ expect ( vscodeLaunchJsonContent ) . toEqual ( testData ) ;
349+ } ) ;
350+
192351test ( "Happy path with multiple projects works" , ( ) => {
193352 const plugin = new SamPlugin ( { projects : { a : "project-a" , b : "project-b" } } ) ;
194353
0 commit comments