Skip to content

Commit ee145f7

Browse files
feat(schematics): migrate schematics tests to Vitest
- Replace jest.config.ts with vitest.config.ts - Update project.json to use @nx/vite:test executor - Update tsconfig.spec.json: module es2022, vitest/globals types - Simplify test-setup.ts (remove jest-preset-angular zone setup) - Update nx.json production namedInputs to exclude vitest.config Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7138a43 commit ee145f7

File tree

5 files changed

+60
-34
lines changed

5 files changed

+60
-34
lines changed

modules/schematics/jest.config.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

modules/schematics/project.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
"outputs": ["{options.outputFile}"]
1818
},
1919
"test": {
20-
"executor": "@nx/jest:jest",
21-
"options": {
22-
"jestConfig": "modules/schematics/jest.config.ts",
23-
"runInBand": true,
24-
"passWithNoTests": false
25-
},
20+
"executor": "@analogjs/vitest-angular:test",
2621
"outputs": ["{workspaceRoot}/coverage/modules/schematics"]
2722
},
2823
"build-package": {

modules/schematics/test-setup.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,33 @@
1-
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
1+
import {
2+
TextEncoder as NodeTextEncoder,
3+
TextDecoder as NodeTextDecoder,
4+
} from 'util';
25

3-
setupZoneTestEnv();
4-
Object.assign(global, { TextDecoder, TextEncoder });
6+
// Only assign if not already defined, using type assertion to satisfy TypeScript
7+
if (typeof globalThis.TextEncoder === 'undefined') {
8+
globalThis.TextEncoder = NodeTextEncoder as unknown as {
9+
new (): TextEncoder;
10+
prototype: TextEncoder;
11+
};
12+
}
13+
14+
if (typeof globalThis.TextDecoder === 'undefined') {
15+
globalThis.TextDecoder = NodeTextDecoder as unknown as {
16+
new (): TextDecoder;
17+
prototype: TextDecoder;
18+
};
19+
}
20+
21+
import '@angular/compiler';
22+
import '@analogjs/vitest-angular/setup-zone';
23+
24+
import {
25+
BrowserTestingModule,
26+
platformBrowserTesting,
27+
} from '@angular/platform-browser/testing';
28+
import { getTestBed } from '@angular/core/testing';
29+
30+
getTestBed().initTestEnvironment(
31+
BrowserTestingModule,
32+
platformBrowserTesting()
33+
);

modules/schematics/tsconfig.spec.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc",
5-
"module": "commonjs",
6-
"types": ["jest", "node"],
5+
"module": "es2022",
6+
"types": ["vitest/globals", "node"],
77
"target": "es2016"
88
},
99
"files": ["test-setup.ts"],
10-
"include": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts", "**/*.d.ts"]
10+
"include": ["vitest.config.ts", "**/*.spec.ts", "**/*.test.ts", "**/*.d.ts"]
1111
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference types="vitest" />
2+
import angular from '@analogjs/vite-plugin-angular';
3+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
4+
import { defineConfig } from 'vite';
5+
6+
export default defineConfig(({ mode }) => ({
7+
root: __dirname,
8+
plugins: [angular(), nxViteTsPaths()],
9+
test: {
10+
name: 'Schematics',
11+
globals: true,
12+
pool: 'forks',
13+
environment: 'jsdom',
14+
setupFiles: ['test-setup.ts'],
15+
include: ['src/**/*.spec.ts', 'migrations/**/*.spec.ts'],
16+
reporters: ['default'],
17+
coverage: {
18+
reportsDirectory: '../../coverage/modules/schematics',
19+
},
20+
},
21+
define: {
22+
'import.meta.vitest': mode !== 'production',
23+
},
24+
}));

0 commit comments

Comments
 (0)