Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/angular/build/src/builders/unit-test/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ export async function normalizeOptions(
dumpVirtualFiles: options.dumpVirtualFiles,
listTests: options.listTests,
runnerConfig:
typeof runnerConfig === 'string' ? path.resolve(workspaceRoot, runnerConfig) : runnerConfig,
typeof runnerConfig === 'string'
? runnerConfig.length === 0
? true
: path.resolve(workspaceRoot, runnerConfig)
: runnerConfig,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/angular/build/src/builders/unit-test/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"enum": ["karma", "vitest"]
},
"runnerConfig": {
"type": ["boolean", "string"],
"type": ["string", "boolean"],
"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.",
"default": false
},
Expand Down
33 changes: 33 additions & 0 deletions tests/legacy-cli/e2e/tests/vitest/runner-config-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from 'node:assert/strict';
import path from 'node:path';
import { writeMultipleFiles } from '../../utils/fs';
import { ng } from '../../utils/process';
import { applyVitestBuilder } from '../../utils/vitest';

export default async function (): Promise<void> {
await applyVitestBuilder();

// Create a custom Vitest configuration file.
const customConfigPath = 'vitest.custom.mjs';
await writeMultipleFiles({
[customConfigPath]: `
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
// A unique option to confirm this file is being used.
passWithNoTests: true,
},
});
`,
});

const absoluteConfigPath = path.resolve(customConfigPath);
const { stdout } = await ng('test', `--runner-config=${absoluteConfigPath}`);

// Assert that the CLI logs the use of the specified configuration file.
assert.match(
stdout,
/vitest\.custom\.mjs/,
'Expected a message confirming the use of the custom config file.',
);
}