Skip to content

Commit 0a64044

Browse files
committed
refactor(@schematics/angular): use .mts extension for generated Vitest configuration
Update the generated Vitest base configuration file extension from `.ts` to `.mts` to ensure it is treated as an ES module by default. This avoids warnings from Vite regarding ESM syntax in CommonJS files when the workspace does not define `"type": "module"`. Also updates related schematics tests, karma migration hints, and builder integration test specs to use `vitest-base.config.mts`.
1 parent 7dc6093 commit 0a64044

9 files changed

Lines changed: 18 additions & 18 deletions

File tree

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: 5 additions & 5 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
});
@@ -96,9 +96,9 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
9696

9797
it('should find and use a `vitest-base.config.js` in the workspace root', async () => {
9898
// This file should be ignored because the new logic looks for `vitest-base.config.*`.
99-
harness.writeFile('vitest.config.mts', VITEST_CONFIG_CONTENT);
99+
harness.writeFile('vitest.config.ts', VITEST_CONFIG_CONTENT);
100100
// The workspace root is the directory containing the project root in the test harness.
101-
harness.writeFile('vitest-base.config.js', VITEST_CONFIG_CONTENT);
101+
harness.writeFile('vitest-base.config.mjs', VITEST_CONFIG_CONTENT);
102102
harness.useTarget('test', {
103103
...BASE_OPTIONS,
104104
runnerConfig: true,

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';

tests/e2e/utils/vitest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function applyVitestBuilder(options?: {
4747
}
4848
});
4949

50-
await installWorkspacePackages();
50+
await installWorkspacePackages({ force: true });
5151

5252
await updateJsonFile('angular.json', (json) => {
5353
const projects = Object.values(json['projects']);

0 commit comments

Comments
 (0)