Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,29 @@ function createTestBedInitVirtualFile(
import { getTestBed, ɵgetCleanupHook as getCleanupHook } from '@angular/core/testing';
import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';
${providersImport}
// Same as https://github.com/angular/angular/blob/05a03d3f975771bb59c7eefd37c01fa127ee2229/packages/core/testing/srcs/test_hooks.ts#L21-L29
beforeEach(getCleanupHook(false));
afterEach(getCleanupHook(true));
@NgModule({
providers: [${usesZoneJS ? 'provideZoneChangeDetection(), ' : ''}...providers],
})
export class TestModule {}
getTestBed().initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting(), {
errorOnUnknownElements: true,
errorOnUnknownProperties: true,
});
const ANGULAR_TESTBED_SETUP = Symbol.for('@angular/cli/testbed-setup');
if (!globalThis[ANGULAR_TESTBED_SETUP]) {
globalThis[ANGULAR_TESTBED_SETUP] = true;
// The Angular TestBed needs to be initialized before any tests are run.
// In a non-isolated environment, this setup file can be executed multiple times.
// The guard condition above ensures that the setup is only performed once.
// Same as https://github.com/angular/angular/blob/05a03d3f975771bb59c7eefd37c01fa127ee2229/packages/core/testing/srcs/test_hooks.ts#L21-L29
beforeEach(getCleanupHook(false));
afterEach(getCleanupHook(true));
@NgModule({
providers: [${usesZoneJS ? 'provideZoneChangeDetection(), ' : ''}...providers],
})
class TestModule {}
getTestBed().initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting(), {
errorOnUnknownElements: true,
errorOnUnknownProperties: true,
});
}
`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ export class VitestExecutor implements TestExecutor {
reporters,
setupFiles: testSetupFiles,
projectPlugins,
include: [...this.testFileToEntryPoint.keys()],
include: [...this.testFileToEntryPoint.keys()].filter(
// Filter internal entries
(entry) => !entry.startsWith('angular:'),
),
}),
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export function createVitestConfigPlugin(options: VitestConfigPluginOptions): Vi
setupFiles: combinedSetupFiles,
include,
globals: testConfig?.globals ?? true,
// Default to `false` to align with the Karma/Jasmine experience.
isolate: testConfig?.isolate ?? false,
...(browser ? { browser } : {}),
// If the user has not specified an environment, use a smart default.
...(!testConfig?.environment
Expand Down