Skip to content

Commit 81951b3

Browse files
committed
save params before running command when --watch is selected
1 parent 5f012c8 commit 81951b3

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

packages/core/src/shared/sam/sync.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,15 @@ export async function runSamSync(args: SyncParams) {
513513
}),
514514
})
515515

516-
await runInTerminal(sam, 'sync')
516+
// with '--watch' selected, the sync process will run in the background until the user manually kills it
517+
// we need to save the stack and region to the samconfig file now, otherwise the user would not see latest deployed resoure during this sync process
517518
const { paramsSource, stackName, region, projectRoot } = args
518519
const shouldWriteSyncSamconfigGlobal = paramsSource !== ParamsSource.SamConfig && !!stackName && !!region
520+
if (boundArgs.includes('--watch')) {
521+
shouldWriteSyncSamconfigGlobal && (await writeSamconfigGlobal(projectRoot, stackName, region))
522+
}
523+
524+
await runInTerminal(sam, 'sync')
519525
shouldWriteSyncSamconfigGlobal && (await writeSamconfigGlobal(projectRoot, stackName, region))
520526
}
521527

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,93 @@ describe('SAM Sync', () => {
17311731
prompterTester.assertCallAll()
17321732
})
17331733

1734+
it('[entry: command palette] specify and save flag (with --watch) should save params before starting SAM process', async () => {
1735+
const prompterTester = PrompterTester.init()
1736+
.handleQuickPick('Select a SAM/CloudFormation Template', async (quickPick) => {
1737+
// Need sometime to wait for the template to search for template file
1738+
await quickPick.untilReady()
1739+
assert.strictEqual(quickPick.items[0].label, templateFile.fsPath)
1740+
quickPick.acceptItem(quickPick.items[0])
1741+
})
1742+
.handleQuickPick('Specify parameters for deploy', async (picker) => {
1743+
// Need time to check samconfig.toml file and generate options
1744+
await picker.untilReady()
1745+
assert.strictEqual(picker.items[0].label, 'Specify required parameters and save as defaults')
1746+
picker.acceptItem(picker.items[0])
1747+
})
1748+
.handleQuickPick('Select a region', (quickPick) => {
1749+
const select = quickPick.items.filter((i) => i.detail === 'us-west-2')[0]
1750+
quickPick.acceptItem(select || quickPick.items[0])
1751+
})
1752+
.handleQuickPick('Select a CloudFormation Stack', async (picker) => {
1753+
await picker.untilReady()
1754+
assert.strictEqual(picker.items[2].label, 'stack3')
1755+
picker.acceptItem(picker.items[2])
1756+
})
1757+
.handleQuickPick('Select an S3 Bucket', async (picker) => {
1758+
await picker.untilReady()
1759+
assert.strictEqual(picker.items.length, 3)
1760+
assert.strictEqual(picker.items[2].label, 'stack-3-bucket')
1761+
picker.acceptItem(picker.items[2])
1762+
})
1763+
.handleQuickPick('Specify parameters for sync', async (picker) => {
1764+
await picker.untilReady()
1765+
assert.strictEqual(picker.items.length, 9)
1766+
const dependencyLayer = picker.items.filter((item) => item.label === 'Dependency layer')[0]
1767+
const useContainer = picker.items.filter((item) => item.label === 'Use container')[0]
1768+
const watch = picker.items.filter((item) => item.label === 'Watch')[0]
1769+
picker.acceptItems(dependencyLayer, useContainer, watch)
1770+
})
1771+
.build()
1772+
1773+
// Invoke sync command from command palette
1774+
await runSync('code', undefined)
1775+
1776+
assert(mockGetSamCliPath.calledOnce)
1777+
assert(mockChildProcessClass.calledOnce)
1778+
assert.deepEqual(mockChildProcessClass.getCall(0).args, [
1779+
'sam-cli-path',
1780+
[
1781+
'sync',
1782+
'--code',
1783+
'--template',
1784+
`${templateFile.fsPath}`,
1785+
'--s3-bucket',
1786+
'stack-3-bucket',
1787+
'--stack-name',
1788+
'stack3',
1789+
'--region',
1790+
'us-west-2',
1791+
'--no-dependency-layer',
1792+
'--save-params',
1793+
'--dependency-layer',
1794+
'--use-container',
1795+
'--watch',
1796+
],
1797+
{
1798+
spawnOptions: {
1799+
cwd: projectRoot?.fsPath,
1800+
env: {
1801+
AWS_TOOLING_USER_AGENT: 'AWS-Toolkit-For-VSCode/testPluginVersion',
1802+
SAM_CLI_TELEMETRY: '0',
1803+
},
1804+
},
1805+
},
1806+
])
1807+
assert(mockGetSpawnEnv.calledOnce)
1808+
assert(spyRunInterminal.calledOnce)
1809+
assert.deepEqual(spyRunInterminal.getCall(0).args, [mockSamSyncChildProcess, 'sync'])
1810+
assert.strictEqual(spyWriteSamconfigGlobal.callCount, 2)
1811+
assert(spyWriteSamconfigGlobal.calledBefore(spyRunInterminal))
1812+
// Check telementry
1813+
assertTelemetry('sam_sync', { result: 'Succeeded', source: undefined })
1814+
assertTelemetryCurried('sam_sync')({
1815+
syncedResources: 'CodeOnly',
1816+
source: undefined,
1817+
})
1818+
prompterTester.assertCallAll()
1819+
})
1820+
17341821
it('[entry: template file] specify flag should instantiate correct process in terminal', async () => {
17351822
const prompterTester = PrompterTester.init()
17361823
.handleQuickPick('Specify parameters for deploy', async (picker) => {

0 commit comments

Comments
 (0)