From 933ab36429b32f41186e3544ed6b4a2e0fea965c Mon Sep 17 00:00:00 2001 From: Michael Goberling Date: Fri, 26 Jan 2024 18:50:11 -0500 Subject: [PATCH] fix: destructure property error --- src/commands/templates/install.js | 2 +- test/commands/templates/install.test.js | 32 ++++++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/commands/templates/install.js b/src/commands/templates/install.js index 33cbc17..44a4f9d 100644 --- a/src/commands/templates/install.js +++ b/src/commands/templates/install.js @@ -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) diff --git a/test/commands/templates/install.test.js b/test/commands/templates/install.test.js index 567d742..d76aca9 100644 --- a/test/commands/templates/install.test.js +++ b/test/commands/templates/install.test.js @@ -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, @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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() @@ -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({