@@ -26,123 +26,113 @@ describe('Serverless Land Integration', async () => {
2626 const workspaceFolder = vscode . workspace . workspaceFolders ! [ 0 ]
2727 const projectFolder = 'my-project-from-Serverless-Land'
2828 let rootNode : sinon . SinonSpiedInstance < AppBuilderRootNode >
29+ let sandbox : sinon . SinonSandbox
2930
30- before ( async ( ) => {
31- sinon . createSandbox ( )
31+ beforeEach ( async ( ) => {
32+ sandbox = sinon . createSandbox ( )
3233 await fs . delete ( path . join ( workspaceFolder . uri . fsPath , projectFolder ) , { recursive : true } )
33- // rootNode = sinon .spy(AppBuilderRootNode.instance)
34+ rootNode = sandbox . spy ( AppBuilderRootNode . instance )
3435 } )
3536
36- after ( async ( ) => {
37+ afterEach ( async ( ) => {
3738 await fs . delete ( path . join ( workspaceFolder . uri . fsPath , projectFolder ) , { recursive : true } )
38- // sinon .restore()
39+ sandbox . restore ( )
3940 } )
4041
41- describe ( 'Happy Path' , async ( ) => {
42- beforeEach ( async ( ) => {
43- rootNode = sinon . spy ( AppBuilderRootNode . instance )
44- } )
45-
46- afterEach ( ( ) => {
47- sinon . restore ( )
48- } )
49-
50- it ( 'creates project from Serverless Land integration' , async ( ) => {
51- /**
52- * Selection:
53- * - pattern : [Select] 2 apigw-rest-api-lambda-sam
54- * - runtime : [Select] 3 dotnet
55- * - iac : [Select] 1 sam
56- * - location : [Input] From TestFolder.uri
57- * - name : [Input] "my-project-from-Serverless-Land"
58- */
59-
60- const testWindow = getTestWindow ( )
61- const prompterTester = PrompterTester . init ( { testWindow } )
62- . handleQuickPick ( 'Select a Pattern for your application' , async ( quickPick ) => {
63- await quickPick . untilReady ( )
64- const options = quickPick . items
65- Object . entries ( parseMetadata . patterns ) . map ( ( [ key , pattern ] ) => {
66- options . find ( ( option ) => option . label === key && option . detail === pattern . description )
67- } )
68- quickPick . acceptItem ( quickPick . items [ 1 ] )
69- } )
70- . handleQuickPick ( 'Select Runtime' , async ( quickPick ) => {
71- await quickPick . untilReady ( )
72- const options = quickPick . items
73- assert . strictEqual ( options [ 0 ] . label , 'python' )
74- assert . strictEqual ( options [ 1 ] . label , 'javascript' )
75- assert . strictEqual ( options [ 2 ] . label , 'java' )
76- assert . strictEqual ( options [ 3 ] . label , 'dotnet' )
77- quickPick . acceptItem ( options [ 3 ] )
42+ it ( 'creates project from Serverless Land integration' , async ( ) => {
43+ /**
44+ * Selection:
45+ * - pattern : [Select] 2 apigw-rest-api-lambda-sam
46+ * - runtime : [Select] 3 dotnet
47+ * - iac : [Select] 1 sam
48+ * - location : [Input] From TestFolder.uri
49+ * - name : [Input] "my-project-from-Serverless-Land"
50+ */
51+
52+ const testWindow = getTestWindow ( )
53+ const prompterTester = PrompterTester . init ( { testWindow } )
54+ . handleQuickPick ( 'Select a Pattern for your application' , async ( quickPick ) => {
55+ await quickPick . untilReady ( )
56+ const options = quickPick . items
57+ Object . entries ( parseMetadata . patterns ) . map ( ( [ key , pattern ] ) => {
58+ options . find ( ( option ) => option . label === key && option . detail === pattern . description )
7859 } )
79- . handleQuickPick ( 'Select IaC' , async ( quickPick ) => {
80- await quickPick . untilReady ( )
81- const options = quickPick . items
82- assert . strictEqual ( options [ 0 ] . label , 'sam' )
83- quickPick . acceptItem ( options [ 0 ] )
84- } )
85- . handleQuickPick ( 'Select Project Location' , async ( quickPick ) => {
86- await quickPick . untilReady ( )
87- const options = quickPick . items
88- assert . strictEqual ( options [ 0 ] . label , '$(folder) workspaceFolder' )
89- assert . strictEqual ( options [ 1 ] . label , '$(folder-opened) Select a folder...' )
90- quickPick . acceptItem ( options [ 0 ] )
91- } )
92- . handleInputBox ( 'Enter Project Name' , ( inputBox ) => {
93- inputBox . acceptValue ( 'my-project-from-Serverless-Land' )
94- } )
95- . build ( )
96-
97- // Validate that the README.md is shown.
98- testWindow . onDidChangeActiveTextEditor ( ( editors ) => {
99- assert ( editors )
100- const readMe = path . join ( workspaceFolder . uri . fsPath , projectFolder , 'README.md' )
101- assert . strictEqual ( editors ?. document . fileName , readMe )
60+ quickPick . acceptItem ( quickPick . items [ 1 ] )
10261 } )
103-
104- await vscode . commands . executeCommand ( 'aws.toolkit.lambda.createServerlessLandProject' )
105-
106- // projectNodes set from previous step
107-
108- const projectNode = await rootNode
109- . getChildren ( )
110- . then (
111- ( children ) =>
112- children . find (
113- ( node ) =>
114- node instanceof AppNode &&
115- node . label === 'workspaceFolder/my-project-from-Serverless-Land'
116- ) as AppNode | undefined
117- )
118-
119- assert . ok ( projectNode , 'Expect Serverless Land project node in Application Builder' )
120-
121- // Check App Builder resources
122- const resourceNodes = await projectNode . getChildren ( )
123- assert . strictEqual ( resourceNodes . length , 1 )
124- assert . ok ( resourceNodes [ 0 ] instanceof ResourceNode )
125-
126- // Validate Lambda resource configuration
127- const lambdaResource = resourceNodes [ 0 ] as ResourceNode
128- assert . strictEqual ( lambdaResource . resource . resource . Type , 'AWS::Serverless::Function' )
129- assert . strictEqual ( lambdaResource . resource . resource . Runtime , 'dotnet8' )
130- assert . strictEqual ( lambdaResource . resource . resource . Id , 'HelloWorldFunction' )
131- assert . deepStrictEqual ( lambdaResource . resource . resource . Events , [
132- {
133- Id : 'HelloWorld' ,
134- Type : 'Api' ,
135- Path : '/hello' ,
136- Method : 'get' ,
137- } ,
138- ] )
139- assert . deepStrictEqual ( lambdaResource . resource . resource . Environment , {
140- Variables : {
141- PARAM1 : 'VALUE' ,
142- } ,
62+ . handleQuickPick ( 'Select Runtime' , async ( quickPick ) => {
63+ await quickPick . untilReady ( )
64+ const options = quickPick . items
65+ assert . strictEqual ( options [ 0 ] . label , 'python' )
66+ assert . strictEqual ( options [ 1 ] . label , 'javascript' )
67+ assert . strictEqual ( options [ 2 ] . label , 'java' )
68+ assert . strictEqual ( options [ 3 ] . label , 'dotnet' )
69+ quickPick . acceptItem ( options [ 3 ] )
70+ } )
71+ . handleQuickPick ( 'Select IaC' , async ( quickPick ) => {
72+ await quickPick . untilReady ( )
73+ const options = quickPick . items
74+ assert . strictEqual ( options [ 0 ] . label , 'sam' )
75+ quickPick . acceptItem ( options [ 0 ] )
14376 } )
77+ . handleQuickPick ( 'Select Project Location' , async ( quickPick ) => {
78+ await quickPick . untilReady ( )
79+ const options = quickPick . items
80+ assert . strictEqual ( options [ 0 ] . label , '$(folder) workspaceFolder' )
81+ assert . strictEqual ( options [ 1 ] . label , '$(folder-opened) Select a folder...' )
82+ quickPick . acceptItem ( options [ 0 ] )
83+ } )
84+ . handleInputBox ( 'Enter Project Name' , ( inputBox ) => {
85+ inputBox . acceptValue ( 'my-project-from-Serverless-Land' )
86+ } )
87+ . build ( )
14488
145- prompterTester . assertCallAll ( )
89+ // Validate that the README.md is shown.
90+ testWindow . onDidChangeActiveTextEditor ( ( editors ) => {
91+ assert ( editors )
92+ const readMe = path . join ( workspaceFolder . uri . fsPath , projectFolder , 'README.md' )
93+ assert . strictEqual ( editors ?. document . fileName , readMe )
14694 } )
95+
96+ await vscode . commands . executeCommand ( 'aws.toolkit.lambda.createServerlessLandProject' )
97+
98+ // projectNodes set from previous step
99+
100+ const projectNode = await rootNode
101+ . getChildren ( )
102+ . then (
103+ ( children ) =>
104+ children . find (
105+ ( node ) =>
106+ node instanceof AppNode && node . label === 'workspaceFolder/my-project-from-Serverless-Land'
107+ ) as AppNode | undefined
108+ )
109+
110+ assert . ok ( projectNode , 'Expect Serverless Land project node in Application Builder' )
111+
112+ // Check App Builder resources
113+ const resourceNodes = await projectNode . getChildren ( )
114+ assert . strictEqual ( resourceNodes . length , 1 )
115+ assert . ok ( resourceNodes [ 0 ] instanceof ResourceNode )
116+
117+ // Validate Lambda resource configuration
118+ const lambdaResource = resourceNodes [ 0 ] as ResourceNode
119+ assert . strictEqual ( lambdaResource . resource . resource . Type , 'AWS::Serverless::Function' )
120+ assert . strictEqual ( lambdaResource . resource . resource . Runtime , 'dotnet8' )
121+ assert . strictEqual ( lambdaResource . resource . resource . Id , 'HelloWorldFunction' )
122+ assert . deepStrictEqual ( lambdaResource . resource . resource . Events , [
123+ {
124+ Id : 'HelloWorld' ,
125+ Type : 'Api' ,
126+ Path : '/hello' ,
127+ Method : 'get' ,
128+ } ,
129+ ] )
130+ assert . deepStrictEqual ( lambdaResource . resource . resource . Environment , {
131+ Variables : {
132+ PARAM1 : 'VALUE' ,
133+ } ,
134+ } )
135+
136+ prompterTester . assertCallAll ( )
147137 } )
148138} )
0 commit comments