Skip to content

Commit 743f96e

Browse files
fix: destructure property error (#63)
1 parent ecffdcd commit 743f96e

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/commands/templates/install.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class InstallCommand extends BaseCommand {
6363
aioLogger.debug(`flags['template-options']: ${JSON.stringify(templateOptions)}`)
6464

6565
const templatePath = require.resolve(templateName, { paths: [process.cwd()] })
66-
const gen = env.instantiate(require(templatePath), {
66+
const gen = await env.instantiate(require(templatePath), {
6767
options: { ...defaultOptions, ...templateOptions }
6868
})
6969
await env.runGenerator(gen)

test/commands/templates/install.test.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ Ims.context.setCli.mockReset()
4141
Ims.getToken.mockReset()
4242
Ims.getToken.mockResolvedValue('bowling')
4343

44-
const yeomanEnvInstantiate = jest.fn()
44+
const yeomanEnvInstantiate = jest.fn(async () => ({}))
45+
const yeomanEnvRunGenerator = jest.fn()
4546
const yeomanEnvOptionsGet = jest.fn()
4647
const yeomanEnvOptionsSet = jest.fn()
4748
const createEnvReturnValue = {
4849
instantiate: yeomanEnvInstantiate,
49-
runGenerator: jest.fn()
50+
runGenerator: yeomanEnvRunGenerator
5051
}
5152
Object.defineProperty(createEnvReturnValue, 'options', {
5253
get: yeomanEnvOptionsGet,
@@ -146,11 +147,12 @@ describe('run', () => {
146147

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

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

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

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

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

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

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

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

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

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

280-
expect.assertions(8)
286+
expect.assertions(9)
281287
await expect(command.run()).resolves.toBeUndefined()
282288
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', templateName])
283289
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
284290
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
291+
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
285292
expect(mockTemplateHandlerInstance.installTemplate).not.toHaveBeenCalled()
286293
expect(getTemplateRequiredServiceNames).toHaveBeenCalledWith(templateName)
287294
expect(writeObjectToPackageJson).toHaveBeenCalledWith({
@@ -305,11 +312,12 @@ describe('run', () => {
305312
getNpmDependency.mockResolvedValueOnce([templateName, '1.0.0'])
306313
getTemplateRequiredServiceNames.mockReturnValueOnce([])
307314

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

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

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

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

380-
expect.assertions(7)
389+
expect.assertions(8)
381390
await expect(command.run()).resolves.toBeUndefined()
382391
expect(runScript).toHaveBeenCalledWith('npm', process.cwd(), ['install', argPath])
383392
expect(yeomanEnvInstantiate).toHaveBeenCalledWith(expect.any(Object), { options: { 'skip-prompt': false, force: true } })
384393
expect(yeomanEnvOptionsSet).toHaveBeenCalledWith({ skipInstall: false })
394+
expect(yeomanEnvRunGenerator).toHaveBeenCalledWith(expect.any(Object))
385395
expect(mockTemplateHandlerInstance.installTemplate).toHaveBeenCalledWith('org-id', 'project-id')
386396
expect(getTemplateRequiredServiceNames).not.toHaveBeenCalled()
387397
expect(writeObjectToPackageJson).toHaveBeenCalledWith({

0 commit comments

Comments
 (0)