Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ import { NormalizedUnitTestBuilderOptions, injectTestingPolyfills } from '../../
import { findTests, getTestEntrypoints } from '../../test-discovery';
import { RunnerOptions } from '../api';

/**
* A list of Angular related packages that should be marked as external.
* This allows Vite to pre-bundle them, improving performance.
*/
const ANGULAR_PACKAGES_TO_EXTERNALIZE = [
'@angular/core',
'@angular/common',
'@angular/platform-browser',
'@angular/compiler',
'@angular/router',
'@angular/forms',
'@angular/animations',
'rxjs',
];

function createTestBedInitVirtualFile(
providersFile: string | undefined,
projectSourceRoot: string,
Expand Down Expand Up @@ -83,6 +98,11 @@ export async function getVitestBuildOptions(
});
entryPoints.set('init-testbed', 'angular:test-bed-init');

const externalDependencies = new Set(['vitest', ...ANGULAR_PACKAGES_TO_EXTERNALIZE]);
if (baseBuildOptions.externalDependencies) {
baseBuildOptions.externalDependencies.forEach((dep) => externalDependencies.add(dep));
}

const buildOptions: Partial<ApplicationBuilderInternalOptions> = {
...baseBuildOptions,
watch,
Expand All @@ -101,7 +121,7 @@ export async function getVitestBuildOptions(
outputHashing: adjustOutputHashing(baseBuildOptions.outputHashing),
optimization: false,
entryPoints,
externalDependencies: ['vitest', '@vitest/browser/context'],
externalDependencies: [...externalDependencies],
};

buildOptions.polyfills = injectTestingPolyfills(buildOptions.polyfills);
Expand Down