Skip to content

Commit 4357733

Browse files
test(eslint-plugin): migrate from Jest to Vitest (#4757)
1 parent 141fecd commit 4357733

File tree

8 files changed

+45
-19
lines changed

8 files changed

+45
-19
lines changed

modules/eslint-plugin/project.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@
5757
"outputs": ["{workspaceRoot}/dist/modules/eslint-plugin"]
5858
},
5959
"test": {
60-
"executor": "@nx/jest:jest",
61-
"options": {
62-
"jestConfig": "modules/eslint-plugin/jest.config.ts",
63-
"runInBand": true,
64-
"passWithNoTests": false
65-
},
60+
"executor": "@analogjs/vitest-angular:test",
61+
"dependsOn": ["build"],
6662
"outputs": ["{workspaceRoot}/coverage/modules/eslint-plugin"]
6763
},
6864
"lint": {

modules/eslint-plugin/schematics/ng-add/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
22
import stripJsonComments from 'strip-json-comments';
33
import type { Schema } from './schema';
44

5-
export default function addNgRxESLintPlugin(schema: Schema): Rule {
5+
export default function (schema: Schema): Rule {
66
return (host: Tree, context: SchematicContext) => {
77
const eslintConfigPath = '.eslintrc.json';
88
const docs = 'https://ngrx.io/guide/eslint-plugin';

modules/eslint-plugin/spec/rules/component-store/require-super-ondestroy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import rule, {
44
messageId,
55
} from '../../../src/rules/component-store/require-super-ondestroy';
66
import { fromFixture, ruleTester } from '../../utils';
7-
import path = require('path');
7+
import * as path from 'path';
88

99
type MessageIds = ESLintUtils.InferMessageIdsTypeFromRule<typeof rule>;
1010
type Options = ESLintUtils.InferOptionsTypeFromRule<typeof rule>;

modules/eslint-plugin/spec/schematics/ng-add.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import * as path from 'path';
77

88
const schematicRunner = new SchematicTestRunner(
99
'@ngrx/eslint-plugin',
10-
path.join(__dirname, '../../schematics/collection.json')
10+
path.join(
11+
process.cwd(),
12+
'dist/modules/eslint-plugin/schematics/collection.json'
13+
)
1114
);
1215

1316
test('registers the plugin with the all config', async () => {

modules/eslint-plugin/src/rules/component-store/require-super-ondestroy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path = require('path');
1+
import * as path from 'path';
22
import { createRule } from '../../rule-creator';
33
import { TSESTree } from '@typescript-eslint/types';
44

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
1+
import * as vitest from 'vitest';
2+
import { RuleTester } from '@typescript-eslint/rule-tester';
23

3-
setupZoneTestEnv();
4-
Object.assign(global, { TextDecoder, TextEncoder });
5-
global.structuredClone = (v) => JSON.parse(JSON.stringify(v));
4+
RuleTester.afterAll = vitest.afterAll;

modules/eslint-plugin/tsconfig.spec.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc",
5-
"module": "commonjs",
6-
"moduleResolution": "nodenext",
5+
"module": "es2022",
6+
"types": ["node", "vitest", "vitest/globals"],
7+
"target": "es2016",
78
"esModuleInterop": true,
8-
"types": ["jest", "node"],
9-
"target": "ES2022",
109
"resolveJsonModule": true
1110
},
1211
"files": ["test-setup.ts"],
13-
"include": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts", "**/*.d.ts"]
12+
"include": ["**/*.spec.ts", "**/*.test.ts", "**/*.d.ts"]
1413
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference types="vitest" />
2+
3+
import angular from '@analogjs/vite-plugin-angular';
4+
5+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
6+
7+
import { defineConfig } from 'vite';
8+
9+
// https://vitejs.dev/config/
10+
export default defineConfig(({ mode }) => {
11+
return {
12+
root: __dirname,
13+
plugins: [
14+
angular(),
15+
nxViteTsPaths(),
16+
],
17+
test: {
18+
globals: true,
19+
pool: 'forks',
20+
environment: 'jsdom',
21+
setupFiles: ['test-setup.ts'],
22+
include: ['**/*.spec.ts'],
23+
reporters: ['default']
24+
},
25+
define: {
26+
'import.meta.vitest': mode !== 'production',
27+
},
28+
};
29+
});

0 commit comments

Comments
 (0)