Skip to content

Commit

Permalink
rename test description
Browse files Browse the repository at this point in the history
  • Loading branch information
vicheey committed Nov 15, 2024
1 parent 4a53b4f commit 96015ab
Show file tree
Hide file tree
Showing 3 changed files with 667 additions and 662 deletions.
270 changes: 136 additions & 134 deletions packages/core/src/test/shared/sam/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { CloudFormationTemplateRegistry } from '../../../shared/fs/templateRegis
import { getTestWindow } from '../vscode/window'
import { CancellationError } from '../../../shared/utilities/timeoutUtils'

describe('BuildWizard', async function () {
describe('SAM BuildWizard', async function () {
const createTester = async (params?: Partial<BuildParams>, arg?: TreeNode | undefined) =>
createWizardTester(new BuildWizard({ ...params }, await globals.templateRegistry, arg))

Expand Down Expand Up @@ -82,154 +82,156 @@ describe('BuildWizard', async function () {
})
})

describe('getBuildFlags', () => {
let sandbox: sinon.SinonSandbox
let projectRoot: vscode.Uri
const defaultFlags: string[] = ['--cached', '--parallel', '--save-params', '--use-container']
let quickPickItems: DataQuickPickItem<string>[]
describe('SAM build helper functions', () => {
describe('getBuildFlags', () => {
let sandbox: sinon.SinonSandbox
let projectRoot: vscode.Uri
const defaultFlags: string[] = ['--cached', '--parallel', '--save-params', '--use-container']
let quickPickItems: DataQuickPickItem<string>[]

beforeEach(() => {
sandbox = sinon.createSandbox()
projectRoot = vscode.Uri.parse('file:///path/to/project')
quickPickItems = [
{
label: 'Beta features',
data: '--beta-features',
description: 'Enable beta features',
},
{
label: 'Build in source',
data: '--build-in-source',
description: 'Opts in to build project in the source folder',
},
{
label: 'Cached',
data: '--cached',
description: 'Reuse build artifacts that have not changed from previous builds',
},
{
label: 'Debug',
data: '--debug',
description: 'Turn on debug logging to print debug messages and display timestamps',
},
{
label: 'Parallel',
data: '--parallel',
description: 'Enable parallel builds for AWS SAM template functions and layers',
},
{
label: 'Skip prepare infra',
data: '--skip-prepare-infra',
description: 'Skip preparation stage when there are no infrastructure changes',
},
{
label: 'Skip pull image',
data: '--skip-pull-image',
description: 'Skip pulling down the latest Docker image for Lambda runtime',
},
{
label: 'Use container',
data: '--use-container',
description: 'Build functions with an AWS Lambda-like container',
},
{
label: 'Save parameters',
data: '--save-params',
description: 'Save to samconfig.toml as default parameters',
},
]
})
beforeEach(() => {
sandbox = sinon.createSandbox()
projectRoot = vscode.Uri.parse('file:///path/to/project')
quickPickItems = [
{
label: 'Beta features',
data: '--beta-features',
description: 'Enable beta features',
},
{
label: 'Build in source',
data: '--build-in-source',
description: 'Opts in to build project in the source folder',
},
{
label: 'Cached',
data: '--cached',
description: 'Reuse build artifacts that have not changed from previous builds',
},
{
label: 'Debug',
data: '--debug',
description: 'Turn on debug logging to print debug messages and display timestamps',
},
{
label: 'Parallel',
data: '--parallel',
description: 'Enable parallel builds for AWS SAM template functions and layers',
},
{
label: 'Skip prepare infra',
data: '--skip-prepare-infra',
description: 'Skip preparation stage when there are no infrastructure changes',
},
{
label: 'Skip pull image',
data: '--skip-pull-image',
description: 'Skip pulling down the latest Docker image for Lambda runtime',
},
{
label: 'Use container',
data: '--use-container',
description: 'Build functions with an AWS Lambda-like container',
},
{
label: 'Save parameters',
data: '--save-params',
description: 'Save to samconfig.toml as default parameters',
},
]
})

afterEach(() => {
sandbox.restore() // Restore all stubs after each test
})
afterEach(() => {
sandbox.restore() // Restore all stubs after each test
})

it('should return flags from buildFlagsPrompter when paramsSource is Specify', async () => {
PrompterTester.init()
.handleQuickPick('Select build flags', async (picker) => {
await picker.untilReady()
assert.strictEqual(picker.items.length, 9)
assert.strictEqual(picker.title, 'Select build flags')
assert.deepStrictEqual(picker.items, quickPickItems)
const betaFeatures = picker.items[0]
const buildInSource = picker.items[1]
const cached = picker.items[2]
assert.strictEqual(betaFeatures.data, '--beta-features')
assert.strictEqual(buildInSource.data, '--build-in-source')
assert.strictEqual(cached.data, '--cached')
const acceptedItems = [betaFeatures, buildInSource, cached]
picker.acceptItems(...acceptedItems)
})
.build()
it('should return flags from buildFlagsPrompter when paramsSource is Specify', async () => {
PrompterTester.init()
.handleQuickPick('Select build flags', async (picker) => {
await picker.untilReady()
assert.strictEqual(picker.items.length, 9)
assert.strictEqual(picker.title, 'Select build flags')
assert.deepStrictEqual(picker.items, quickPickItems)
const betaFeatures = picker.items[0]
const buildInSource = picker.items[1]
const cached = picker.items[2]
assert.strictEqual(betaFeatures.data, '--beta-features')
assert.strictEqual(buildInSource.data, '--build-in-source')
assert.strictEqual(cached.data, '--cached')
const acceptedItems = [betaFeatures, buildInSource, cached]
picker.acceptItems(...acceptedItems)
})
.build()

const flags = await createMultiPick(quickPickItems, {
title: 'Select build flags',
ignoreFocusOut: true,
}).prompt()
const flags = await createMultiPick(quickPickItems, {
title: 'Select build flags',
ignoreFocusOut: true,
}).prompt()

assert.deepStrictEqual(flags, JSON.stringify(['--beta-features', '--build-in-source', '--cached']))
})
assert.deepStrictEqual(flags, JSON.stringify(['--beta-features', '--build-in-source', '--cached']))
})

it('should return config file flag when paramsSource is SamConfig', async () => {
const mockConfigFileUri = vscode.Uri.parse('file:///path/to/samconfig.toml')
const getConfigFileUriStub = sandbox.stub().resolves(mockConfigFileUri)
sandbox.stub(config, 'getConfigFileUri').callsFake(getConfigFileUriStub)
it('should return config file flag when paramsSource is SamConfig', async () => {
const mockConfigFileUri = vscode.Uri.parse('file:///path/to/samconfig.toml')
const getConfigFileUriStub = sandbox.stub().resolves(mockConfigFileUri)
sandbox.stub(config, 'getConfigFileUri').callsFake(getConfigFileUriStub)

const flags = await getBuildFlags(ParamsSource.SamConfig, projectRoot, defaultFlags)
assert.deepStrictEqual(flags, ['--config-file', mockConfigFileUri.fsPath])
})
const flags = await getBuildFlags(ParamsSource.SamConfig, projectRoot, defaultFlags)
assert.deepStrictEqual(flags, ['--config-file', mockConfigFileUri.fsPath])
})

it('should return default flags if getConfigFileUri throws an error', async () => {
const getConfigFileUriStub = sinon.stub().rejects(new Error('Config file not found'))
sandbox.stub(config, 'getConfigFileUri').callsFake(getConfigFileUriStub)
it('should return default flags if getConfigFileUri throws an error', async () => {
const getConfigFileUriStub = sinon.stub().rejects(new Error('Config file not found'))
sandbox.stub(config, 'getConfigFileUri').callsFake(getConfigFileUriStub)

const flags = await getBuildFlags(ParamsSource.SamConfig, projectRoot, defaultFlags)
assert.deepStrictEqual(flags, defaultFlags)
const flags = await getBuildFlags(ParamsSource.SamConfig, projectRoot, defaultFlags)
assert.deepStrictEqual(flags, defaultFlags)
})
})
})

describe('createParamsSourcePrompter', () => {
it('should return a prompter with the correct items with no valid samconfig', () => {
const expectedItems: DataQuickPickItem<ParamsSource>[] = [
{
label: 'Specify build flags',
data: ParamsSource.Specify,
},
{
label: 'Use default values',
data: ParamsSource.DefaultValues,
description: 'cached = true, parallel = true, use_container = true',
},
]
const prompter = createParamsSourcePrompter(false)
const quickPick = prompter.quickPick
assert.strictEqual(quickPick.title, 'Specify parameter source for build')
assert.strictEqual(quickPick.placeholder, 'Select configuration options for sam build')
assert.strictEqual(quickPick.items.length, 2)
assert.deepStrictEqual(quickPick.items, expectedItems)
})
describe('createParamsSourcePrompter', () => {
it('should return a prompter with the correct items with no valid samconfig', () => {
const expectedItems: DataQuickPickItem<ParamsSource>[] = [
{
label: 'Specify build flags',
data: ParamsSource.Specify,
},
{
label: 'Use default values',
data: ParamsSource.DefaultValues,
description: 'cached = true, parallel = true, use_container = true',
},
]
const prompter = createParamsSourcePrompter(false)
const quickPick = prompter.quickPick
assert.strictEqual(quickPick.title, 'Specify parameter source for build')
assert.strictEqual(quickPick.placeholder, 'Select configuration options for sam build')
assert.strictEqual(quickPick.items.length, 2)
assert.deepStrictEqual(quickPick.items, expectedItems)
})

it('should return a prompter with the correct items with valid samconfig', () => {
const expectedItems: DataQuickPickItem<ParamsSource>[] = [
{
label: 'Specify build flags',
data: ParamsSource.Specify,
},
{
label: 'Use default values from samconfig',
data: ParamsSource.SamConfig,
},
]
const prompter = createParamsSourcePrompter(true)
const quickPick = prompter.quickPick
assert.strictEqual(quickPick.title, 'Specify parameter source for build')
assert.strictEqual(quickPick.placeholder, 'Select configuration options for sam build')
assert.strictEqual(quickPick.items.length, 2)
assert.deepStrictEqual(quickPick.items, expectedItems)
it('should return a prompter with the correct items with valid samconfig', () => {
const expectedItems: DataQuickPickItem<ParamsSource>[] = [
{
label: 'Specify build flags',
data: ParamsSource.Specify,
},
{
label: 'Use default values from samconfig',
data: ParamsSource.SamConfig,
},
]
const prompter = createParamsSourcePrompter(true)
const quickPick = prompter.quickPick
assert.strictEqual(quickPick.title, 'Specify parameter source for build')
assert.strictEqual(quickPick.placeholder, 'Select configuration options for sam build')
assert.strictEqual(quickPick.items.length, 2)
assert.deepStrictEqual(quickPick.items, expectedItems)
})
})
})

describe('SAM Build', () => {
describe('SAM runBuild', () => {
let sandbox: sinon.SinonSandbox
let testFolder: TestFolder
let projectRoot: vscode.Uri
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/test/shared/sam/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { TemplateItem } from '../../../shared/ui/sam/templatePrompter'
import { ParamsSource } from '../../../shared/ui/sam/paramsSourcePrompter'
import { BucketSource } from '../../../shared/ui/sam/bucketPrompter'

describe('DeployWizard', async function () {
describe('SAM DeployWizard', async function () {
let sandbox: sinon.SinonSandbox
let testFolder: TestFolder
let projectRoot: vscode.Uri
Expand Down
Loading

0 comments on commit 96015ab

Please sign in to comment.