Skip to content

Commit e79e9e5

Browse files
committed
add prompter tester validation and registry clean up
1 parent 86c4b3d commit e79e9e5

File tree

5 files changed

+123
-56
lines changed

5 files changed

+123
-56
lines changed

packages/core/src/test/awsService/appBuilder/wizards/deployTypeWizard.test.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('DeployTypeWizard', function () {
3232

3333
it('customer abort wizard should not call any command function', async function () {
3434
// Given
35-
PrompterTester.init()
35+
const prompterTester = PrompterTester.init()
3636
.handleQuickPick('Select deployment command', async (picker) => {
3737
await picker.untilReady()
3838
assert.strictEqual(picker.items[0].label, 'Sync')
@@ -45,6 +45,7 @@ describe('DeployTypeWizard', function () {
4545
const choices = await deployTypeWizard.run()
4646
// Then
4747
assert(!choices)
48+
prompterTester.assertHandlerCall('Select deployment command', 1)
4849
})
4950

5051
it('deploy is selected', async function () {
@@ -54,7 +55,7 @@ describe('DeployTypeWizard', function () {
5455
* More cases are test in Deploy.test.ts
5556
*
5657
*/
57-
PrompterTester.init()
58+
const prompterTester = PrompterTester.init()
5859
.handleQuickPick('Select deployment command', async (picker) => {
5960
await picker.untilReady()
6061
assert.strictEqual(picker.items[0].label, 'Sync')
@@ -68,11 +69,6 @@ describe('DeployTypeWizard', function () {
6869
.handleInputBox('Specify SAM parameter value for DestinationBucketName', (inputBox) => {
6970
inputBox.acceptValue('my-destination-bucket-name')
7071
})
71-
.handleQuickPick('Select a SAM/CloudFormation Template', async (quickPick) => {
72-
// Need sometime to wait for the template to search for template file
73-
await quickPick.untilReady()
74-
quickPick.acceptItem(quickPick.items[0])
75-
})
7672
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
7773
// Need time to check samconfig.toml file and generate options
7874
await quickPick.untilReady()
@@ -84,6 +80,7 @@ describe('DeployTypeWizard', function () {
8480
const choices = await deployTypeWizard.run()
8581
// Then
8682
assert.strictEqual(choices?.choice, 'deploy')
83+
prompterTester.assertAllHandlerCall(1)
8784
})
8885

8986
it('sync is selected', async function () {
@@ -93,19 +90,14 @@ describe('DeployTypeWizard', function () {
9390
* More cases are test in Sync.test.ts
9491
*
9592
*/
96-
PrompterTester.init()
93+
const prompterTester = PrompterTester.init()
9794
.handleQuickPick('Select deployment command', async (picker) => {
9895
await picker.untilReady()
9996
assert.strictEqual(picker.items[0].label, 'Sync')
10097
assert.strictEqual(picker.items[1].label, 'Deploy')
10198
assert.strictEqual(picker.items.length, 2)
10299
picker.acceptItem(picker.items[0])
103100
})
104-
.handleQuickPick('Select a SAM/CloudFormation Template', async (quickPick) => {
105-
// Need sometime to wait for the template to search for template file
106-
await quickPick.untilReady()
107-
quickPick.acceptItem(quickPick.items[0])
108-
})
109101
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
110102
// Need time to check samconfig.toml file and generate options
111103
await quickPick.untilReady()
@@ -117,5 +109,6 @@ describe('DeployTypeWizard', function () {
117109
const choices = await deployTypeWizard.run()
118110
// Then
119111
assert.strictEqual(choices?.choice, 'sync')
112+
prompterTester.assertAllHandlerCall(1)
120113
})
121114
})

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('DeployWizard', async function () {
9393
// generate samconfig.toml in temporary test folder
9494
await testFolder.write('samconfig.toml', samconfigInvalidData)
9595

96-
PrompterTester.init()
96+
const prompterTester = PrompterTester.init()
9797
.handleInputBox('Specify SAM parameter value for SourceBucketName', (inputBox) => {
9898
inputBox.acceptValue('my-source-bucket-name')
9999
})
@@ -143,6 +143,7 @@ describe('DeployWizard', async function () {
143143
assert.strictEqual(parameters.region, 'us-west-2')
144144
assert.strictEqual(parameters.stackName, 'stack1')
145145
assert.strictEqual(parameters.bucketSource, 0)
146+
prompterTester.assertAllHandlerCall(1)
146147
})
147148

148149
it('happy path with valid samconfig.toml', async () => {
@@ -163,7 +164,7 @@ describe('DeployWizard', async function () {
163164
// generate samconfig.toml in temporary test folder
164165
await testFolder.write('samconfig.toml', samconfigCompleteData)
165166

166-
PrompterTester.init()
167+
const prompterTester = PrompterTester.init()
167168
.handleInputBox('Specify SAM parameter value for SourceBucketName', (inputBox) => {
168169
inputBox.acceptValue('my-source-bucket-name')
169170
})
@@ -194,6 +195,7 @@ describe('DeployWizard', async function () {
194195
assert(!parameters.region)
195196
assert(!parameters.stackName)
196197
assert(!parameters.bucketSource)
198+
prompterTester.assertAllHandlerCall(1)
197199
})
198200
})
199201

@@ -301,7 +303,7 @@ describe('DeployWizard', async function () {
301303

302304
await testFolder.write('samconfig.toml', samconfigCompleteData)
303305

304-
PrompterTester.init()
306+
const prompterTester = PrompterTester.init()
305307
.handleQuickPick('Select a SAM/CloudFormation Template', async (quickPick) => {
306308
// Need sometime to wait for the template to search for template file
307309
await quickPick.untilReady()
@@ -331,6 +333,7 @@ describe('DeployWizard', async function () {
331333
assert.strictEqual(parameters.region, 'us-west-2')
332334
assert(!parameters.stackName)
333335
assert(!parameters.bucketSource)
336+
prompterTester.assertAllHandlerCall(1)
334337
})
335338
})
336339

@@ -362,7 +365,7 @@ describe('DeployWizard', async function () {
362365
* - bucketName : [Skip] automatically set for bucketSource option 1
363366
*/
364367

365-
PrompterTester.init()
368+
const prompterTester = PrompterTester.init()
366369
.handleInputBox('Specify SAM parameter value for SourceBucketName', (inputBox) => {
367370
inputBox.acceptValue('my-source-bucket-name')
368371
})
@@ -412,6 +415,7 @@ describe('DeployWizard', async function () {
412415
assert.strictEqual(parameters.stackName, 'stack2')
413416
assert.strictEqual(parameters.bucketSource, 0)
414417
assert(!parameters.bucketName)
418+
prompterTester.assertAllHandlerCall(1)
415419
})
416420

417421
it('happy path with valid samconfig.toml', async () => {
@@ -432,7 +436,7 @@ describe('DeployWizard', async function () {
432436
// generate samconfig.toml in temporary test folder
433437
await testFolder.write('samconfig.toml', samconfigCompleteData)
434438

435-
PrompterTester.init()
439+
const prompterTester = PrompterTester.init()
436440
.handleInputBox('Specify SAM parameter value for SourceBucketName', (inputBox) => {
437441
inputBox.acceptValue('my-source-bucket-name')
438442
})
@@ -463,6 +467,7 @@ describe('DeployWizard', async function () {
463467
assert(!parameters.region)
464468
assert(!parameters.stackName)
465469
assert(!parameters.bucketSource)
470+
prompterTester.assertAllHandlerCall(1)
466471
})
467472
})
468473

@@ -487,7 +492,7 @@ describe('DeployWizard', async function () {
487492
const templateFile2 = vscode.Uri.file(await testFolder2.write('template.yaml', validTemplateData))
488493
await (await globals.templateRegistry).addItem(templateFile2)
489494

490-
PrompterTester.init()
495+
const prompterTester = PrompterTester.init()
491496
.handleQuickPick('Select a SAM/CloudFormation Template', async (quickPick) => {
492497
// Need sometime to wait for the template to search for template file
493498
await quickPick.untilReady()
@@ -544,6 +549,7 @@ describe('DeployWizard', async function () {
544549
assert.strictEqual(parameters.stackName, 'stack3')
545550
assert.strictEqual(parameters.bucketSource, 1)
546551
assert.strictEqual(parameters.bucketName, 'stack-3-bucket')
552+
prompterTester.assertAllHandlerCall(1)
547553
})
548554

549555
it('happy path with samconfig.toml', async () => {
@@ -569,7 +575,7 @@ describe('DeployWizard', async function () {
569575
await testFolder.write('samconfig.toml', samconfigCompleteData)
570576
// Simulate return of deployed stacks
571577

572-
PrompterTester.init()
578+
const prompterTester = PrompterTester.init()
573579
.handleQuickPick('Select a SAM/CloudFormation Template', async (quickPick) => {
574580
// Need sometime to wait for the template to search for template file
575581
await quickPick.untilReady()
@@ -596,6 +602,7 @@ describe('DeployWizard', async function () {
596602
assert(!parameters.region)
597603
assert(!parameters.stackName)
598604
assert(!parameters.bucketSource)
605+
prompterTester.assertAllHandlerCall(1)
599606
})
600607
})
601608
})

0 commit comments

Comments
 (0)