Skip to content

Commit

Permalink
base-core: fix varargs cli argument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 24, 2024
1 parent 78c8875 commit c3116b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
25 changes: 25 additions & 0 deletions generators/ci-cd/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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",
]
`);
});
});
});
});

0 comments on commit c3116b6

Please sign in to comment.