Skip to content

Commit 91859e2

Browse files
authored
fix(lambda): flakiness due to existing template.yaml #6924
## Problem fix #6921 ## Solution Refactor the tests for cleaner creating and deletion template.yaml file. - Scope and group tests cases based on required starting template. - Update assertion and error message.
1 parent 4606f5e commit 91859e2

File tree

2 files changed

+83
-70
lines changed

2 files changed

+83
-70
lines changed

packages/core/src/test/awsService/appBuilder/walkthrough.test.ts

+77-66
Original file line numberDiff line numberDiff line change
@@ -166,82 +166,93 @@ describe('AppBuilder Walkthrough', function () {
166166
const prevInfo = 'random text'
167167
assert.ok(workspaceUri)
168168

169-
before(async function () {
170-
await fs.delete(vscode.Uri.joinPath(workspaceUri, 'template.yaml'), { force: true })
171-
})
172-
173-
beforeEach(async function () {
174-
await fs.writeFile(vscode.Uri.joinPath(workspaceUri, 'template.yaml'), prevInfo)
175-
})
176-
177-
afterEach(async function () {
178-
await fs.delete(vscode.Uri.joinPath(workspaceUri, 'template.yaml'), { force: true })
179-
})
169+
describe('start without existing template', async () => {
170+
beforeEach(async () => {
171+
await fs.delete(vscode.Uri.joinPath(workspaceUri, 'template.yaml'), { force: true })
172+
})
180173

181-
it('open existing template', async function () {
182-
// Given no template exist
183-
await fs.delete(vscode.Uri.joinPath(workspaceUri, 'template.yaml'), { force: true })
184-
// When
185-
await genWalkthroughProject('CustomTemplate', workspaceUri, undefined)
186-
// Then nothing should be created
187-
assert.equal(await fs.exists(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), false)
174+
it('open existing template', async function () {
175+
// When
176+
await genWalkthroughProject('CustomTemplate', workspaceUri, undefined)
177+
// Then nothing should be created
178+
assert.ok(!(await fs.exists(vscode.Uri.joinPath(workspaceUri, 'template.yaml'))))
179+
})
188180
})
189181

190-
it('build an app with appcomposer overwrite', async function () {
191-
getTestWindow().onDidShowMessage((message) => {
192-
message.selectItem('Yes')
182+
describe('start with an existing template', async () => {
183+
beforeEach(async () => {
184+
await fs.writeFile(vscode.Uri.joinPath(workspaceUri, 'template.yaml'), prevInfo)
193185
})
194-
// When
195-
await genWalkthroughProject('Visual', workspaceUri, undefined)
196-
// Then
197-
assert.notEqual(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)
198-
})
199186

200-
it('build an app with appcomposer no overwrite', async function () {
201-
// Given
202-
getTestWindow().onDidShowMessage((message) => {
203-
message.selectItem('No')
187+
afterEach(async function () {
188+
await fs.delete(vscode.Uri.joinPath(workspaceUri, 'template.yaml'), { force: true })
204189
})
205-
// When
206-
try {
207-
// When
208-
await genWalkthroughProject('Visual', workspaceUri, undefined)
209-
assert.fail('A file named template.yaml already exists in this path.')
210-
} catch (e) {
211-
assert.equal((e as Error).message, 'A file named template.yaml already exists in this path.')
212-
}
213-
// Then
214-
assert.equal(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)
215-
})
216190

217-
it('download serverlessland proj', async function () {
218-
// Given
219-
// select overwrite
220-
getTestWindow().onDidShowMessage((message) => {
221-
message.selectItem('Yes')
191+
describe('override existing template', async () => {
192+
beforeEach(() => {
193+
getTestWindow().onDidShowMessage((message) => {
194+
assert.strictEqual(
195+
message.message,
196+
'template.yaml already exist in the selected directory, overwrite?'
197+
)
198+
message.selectItem('Yes')
199+
})
200+
})
201+
202+
it('build an app with appcomposer', async function () {
203+
// When
204+
await genWalkthroughProject('Visual', workspaceUri, undefined)
205+
// Then
206+
assert.notEqual(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)
207+
})
208+
209+
it('download serverlessland proj', async function () {
210+
// When
211+
await genWalkthroughProject('API', workspaceUri, 'python')
212+
// Then template should be overwritten
213+
assert.equal(await fs.exists(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), true)
214+
assert.notEqual(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)
215+
})
222216
})
223-
// When
224-
await genWalkthroughProject('API', workspaceUri, 'python')
225-
// Then template should be overwritten
226-
assert.equal(await fs.exists(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), true)
227-
assert.notEqual(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)
228-
})
229217

230-
it('download serverlessland proj no overwrite', async function () {
231-
// Given existing template.yaml
232-
// select do not overwrite
233-
getTestWindow().onDidShowMessage((message) => {
234-
message.selectItem('No')
218+
describe('without override existing template', async () => {
219+
beforeEach(() => {
220+
// Given existing template.yaml
221+
// select do not overwrite
222+
getTestWindow().onDidShowMessage((message) => {
223+
assert.strictEqual(
224+
message.message,
225+
'template.yaml already exist in the selected directory, overwrite?'
226+
)
227+
message.selectItem('No')
228+
})
229+
})
230+
231+
it('build an app with appcomposer', async function () {
232+
// When
233+
try {
234+
// When
235+
await genWalkthroughProject('Visual', workspaceUri, undefined)
236+
assert.fail('Expect failure due to template.yaml already exists in this path, but see success.')
237+
} catch (e) {
238+
assert.equal((e as Error).message, 'A file named template.yaml already exists in this path.')
239+
}
240+
// Then
241+
assert.equal(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)
242+
})
243+
244+
it('download serverlessland proj', async function () {
245+
try {
246+
// When
247+
await genWalkthroughProject('S3', workspaceUri, 'python')
248+
assert.fail('Expect failure due to template.yaml already exists in this path, but see success.')
249+
} catch (e) {
250+
assert.equal((e as Error).message, 'A file named template.yaml already exists in this path.')
251+
}
252+
// Then no overwrite happens
253+
assert.equal(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)
254+
})
235255
})
236-
try {
237-
// When
238-
await genWalkthroughProject('S3', workspaceUri, 'python')
239-
assert.fail('A file named template.yaml already exists in this path.')
240-
} catch (e) {
241-
assert.equal((e as Error).message, 'A file named template.yaml already exists in this path.')
242-
}
243-
// Then no overwrite happens
244-
assert.equal(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)
245256
})
246257
})
247258

packages/core/src/test/shared/sam/build.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,16 @@ describe('SAM runBuild', () => {
332332
})
333333

334334
afterEach(() => {
335+
spyRunInterminal.resetHistory()
335336
sandbox.restore()
336337
})
337338

338339
const verifyCorrectDependencyCall = () => {
339340
// Prefer count comparison for debugging flakiness
340-
assert.strictEqual(mockGetSamCliPath.callCount, 1)
341-
assert.strictEqual(mockChildProcessClass.callCount, 1)
342-
assert.strictEqual(mockGetSpawnEnv.callCount, 1)
343-
assert.strictEqual(spyRunInterminal.callCount, 1)
341+
assert.strictEqual(1, mockGetSamCliPath.callCount, 'GetSamCliPath')
342+
assert.strictEqual(1, mockChildProcessClass.callCount, 'ChildProcessClass')
343+
assert.strictEqual(1, mockGetSpawnEnv.callCount, 'GetSpawnEnv')
344+
assert.strictEqual(1, spyRunInterminal.callCount, 'RunInterminal')
344345
assert.deepEqual(spyRunInterminal.getCall(0).args, [mockSamBuildChildProcess, 'build'])
345346
}
346347

@@ -527,6 +528,7 @@ describe('SAM runBuild', () => {
527528
},
528529
},
529530
])
531+
530532
verifyCorrectDependencyCall()
531533
prompterTester.assertCallAll()
532534
})

0 commit comments

Comments
 (0)