From 17ff3214dfece1f61711970ccb15e0a6bfe85494 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 20 May 2023 22:44:22 -0300 Subject: [PATCH] rework createGenerator parameters to match yeoman-environment --- src/helpers.ts | 16 ++++++++-------- test/helpers.spec.ts | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 717e742..db4767c 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-params */ import { mkdirSync, existsSync, rmSync } from 'node:fs'; import { resolve } from 'node:path'; import process from 'node:process'; @@ -10,7 +9,7 @@ import type { BaseGenerator, BaseGeneratorOptions, GetGeneratorConstructor, - GetGeneratorOptions, + InstantiateOptions, PromptAnswers, PromptQuestion, } from '@yeoman/types'; @@ -218,12 +217,13 @@ export class YeomanTest { * var angular = createGenerator('angular:app', deps); */ async createGenerator( - name: string, - dependencies: Dependency[], - args?: string[], - options?: GetGeneratorOptions, - localConfigOnly = true, + name: string | GetGeneratorConstructor, + options: { + dependencies?: Dependency[]; + localConfigOnly?: boolean; + } & InstantiateOptions = {}, ): Promise { + const { dependencies = [], localConfigOnly = true, ...instantiateOptions } = options; const env = await this.createEnv({ sharedOptions: { localConfigOnly } }); for (const dependency of dependencies) { if (typeof dependency === 'string') { @@ -233,7 +233,7 @@ export class YeomanTest { } } - return env.create(name, { generatorArgs: args, generatorOptions: options }); + return env.create(name, instantiateOptions); } /** diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index 29bc631..1688970 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -28,20 +28,29 @@ describe('yeoman-test', function () { describe('.createGenerator()', function () { it('create a new generator', async function () { - const generator = await helpers.createGenerator('unicorn:app', [[this.StubGenerator, { namespace: 'unicorn:app' }]]); + const generator = await helpers.createGenerator('unicorn:app', { + dependencies: [[this.StubGenerator, { namespace: 'unicorn:app' }]], + }); assert.ok(generator instanceof this.StubGenerator); }); it('pass args params to the generator', async function () { - const generator = await helpers.createGenerator('unicorn:app', [[this.StubGenerator, { namespace: 'unicorn:app' }]], ['temp']); + const generator = await helpers.createGenerator('unicorn:app', { + dependencies: [[this.StubGenerator, { namespace: 'unicorn:app' }]], + generatorArgs: ['temp'], + }); assert.deepEqual(generator.args, ['temp']); }); it('pass options param to the generator', async function () { - const generator = await helpers.createGenerator('unicorn:app', [[this.StubGenerator, { namespace: 'unicorn:app' }]], ['temp'], { - ui: 'tdd', + const generator = await helpers.createGenerator('unicorn:app', { + dependencies: [[this.StubGenerator, { namespace: 'unicorn:app' }]], + generatorArgs: ['temp'], + generatorOptions: { + ui: 'tdd', + }, }); assert.equal(generator.options.ui, 'tdd');