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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function createTestBedInitVirtualFile(
import { NgModule${usesZoneJS ? ', provideZoneChangeDetection' : ''} } from '@angular/core';
import { getTestBed, ɵgetCleanupHook as getCleanupHook } from '@angular/core/testing';
import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';
import { afterEach, beforeEach } from 'vitest';
${providersImport}

const ANGULAR_TESTBED_SETUP = Symbol.for('@angular/cli/testbed-setup');
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was not passing for the good reasons.
The result.success was false because the init env virtual file was failing.

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
expect(results.numPassedTests).toBe(1);
});

it('should allow overriding builder options via runnerConfig file', async () => {
it('should allow overriding globals to false via runnerConfig file', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
runnerConfig: 'vitest.config.ts',
Expand All @@ -111,7 +111,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
harness.writeFile(
'src/app/app.component.spec.ts',
`
import { vi, test, expect } from 'vitest';
import { expect } from 'vitest';
test('should pass', () => {
expect(true).toBe(true);
});
Expand All @@ -122,6 +122,38 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
expect(result?.success).toBeFalse();
});

it('should initialize environment even when globals are disabled in runnerConfig file', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
runnerConfig: 'vitest.config.ts',
});

harness.writeFile(
'vitest.config.ts',
`
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: false,
},
});
`,
);

harness.writeFile(
'src/app/app.component.spec.ts',
`
import { test, expect } from 'vitest';
test('should pass', () => {
expect(true).toBe(true);
});
`,
);

const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();
});

it('should fail when a DOM-dependent test is run in a node environment', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
Expand Down