From c3116b610c2fc9ef6db750bbc219ad6253225efb Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Tue, 24 Sep 2024 09:54:14 -0300 Subject: [PATCH] base-core: fix varargs cli argument handling --- generators/base-core/generator.ts | 2 ++ generators/ci-cd/generator.spec.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/generators/base-core/generator.ts b/generators/base-core/generator.ts index 1bb66c8d4a23..4d80c30e92b3 100644 --- a/generators/base-core/generator.ts +++ b/generators/base-core/generator.ts @@ -578,6 +578,8 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`); argument = positionalArguments; positionalArguments = []; } + // Replace varargs empty array with undefined. + argument = Array.isArray(argument) && argument.length === 0 ? undefined : argument; if (argument !== undefined) { const convertedValue = !argumentDef.type || argumentDef.type === Array ? argument : argumentDef.type(argument); if (argumentDef.scope === undefined || argumentDef.scope === 'generator') { diff --git a/generators/ci-cd/generator.spec.ts b/generators/ci-cd/generator.spec.ts index eac371cd8f9f..6b35cb44b424 100644 --- a/generators/ci-cd/generator.spec.ts +++ b/generators/ci-cd/generator.spec.ts @@ -22,6 +22,7 @@ import { describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; import { shouldSupportFeatures, testBlueprintSupport } from '../../test/support/tests.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/helpers.js'; import Generator from './index.js'; const __filename = fileURLToPath(import.meta.url); @@ -35,4 +36,28 @@ describe(`generator - ${generator}`, () => { }); shouldSupportFeatures(Generator); describe('blueprint support', () => testBlueprintSupport(generator)); + + describe('questions', () => { + describe('without answers', () => { + before(async () => { + await helpers + .runJHipster('ci-cd') + .withJHipsterConfig() + .withOptions({ + // ciCd argument is a varargs, pass an empty array to check if ciCd prompt is asked + positionalArguments: [[]], + }) + .withSkipWritingPriorities(); + }); + + it('should match order', () => { + expect(runResult.askedQuestions.map(({ name }) => name)).toMatchInlineSnapshot(` +[ + "ciCd", + "ciCdIntegrations", +] +`); + }); + }); + }); });