Skip to content

Commit ed700a1

Browse files
clydindgp1130
authored andcommitted
fix(@angular/build): prioritize string type for runnerConfig schema
Reorders the `type` union in the `runnerConfig` option's schema to prioritize `string` over `boolean`. This change provides a stronger hint to the CLI's argument parser, ensuring that when a value is provided for the option (e.g., a file path), it is unambiguously treated as a string. This improves the robustness of the parsing logic for this union-type option while preserving the functionality of its boolean flag forms.
1 parent 70e67fe commit ed700a1

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

packages/angular/build/src/builders/unit-test/options.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export async function normalizeOptions(
127127
dumpVirtualFiles: options.dumpVirtualFiles,
128128
listTests: options.listTests,
129129
runnerConfig:
130-
typeof runnerConfig === 'string' ? path.resolve(workspaceRoot, runnerConfig) : runnerConfig,
130+
typeof runnerConfig === 'string'
131+
? runnerConfig.length === 0
132+
? true
133+
: path.resolve(workspaceRoot, runnerConfig)
134+
: runnerConfig,
131135
};
132136
}
133137

packages/angular/build/src/builders/unit-test/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"enum": ["karma", "vitest"]
2121
},
2222
"runnerConfig": {
23-
"type": ["boolean", "string"],
23+
"type": ["string", "boolean"],
2424
"description": "Specifies the configuration file for the selected test runner. If a string is provided, it will be used as the path to the configuration file. If `true`, the builder will search for a default configuration file (e.g., `vitest.config.ts` or `karma.conf.js`). If `false`, no external configuration file will be used.\\nFor Vitest, this enables advanced options and the use of custom plugins. Please note that while the file is loaded, the Angular team does not provide direct support for its specific contents or any third-party plugins used within it.",
2525
"default": false
2626
},
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import assert from 'node:assert/strict';
2+
import path from 'node:path';
3+
import { writeMultipleFiles } from '../../utils/fs';
4+
import { ng } from '../../utils/process';
5+
import { applyVitestBuilder } from '../../utils/vitest';
6+
7+
export default async function (): Promise<void> {
8+
await applyVitestBuilder();
9+
10+
// Create a custom Vitest configuration file.
11+
const customConfigPath = 'vitest.custom.mjs';
12+
await writeMultipleFiles({
13+
[customConfigPath]: `
14+
import { defineConfig } from 'vitest/config';
15+
export default defineConfig({
16+
test: {
17+
// A unique option to confirm this file is being used.
18+
passWithNoTests: true,
19+
},
20+
});
21+
`,
22+
});
23+
24+
const absoluteConfigPath = path.resolve(customConfigPath);
25+
const { stdout } = await ng('test', `--runner-config=${absoluteConfigPath}`);
26+
27+
// Assert that the CLI logs the use of the specified configuration file.
28+
assert.match(
29+
stdout,
30+
/vitest\.custom\.mjs/,
31+
'Expected a message confirming the use of the custom config file.',
32+
);
33+
}

0 commit comments

Comments
 (0)