Skip to content

Commit

Permalink
Merge master into feature/sdkv3
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-toolkit-automation authored Mar 6, 2025
2 parents e057ec4 + da0b811 commit 8ad94fe
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Amazon Q Chat: You can now keep a \"library\" of prompt files in your home directory under `~/.aws/amazonq/prompts` and then quickly add them to the context using `@` on any project you’re working on. Prompt files are in markdown (`.md`) format."
}
196 changes: 101 additions & 95 deletions packages/core/src/testInteg/appBuilder/serverlessLand/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppBuilderRootNode>
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<AppBuilderRootNode>
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()
})
})

0 comments on commit 8ad94fe

Please sign in to comment.