@@ -27,12 +27,14 @@ import { getProjectRootUri } from '../../../shared/sam/utils'
2727import sinon from 'sinon'
2828import { createMultiPick , DataQuickPickItem } from '../../../shared/ui/pickerPrompter'
2929import * as config from '../../../shared/sam/config'
30+ import * as utils from '../../../shared/sam/utils'
3031import { PrompterTester } from '../wizards/prompterTester'
3132import { getWorkspaceFolder , TestFolder } from '../../testUtil'
3233import { samconfigCompleteData , validTemplateData } from './samTestUtils'
3334import { CloudFormationTemplateRegistry } from '../../../shared/fs/templateRegistry'
3435import { getTestWindow } from '../vscode/window'
3536import { CancellationError } from '../../../shared/utilities/timeoutUtils'
37+ import { SemVer } from 'semver'
3638
3739describe ( 'SAM BuildWizard' , async function ( ) {
3840 const createTester = async ( params ?: Partial < BuildParams > , arg ?: TreeNode | undefined ) =>
@@ -232,10 +234,42 @@ describe('SAM build helper functions', () => {
232234 } )
233235
234236 describe ( 'resolveBuildFlags' , ( ) => {
235- it ( 'should add --no-use-container if the buildFlags array does not contain --use-container' , ( ) => {
237+ let sandbox : sinon . SinonSandbox
238+ let pathAndVersionStub : sinon . SinonStub < any [ ] , any >
239+
240+ beforeEach ( ( ) => {
241+ sandbox = sinon . createSandbox ( )
242+ } )
243+
244+ afterEach ( ( ) => {
245+ sandbox . restore ( )
246+ } )
247+
248+ it ( 'should add --no-use-container if the buildFlags array does not contain --use-container' , async ( ) => {
249+ const normalVersion = { path : 'file:///path/to/cli' , parsedVersion : new SemVer ( '1.133.0' ) }
250+ pathAndVersionStub = sandbox . stub ( ) . resolves ( normalVersion )
251+ sandbox . stub ( utils , 'getSamCliPathAndVersion' ) . callsFake ( pathAndVersionStub )
236252 const buildFlags : string [ ] = [ '--cached' , '--debug' , '--parallel' ]
237253 const resolvedBuildFlags = [ '--cached' , '--debug' , '--parallel' , '--no-use-container' ]
238- assert . deepStrictEqual ( resolvedBuildFlags , resolveBuildFlags ( buildFlags ) )
254+ assert . deepEqual ( resolvedBuildFlags , await resolveBuildFlags ( buildFlags , normalVersion . parsedVersion ) )
255+ } )
256+
257+ it ( 'should return the original buildFlags array if SAM CLI version is less than 1.133' , async ( ) => {
258+ const lowerVersion = { path : 'file:///path/to/cli' , parsedVersion : new SemVer ( '1.110.0' ) }
259+ const pathAndVersionStub = sandbox . stub ( ) . resolves ( lowerVersion )
260+ sandbox . stub ( utils , 'getSamCliPathAndVersion' ) . callsFake ( pathAndVersionStub )
261+ const buildFlags = [ '--cached' , '--parallel' , '--save-params' ]
262+ const resolvedBuildFlags = await resolveBuildFlags ( buildFlags , lowerVersion . parsedVersion )
263+ assert . deepEqual ( resolvedBuildFlags , buildFlags )
264+ } )
265+
266+ it ( 'should not add "--no-use-container" if "--use-container" is already present' , async ( ) => {
267+ const normalVersion = { path : 'file:///path/to/cli' , parsedVersion : new SemVer ( '1.110.0' ) }
268+ pathAndVersionStub = sandbox . stub ( ) . resolves ( normalVersion )
269+ sandbox . stub ( utils , 'getSamCliPathAndVersion' ) . callsFake ( pathAndVersionStub )
270+ const buildFlags = [ '--cached' , '--parallel' , '--save-params' , '--use-container' ]
271+ const resolvedBuildFlags = await resolveBuildFlags ( buildFlags , normalVersion . parsedVersion )
272+ assert . deepStrictEqual ( resolvedBuildFlags , buildFlags )
239273 } )
240274 } )
241275} )
0 commit comments