diff --git a/packages/core/src/testInteg/appBuilder/serverlessLand/main.test.ts b/packages/core/src/testInteg/appBuilder/serverlessLand/main.test.ts index 7b2154ecf30..7a443483440 100644 --- a/packages/core/src/testInteg/appBuilder/serverlessLand/main.test.ts +++ b/packages/core/src/testInteg/appBuilder/serverlessLand/main.test.ts @@ -25,114 +25,120 @@ describe('Serverless Land Integration', async () => { const parseMetadata = JSON.parse(metadataContent) as ProjectMetadata const workspaceFolder = vscode.workspace.workspaceFolders![0] const projectFolder = 'my-project-from-Serverless-Land' - let rootNode: sinon.SinonSpiedInstance - let sandbox: sinon.SinonSandbox - beforeEach(async () => { - sandbox = sinon.createSandbox() - await fs.delete(path.join(workspaceFolder.uri.fsPath, projectFolder), { recursive: true }) - rootNode = sandbox.spy(AppBuilderRootNode.instance) - }) + // Additional layer of describe() needed here to prevent side effect from + // `sandbox.spy(AppBuilderRootNode.instance)` + describe('Happy Path', async () => { + let rootNode: sinon.SinonSpiedInstance + let sandbox: sinon.SinonSandbox - afterEach(async () => { - await fs.delete(path.join(workspaceFolder.uri.fsPath, projectFolder), { recursive: true }) - sandbox.restore() - }) + beforeEach(async () => { + sandbox = sinon.createSandbox() + rootNode = sandbox.spy(AppBuilderRootNode.instance) + await fs.delete(path.join(workspaceFolder.uri.fsPath, projectFolder), { recursive: true }) + }) + + afterEach(async () => { + await fs.delete(path.join(workspaceFolder.uri.fsPath, projectFolder), { recursive: true }) + sandbox.restore() + }) - it('creates project from Serverless Land integration', async () => { - /** - * Selection: - * - pattern : [Select] 2 apigw-rest-api-lambda-sam - * - runtime : [Select] 3 dotnet - * - iac : [Select] 1 sam - * - location : [Input] From TestFolder.uri - * - name : [Input] "my-project-from-Serverless-Land" - */ + it('creates project from Serverless Land integration', async () => { + /** + * Selection: + * - pattern : [Select] 2 apigw-rest-api-lambda-sam + * - runtime : [Select] 3 dotnet + * - iac : [Select] 1 sam + * - location : [Input] From TestFolder.uri + * - name : [Input] "my-project-from-Serverless-Land" + */ - const testWindow = getTestWindow() - const prompterTester = PrompterTester.init({ testWindow }) - .handleQuickPick('Select a Pattern for your application', async (quickPick) => { - await quickPick.untilReady() - const options = quickPick.items - Object.entries(parseMetadata.patterns).map(([key, pattern]) => { - options.find((option) => option.label === key && option.detail === pattern.description) + const testWindow = getTestWindow() + const prompterTester = PrompterTester.init({ testWindow }) + .handleQuickPick('Select a Pattern for your application', async (quickPick) => { + await quickPick.untilReady() + const options = quickPick.items + Object.entries(parseMetadata.patterns).map(([key, pattern]) => { + options.find((option) => option.label === key && option.detail === pattern.description) + }) + quickPick.acceptItem(quickPick.items[1]) }) - quickPick.acceptItem(quickPick.items[1]) - }) - .handleQuickPick('Select Runtime', async (quickPick) => { - await quickPick.untilReady() - const options = quickPick.items - assert.strictEqual(options[0].label, 'python') - assert.strictEqual(options[1].label, 'javascript') - assert.strictEqual(options[2].label, 'java') - assert.strictEqual(options[3].label, 'dotnet') - quickPick.acceptItem(options[3]) - }) - .handleQuickPick('Select IaC', async (quickPick) => { - await quickPick.untilReady() - const options = quickPick.items - assert.strictEqual(options[0].label, 'sam') - quickPick.acceptItem(options[0]) - }) - .handleQuickPick('Select Project Location', async (quickPick) => { - await quickPick.untilReady() - const options = quickPick.items - assert.strictEqual(options[0].label, '$(folder) workspaceFolder') - assert.strictEqual(options[1].label, '$(folder-opened) Select a folder...') - quickPick.acceptItem(options[0]) - }) - .handleInputBox('Enter Project Name', (inputBox) => { - inputBox.acceptValue('my-project-from-Serverless-Land') + .handleQuickPick('Select Runtime', async (quickPick) => { + await quickPick.untilReady() + const options = quickPick.items + assert.strictEqual(options[0].label, 'python') + assert.strictEqual(options[1].label, 'javascript') + assert.strictEqual(options[2].label, 'java') + assert.strictEqual(options[3].label, 'dotnet') + quickPick.acceptItem(options[3]) + }) + .handleQuickPick('Select IaC', async (quickPick) => { + await quickPick.untilReady() + const options = quickPick.items + assert.strictEqual(options[0].label, 'sam') + quickPick.acceptItem(options[0]) + }) + .handleQuickPick('Select Project Location', async (quickPick) => { + await quickPick.untilReady() + const options = quickPick.items + assert.strictEqual(options[0].label, '$(folder) workspaceFolder') + assert.strictEqual(options[1].label, '$(folder-opened) Select a folder...') + quickPick.acceptItem(options[0]) + }) + .handleInputBox('Enter Project Name', (inputBox) => { + inputBox.acceptValue('my-project-from-Serverless-Land') + }) + .build() + + // Validate that the README.md is shown. + testWindow.onDidChangeActiveTextEditor((editors) => { + assert(editors) + const readMe = path.join(workspaceFolder.uri.fsPath, projectFolder, 'README.md') + assert.strictEqual(editors?.document.fileName, readMe) }) - .build() - // Validate that the README.md is shown. - testWindow.onDidChangeActiveTextEditor((editors) => { - assert(editors) - const readMe = path.join(workspaceFolder.uri.fsPath, projectFolder, 'README.md') - assert.strictEqual(editors?.document.fileName, readMe) - }) + await vscode.commands.executeCommand('aws.toolkit.lambda.createServerlessLandProject') - await vscode.commands.executeCommand('aws.toolkit.lambda.createServerlessLandProject') + // projectNodes set from previous step - // projectNodes set from previous step + const projectNode = await rootNode + .getChildren() + .then( + (children) => + children.find( + (node) => + node instanceof AppNode && + node.label === 'workspaceFolder/my-project-from-Serverless-Land' + ) as AppNode | undefined + ) - const projectNode = await rootNode - .getChildren() - .then( - (children) => - children.find( - (node) => - node instanceof AppNode && node.label === 'workspaceFolder/my-project-from-Serverless-Land' - ) as AppNode | undefined - ) + assert.ok(projectNode, 'Expect Serverless Land project node in Application Builder') - assert.ok(projectNode, 'Expect Serverless Land project node in Application Builder') + // Check App Builder resources + const resourceNodes = await projectNode.getChildren() + assert.strictEqual(resourceNodes.length, 1) + assert.ok(resourceNodes[0] instanceof ResourceNode) - // Check App Builder resources - const resourceNodes = await projectNode.getChildren() - assert.strictEqual(resourceNodes.length, 1) - assert.ok(resourceNodes[0] instanceof ResourceNode) + // Validate Lambda resource configuration + const lambdaResource = resourceNodes[0] as ResourceNode + assert.strictEqual(lambdaResource.resource.resource.Type, 'AWS::Serverless::Function') + assert.strictEqual(lambdaResource.resource.resource.Runtime, 'dotnet8') + assert.strictEqual(lambdaResource.resource.resource.Id, 'HelloWorldFunction') + assert.deepStrictEqual(lambdaResource.resource.resource.Events, [ + { + Id: 'HelloWorld', + Type: 'Api', + Path: '/hello', + Method: 'get', + }, + ]) + assert.deepStrictEqual(lambdaResource.resource.resource.Environment, { + Variables: { + PARAM1: 'VALUE', + }, + }) - // Validate Lambda resource configuration - const lambdaResource = resourceNodes[0] as ResourceNode - assert.strictEqual(lambdaResource.resource.resource.Type, 'AWS::Serverless::Function') - assert.strictEqual(lambdaResource.resource.resource.Runtime, 'dotnet8') - assert.strictEqual(lambdaResource.resource.resource.Id, 'HelloWorldFunction') - assert.deepStrictEqual(lambdaResource.resource.resource.Events, [ - { - Id: 'HelloWorld', - Type: 'Api', - Path: '/hello', - Method: 'get', - }, - ]) - assert.deepStrictEqual(lambdaResource.resource.resource.Environment, { - Variables: { - PARAM1: 'VALUE', - }, + prompterTester.assertCallAll() }) - - prompterTester.assertCallAll() }) })