Skip to content

Commit

Permalink
fix: destructure property error (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelGoberling authored Jan 27, 2024
1 parent ecffdcd commit 743f96e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/commands/templates/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class InstallCommand extends BaseCommand {
aioLogger.debug(`flags['template-options']: ${JSON.stringify(templateOptions)}`)

const templatePath = require.resolve(templateName, { paths: [process.cwd()] })
const gen = env.instantiate(require(templatePath), {
const gen = await env.instantiate(require(templatePath), {
options: { ...defaultOptions, ...templateOptions }
})
await env.runGenerator(gen)
Expand Down
32 changes: 21 additions & 11 deletions test/commands/templates/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ Ims.context.setCli.mockReset()
Ims.getToken.mockReset()
Ims.getToken.mockResolvedValue('bowling')

const yeomanEnvInstantiate = jest.fn()
const yeomanEnvInstantiate = jest.fn(async () => ({}))
const yeomanEnvRunGenerator = jest.fn()
const yeomanEnvOptionsGet = jest.fn()
const yeomanEnvOptionsSet = jest.fn()
const createEnvReturnValue = {
instantiate: yeomanEnvInstantiate,
runGenerator: jest.fn()
runGenerator: yeomanEnvRunGenerator
}
Object.defineProperty(createEnvReturnValue, 'options', {
get: yeomanEnvOptionsGet,
Expand Down Expand Up @@ -146,11 +147,12 @@ describe('run', () => {

getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])

expect.assertions(7)
expect.assertions(8)
await expect(command.run()).resolves.toBeUndefined()
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', argPath])
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
expect(mockTemplateHandlerInstance.installTemplate).toHaveBeenCalledWith('org-id', 'project-id')
expect(getTemplateRequiredServiceNames).not.toHaveBeenCalled()
expect(writeObjectToPackageJson).toHaveBeenCalledWith({
Expand All @@ -172,11 +174,12 @@ describe('run', () => {

getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])

expect.assertions(7)
expect.assertions(8)
await expect(command.run()).resolves.toBeUndefined()
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', templateName])
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
expect(mockTemplateHandlerInstance.installTemplate).toHaveBeenCalledWith('org-id', 'project-id')
expect(getTemplateRequiredServiceNames).not.toHaveBeenCalled()
expect(writeObjectToPackageJson).toHaveBeenCalledWith({
Expand All @@ -198,11 +201,12 @@ describe('run', () => {

getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])

expect.assertions(7)
expect.assertions(8)
await expect(command.run()).resolves.toBeUndefined()
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', templateName])
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': true, force: true } })
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
expect(mockTemplateHandlerInstance.installTemplate).toHaveBeenCalledWith('org-id', 'project-id')
expect(getTemplateRequiredServiceNames).not.toHaveBeenCalled()
expect(writeObjectToPackageJson).toHaveBeenCalledWith({
Expand All @@ -224,11 +228,12 @@ describe('run', () => {

getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])

expect.assertions(7)
expect.assertions(8)
await expect(command.run()).resolves.toBeUndefined()
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', templateName])
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: true })
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
expect(mockTemplateHandlerInstance.installTemplate).toHaveBeenCalledWith('org-id', 'project-id')
expect(getTemplateRequiredServiceNames).not.toHaveBeenCalled()
expect(writeObjectToPackageJson).toHaveBeenCalledWith({
Expand All @@ -250,11 +255,12 @@ describe('run', () => {

getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])

expect.assertions(7)
expect.assertions(8)
await expect(command.run()).resolves.toBeUndefined()
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', templateName])
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
expect(mockTemplateHandlerInstance.installTemplate).toHaveBeenCalledWith('org-id', 'project-id')
expect(getTemplateRequiredServiceNames).not.toHaveBeenCalled()
expect(writeObjectToPackageJson).toHaveBeenCalledWith({
Expand All @@ -277,11 +283,12 @@ describe('run', () => {
getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])
getTemplateRequiredServiceNames.mockReturnValueOnce(['runtime', 'GraphQLServiceSDK', 'AssetComputeSDK'])

expect.assertions(8)
expect.assertions(9)
await expect(command.run()).resolves.toBeUndefined()
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', templateName])
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
expect(mockTemplateHandlerInstance.installTemplate).not.toHaveBeenCalled()
expect(getTemplateRequiredServiceNames).toHaveBeenCalledWith(templateName)
expect(writeObjectToPackageJson).toHaveBeenCalledWith({
Expand All @@ -305,11 +312,12 @@ describe('run', () => {
getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])
getTemplateRequiredServiceNames.mockReturnValueOnce([])

expect.assertions(7)
expect.assertions(8)
await expect(command.run()).resolves.toBeUndefined()
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', templateName])
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
expect(mockTemplateHandlerInstance.installTemplate).not.toHaveBeenCalled()
expect(getTemplateRequiredServiceNames).toHaveBeenCalledWith(templateName)
expect(writeObjectToPackageJson).toHaveBeenCalledWith({
Expand All @@ -334,11 +342,12 @@ describe('run', () => {

getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])

expect.assertions(7)
expect.assertions(8)
await expect(command.run()).resolves.toBeUndefined()
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', templateName])
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
expect(mockTemplateHandlerInstance.installTemplate).toHaveBeenCalledWith('org-id', 'project-id')
expect(getTemplateRequiredServiceNames).not.toHaveBeenCalled()
expect(writeObjectToPackageJson).not.toHaveBeenCalled()
Expand Down Expand Up @@ -377,11 +386,12 @@ describe('template-options', () => {

getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])

expect.assertions(7)
expect.assertions(8)
await expect(command.run()).resolves.toBeUndefined()
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', argPath])
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
expect(mockTemplateHandlerInstance.installTemplate).toHaveBeenCalledWith('org-id', 'project-id')
expect(getTemplateRequiredServiceNames).not.toHaveBeenCalled()
expect(writeObjectToPackageJson).toHaveBeenCalledWith({
Expand Down

0 comments on commit 743f96e

Please sign in to comment.