From 922ddfdc5ceca5da0684722649c8bf94bc519a3c Mon Sep 17 00:00:00 2001 From: Shuaib Hasan Akib Date: Tue, 17 Nov 2026 00:15:46 +0600 Subject: [PATCH] fix(@angular/build): report the failing sequence sub-option in runner args errors The `runnerArgs` validation reports every invalid value for the `--sequence` option with a single message that only lists the supported sub-option names: `--sequence.seed=-1` fails with 'The Vitest "--sequence" option requires only the following options: "--sequence.shuffle", "--sequence.seed".' although the user already used one of those options, and nothing states the actual value requirement. Report each failing sub-option individually, matching the phrasing used for top-level options: an unknown name such as `--sequence.concurrent` is reported as not supported alongside the accepted names, and an invalid value such as `--sequence.seed=-1` is reported with the sub-option's own value requirement. An invalid `--sequence.shuffle` value is not testable through the real Vitest parser, which types the option as a boolean flag and treats a provided value as a test file filter. --- .../unit-test/runners/vitest/runner-args.ts | 43 +++++++++++++++++-- .../runners/vitest/runner-args_spec.ts | 9 +++- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/packages/angular/build/src/builders/unit-test/runners/vitest/runner-args.ts b/packages/angular/build/src/builders/unit-test/runners/vitest/runner-args.ts index 306e480bb6e1..676f7959713c 100644 --- a/packages/angular/build/src/builders/unit-test/runners/vitest/runner-args.ts +++ b/packages/angular/build/src/builders/unit-test/runners/vitest/runner-args.ts @@ -49,6 +49,12 @@ interface SupportedOption { /** Indicates the option only applies to the root Vitest configuration. */ readonly rootOnly?: boolean; + + /** + * Creates error messages specific to an invalid value. When absent, or when no + * messages are returned, a generic message based on `expects` is used. + */ + readonly invalidMessages?: (value: unknown) => string[]; } const isBoolean = (value: unknown): boolean => typeof value === 'boolean'; @@ -63,6 +69,10 @@ const SUPPORTED_SEQUENCE_OPTIONS: ReadonlyMap = new Map ['seed', COUNT_OPTION], ]); +const SEQUENCE_OPTION_FLAGS = [...SUPPORTED_SEQUENCE_OPTIONS.keys()] + .map((name) => `"--sequence.${name}"`) + .join(', '); + /** * The Vitest CLI options that can be provided via the `runnerArgs` option. * The keys are the camel case option names as provided by the Vitest command line parser. @@ -86,9 +96,7 @@ const SUPPORTED_OPTIONS: ReadonlyMap = new Map `"--sequence.${name}"`) - .join(', ')}`, + expects: `only the following options: ${SEQUENCE_OPTION_FLAGS}`, isValid: (value) => typeof value === 'object' && value !== null && @@ -96,6 +104,28 @@ const SUPPORTED_OPTIONS: ReadonlyMap = new Map SUPPORTED_SEQUENCE_OPTIONS.get(name)?.isValid(nestedValue) === true, ), + invalidMessages: (value) => { + if (typeof value !== 'object' || value === null) { + return []; + } + + const messages: string[] = []; + for (const [name, nestedValue] of Object.entries(value)) { + const nestedOption = SUPPORTED_SEQUENCE_OPTIONS.get(name); + if (!nestedOption) { + messages.push( + `The Vitest "--sequence.${name}" option is not supported. ` + + `The "--sequence" option accepts only the following options: ${SEQUENCE_OPTION_FLAGS}.`, + ); + } else if (!nestedOption.isValid(nestedValue)) { + messages.push( + `The Vitest "--sequence.${name}" option requires ${nestedOption.expects}.`, + ); + } + } + + return messages; + }, }, ], [ @@ -264,7 +294,12 @@ export function parseRunnerArgs( project[name] = value; } } else { - errors.push(`The Vitest "${toFlag(name)}" option requires ${supported.expects}.`); + const messages = supported.invalidMessages?.(value); + if (messages?.length) { + errors.push(...messages); + } else { + errors.push(`The Vitest "${toFlag(name)}" option requires ${supported.expects}.`); + } } continue; diff --git a/packages/angular/build/src/builders/unit-test/runners/vitest/runner-args_spec.ts b/packages/angular/build/src/builders/unit-test/runners/vitest/runner-args_spec.ts index fe472dab8275..2193f3263f51 100644 --- a/packages/angular/build/src/builders/unit-test/runners/vitest/runner-args_spec.ts +++ b/packages/angular/build/src/builders/unit-test/runners/vitest/runner-args_spec.ts @@ -122,7 +122,14 @@ describe('parseRunnerArgs', () => { it('should reject an unsupported nested sequence option', () => { expect(() => parse('--sequence.concurrent')).toThrowError( - /The Vitest "--sequence" option requires only the following options: "--sequence.shuffle", "--sequence.seed"\./, + // eslint-disable-next-line max-len + /The Vitest "--sequence.concurrent" option is not supported\. The "--sequence" option accepts only the following options: "--sequence.shuffle", "--sequence.seed"\./, + ); + }); + + it('should reject an invalid value for a supported nested sequence option', () => { + expect(() => parse('--sequence.seed=-1')).toThrowError( + /The Vitest "--sequence.seed" option requires a non-negative integer\./, ); });