Skip to content

Commit 725f7c3

Browse files
committed
refactor(@angular/build): deprecate splitting option in unit-test builder
DEPRECATED: The `splitting` option in the unit-test builder is deprecated as it is no longer needed with Vitest 5. Disabling code splitting is no longer necessary with Vitest 5, as the issue where shared-module exports were uninitialized in class-field initializers under JSDOM has been resolved.
1 parent 17dc0f4 commit 725f7c3

11 files changed

Lines changed: 19 additions & 35 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"runnerConfig": {
2323
"type": ["string", "boolean"],
24-
"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-base.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.",
24+
"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-base.config.mts` 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
},
2727
"browsers": {
@@ -80,7 +80,8 @@
8080
"splitting": {
8181
"type": "boolean",
8282
"description": "Enables code splitting for test execution. When enabled, shared code between test files is split into separate chunks. Issues with live ESM bindings in Node.js environments (such as uninitialized exports or mocking failures) can be resolved by disabling splitting. This option is only available for the Vitest runner.",
83-
"default": true
83+
"default": true,
84+
"x-deprecated": "No longer needed with Vitest 5."
8485
},
8586
"quiet": {
8687
"type": "boolean",

packages/angular/build/src/builders/unit-test/tests/behavior/vitest-shared-chunk-init_spec.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,11 @@ import {
1616

1717
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
1818
describe('Behavior: "Vitest shared chunk initialization"', () => {
19-
// Regression test for https://github.com/angular/angular-cli/issues/33728.
20-
//
21-
// Without `disableCodeSplitting`, esbuild hoists a module imported by more than one spec
22-
// entry point into a shared chunk behind a lazy `__esm` initializer, and a class-field
23-
// initializer in another chunk reads the exported value as `undefined` under the jsdom
24-
// runner. All four trigger conditions are required and encoded below:
25-
// 1. two spec entry points import the shared module (so it lands in a shared chunk);
26-
// 2. a component in one entry reads the export during class-field initialization;
27-
// 3. that component's spec file contains an `async` test callback (no `await` needed);
28-
// 4. zone.js is in the polyfills (the `setupApplicationTarget` default), which downlevels
29-
// async and makes esbuild emit the spec entry CommonJS-wrapped.
30-
//
31-
// NOTE: the failure this guards against is sensitive to inert content — adding a top-level
32-
// side effect (even a `console.log`) to the shared or importing module below defused it
33-
// during reduction. Mirror https://github.com/jonmarozick/ng-shared-chunk-repro when
34-
// modifying these fixtures.
3519
it('should provide shared-module exports to class-field initializers in async specs', async () => {
3620
setupApplicationTarget(harness);
3721

3822
harness.useTarget('test', {
3923
...BASE_OPTIONS,
40-
splitting: false,
4124
});
4225

4326
// Keep the default project's spec deterministic; a third spec entry that does not touch

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
5757

5858
it('should override isolate from the Vitest config file when set to false', async () => {
5959
harness.writeFile(
60-
'vitest-base.config.ts',
60+
'vitest-base.config.mts',
6161
`
6262
import { defineConfig } from 'vitest/config';
6363

packages/angular/build/src/builders/unit-test/tests/options/runner-config-coverage_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
2323
describe('Vitest Runner', () => {
2424
it('should preserve thresholds from Vitest config when not overridden by CLI', async () => {
2525
harness.writeFile(
26-
'vitest-base.config.ts',
26+
'vitest-base.config.mts',
2727
`
2828
import { defineConfig } from 'vitest/config';
2929
export default defineConfig({
@@ -52,7 +52,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
5252

5353
it('should override Vitest config thresholds with CLI thresholds', async () => {
5454
harness.writeFile(
55-
'vitest-base.config.ts',
55+
'vitest-base.config.mts',
5656
`
5757
import { defineConfig } from 'vitest/config';
5858
export default defineConfig({
@@ -84,7 +84,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
8484

8585
it('should merge partial CLI thresholds with Vitest config thresholds', async () => {
8686
harness.writeFile(
87-
'vitest-base.config.ts',
87+
'vitest-base.config.mts',
8888
`
8989
import { defineConfig } from 'vitest/config';
9090
export default defineConfig({

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
4444
});
4545

4646
it('should search for a config file when `true`', async () => {
47-
harness.writeFile('vitest-base.config.ts', VITEST_CONFIG_CONTENT);
47+
harness.writeFile('vitest-base.config.mts', VITEST_CONFIG_CONTENT);
4848
harness.useTarget('test', {
4949
...BASE_OPTIONS,
5050
runnerConfig: true,
@@ -57,7 +57,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
5757
});
5858

5959
it('should ignore config file when `false`', async () => {
60-
harness.writeFile('vitest-base.config.ts', VITEST_CONFIG_CONTENT);
60+
harness.writeFile('vitest-base.config.mts', VITEST_CONFIG_CONTENT);
6161
harness.useTarget('test', {
6262
...BASE_OPTIONS,
6363
runnerConfig: false,
@@ -70,7 +70,7 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
7070
});
7171

7272
it('should ignore config file by default', async () => {
73-
harness.writeFile('vitest-base.config.ts', VITEST_CONFIG_CONTENT);
73+
harness.writeFile('vitest-base.config.mts', VITEST_CONFIG_CONTENT);
7474
harness.useTarget('test', {
7575
...BASE_OPTIONS,
7676
});

packages/schematics/angular/config/files/vitest-base.config.ts.template renamed to packages/schematics/angular/config/files/vitest-base.config.mts.template

File renamed without changes.

packages/schematics/angular/config/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function addVitestConfig(options: ConfigOptions): Rule {
7272
if (testTarget.options.runner === 'karma') {
7373
context.logger.warn(
7474
`The "test" target is configured to use the "karma" runner in the main options.` +
75-
' The generated "vitest-base.config.ts" file may not be used.',
75+
' The generated "vitest-base.config.mts" file may not be used.',
7676
);
7777
}
7878

@@ -85,14 +85,14 @@ function addVitestConfig(options: ConfigOptions): Rule {
8585
) {
8686
context.logger.warn(
8787
`The "test" target's "${name}" configuration is configured to use the "karma" runner.` +
88-
' The generated "vitest-base.config.ts" file may not be used for that configuration.',
88+
' The generated "vitest-base.config.mts" file may not be used for that configuration.',
8989
);
9090
}
9191
}
9292

9393
return mergeWith(
9494
apply(url('./files'), [
95-
filter((p) => p.endsWith('vitest-base.config.ts.template')),
95+
filter((p) => p.endsWith('vitest-base.config.mts.template')),
9696
applyTemplates({}),
9797
move(project.root),
9898
]),

packages/schematics/angular/config/index_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ describe('Config Schematic', () => {
194194
applicationTree.overwrite('angular.json', JSON.stringify(angularJson));
195195
});
196196

197-
it('should create a vitest-base.config.ts file', async () => {
197+
it('should create a vitest-base.config.mts file', async () => {
198198
const tree = await runConfigSchematic(ConfigType.Vitest);
199-
expect(tree.exists('projects/foo/vitest-base.config.ts')).toBeTrue();
199+
expect(tree.exists('projects/foo/vitest-base.config.mts')).toBeTrue();
200200
});
201201

202202
it(`should set 'runnerConfig' in test builder`, async () => {

packages/schematics/angular/migrations/migrate-karma-to-vitest/karma-processor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export async function processKarmaConfig(
163163
context.logger.warn(
164164
`Project "${projectName}" uses a custom Karma configuration file "${karmaConfig}". ` +
165165
`Tests have been migrated to use Vitest, but you may need to manually migrate custom settings ` +
166-
`from this Karma config to a Vitest config (e.g. "vitest-base.config.ts") ` +
166+
`from this Karma config to a Vitest config (e.g. "vitest-base.config.mts") ` +
167167
`and set the "runnerConfig" option to true.`,
168168
);
169169
manualMigrationFiles.push(karmaConfig);

tests/e2e/tests/vitest/browser-custom-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export default async function (): Promise<void> {
1010

1111
await ng('generate', 'component', 'my-comp');
1212

13-
// Create vitest-base.config.ts
13+
// Create vitest-base.config.mts
1414
await writeFile(
15-
'vitest-base.config.ts',
15+
'vitest-base.config.mts',
1616
`
1717
import { defineConfig } from 'vitest/config';
1818
import { playwright } from '@vitest/browser-playwright';

0 commit comments

Comments
 (0)