@@ -9,6 +9,7 @@ import { execaCommandSync } from 'execa';
99import { coerce } from 'semver' ;
1010import type FullEnvironment from 'yeoman-environment' ;
1111
12+ import type { JHipsterCommandDefinition } from '../generators/index.ts' ;
1213import { createBlueprintFiles , defaultHelpers as helpers } from '../lib/testing/index.ts' ;
1314
1415import type JHipsterCommand from './jhipster-command.ts' ;
@@ -37,15 +38,6 @@ const cliBlueprintFiles = {
3738 'generators/foo/index.js' : `export const createGenerator = async env => {
3839 const BaseGenerator = await env.requireGenerator('jhipster:base');
3940 return class extends BaseGenerator {
40- constructor(args, opts, features) {
41- super(args, opts, features);
42-
43- this.option('foo-bar', {
44- description: 'Sample option',
45- type: Boolean,
46- });
47- }
48-
4941 get [BaseGenerator.INITIALIZING]() {
5042 /* eslint-disable no-console */
5143 console.log('Running foo');
@@ -57,6 +49,18 @@ const cliBlueprintFiles = {
5749 }
5850 };
5951};
52+
53+ export const command = {
54+ configs: {
55+ fooBar: {
56+ cli: {
57+ description: 'Sample option',
58+ type: Boolean,
59+ },
60+ scope: 'none',
61+ },
62+ },
63+ };
6064` ,
6165} ;
6266
@@ -76,16 +80,21 @@ const cliSharedBlueprintFiles = {
7680 'generators/bar/index.js' : `export const createGenerator = async env => {
7781 const BaseGenerator = await env.requireGenerator('jhipster:base');
7882 return class extends BaseGenerator {
79- constructor(args, options) {
80- super(args, options);
81- this.option('foo', {
82- description: 'foo description',
83- type: Boolean,
84- });
85- }
8683 get [BaseGenerator.INITIALIZING]() {}
8784 };
8885};
86+
87+ export const command = {
88+ configs: {
89+ foo: {
90+ cli: {
91+ description: 'foo description',
92+ type: Boolean,
93+ },
94+ scope: 'none',
95+ },
96+ },
97+ };
8998` ,
9099} ;
91100
@@ -170,22 +179,34 @@ describe('cli', () => {
170179 let generator : Awaited < ReturnType < typeof helpers . instantiateDummyBaseCoreGenerator > > ;
171180 let runArgs : any [ ] ;
172181 let env : FullEnvironment ;
182+ let command : JHipsterCommandDefinition ;
173183
174184 beforeEach ( async ( ) => {
185+ command = {
186+ arguments : { } ,
187+ configs : {
188+ foo : {
189+ cli : {
190+ description : 'Foo' ,
191+ type : Boolean ,
192+ } ,
193+ scope : 'none' ,
194+ } ,
195+ fooBar : {
196+ cli : {
197+ description : 'Foo bar' ,
198+ type : Boolean ,
199+ } ,
200+ scope : 'none' ,
201+ } ,
202+ } ,
203+ } ;
175204 getCommand . mockImplementation ( actualGetCommand ) ;
176205
177- generator = await helpers . instantiateDummyBaseCoreGenerator ( ) ;
178- env = generator . env ;
179- Object . assign ( generator . _options , {
180- foo : {
181- description : 'Foo' ,
182- } ,
183- 'foo-bar' : {
184- description : 'Foo bar' ,
185- } ,
186- } ) ;
187- const runSpy = esmocha . spyOn ( env , 'run' ) ;
188- runSpy . mockImplementation ( ( ...args ) => {
206+ const BaseGenerator = ( await import ( '../generators/base/index.ts' ) ) . default ;
207+ env = ( await helpers . createTestEnv ( ) ) as FullEnvironment ;
208+ generator = new ( helpers . createDummyGenerator ( BaseGenerator ) ) ( [ ] , { env } ) ;
209+ env . run = esmocha . fn < typeof env . run > ( ( ...args ) => {
189210 runArgs = args ;
190211 return Promise . resolve ( ) ;
191212 } ) ;
@@ -197,7 +218,9 @@ describe('cli', () => {
197218 if ( namespace === 'jhipster:mocked' ) {
198219 return {
199220 namespace,
200- importModule : async ( ) => ( { } ) ,
221+ importModule : async ( ) => ( {
222+ command,
223+ } ) ,
201224 resolved : __filename ,
202225 instantiateHelp : < G > ( ) => Promise . resolve ( generator as G ) ,
203226 packageNamespace : undefined ,
@@ -235,7 +258,7 @@ describe('cli', () => {
235258
236259 describe ( 'with argument' , ( ) => {
237260 beforeEach ( ( ) => {
238- generator . _arguments . push ( { name : 'name' , type : String } ) ;
261+ command . arguments ! . name = { type : String , scope : 'none' } ;
239262 argv = [ 'jhipster' , 'jhipster' , 'mocked' , 'Foo' , '--foo' , '--foo-bar' ] ;
240263 } ) ;
241264
@@ -252,7 +275,7 @@ describe('cli', () => {
252275
253276 describe ( 'with variable arguments' , ( ) => {
254277 beforeEach ( ( ) => {
255- generator . _arguments . push ( { name : 'name' , type : Array } ) ;
278+ command . arguments ! . name = { type : Array , scope : 'none' } ;
256279 argv = [ 'jhipster' , 'jhipster' , 'mocked' , 'Foo' , 'Bar' , '--foo' , '--foo-bar' ] ;
257280 } ) ;
258281
@@ -549,20 +572,23 @@ describe('cli', () => {
549572 generatorContent : `export const createGenerator = async env => {
550573 const BaseGenerator = await env.requireGenerator('jhipster:base');
551574 return class extends BaseGenerator {
552- constructor(args, opts, features) {
553- super(args, opts, features);
554-
555- this.option('foo-bar', {
556- description: 'Sample option',
557- type: Boolean,
558- });
559- }
560-
561575 get [BaseGenerator.INITIALIZING]() {
562576 return {};
563577 }
564578 };
565579 };
580+
581+ export const command = {
582+ configs: {
583+ fooBar: {
584+ cli: {
585+ description: 'Sample option',
586+ type: Boolean,
587+ },
588+ scope: 'none',
589+ },
590+ },
591+ };
566592 ` ,
567593 } ) ,
568594 )
0 commit comments