Skip to content

Commit 43c279b

Browse files
refactor(component): migrate unit tests to Vitest (#5089)
1 parent 71406e2 commit 43c279b

21 files changed

Lines changed: 171 additions & 146 deletions

modules/component/eslint.config.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ const compat = new FlatCompat({
1111

1212
export default [
1313
{
14-
ignores: ['**/dist', '**/jest.config.ts', '**/schematics-core/**/*.ts'],
14+
ignores: [
15+
'**/dist',
16+
'**/jest.config.ts',
17+
'**/schematics-core/**/*.ts',
18+
'**/vite.config.*.timestamp*',
19+
'**/vitest.config.*.timestamp*'
20+
],
1521
},
1622
...baseConfig,
1723
...compat

modules/component/jest.config.ts

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

modules/component/migrations/15_0_0-beta/index.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { waitForAsync } from '@angular/core/testing';
99

1010
describe('Component Migration 15_0_0-beta', () => {
1111
let appTree: UnitTestTree;
12-
const collectionPath = path.join(__dirname, '../migration.json');
12+
const collectionPath = path.join(
13+
process.cwd(),
14+
'dist/modules/component/migrations/migration.json'
15+
);
1316
const pkgName = 'component';
1417

1518
beforeEach(() => {

modules/component/migrations/16_0_0/index.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { createPackageJson } from '@ngrx/schematics-core/testing/create-package'
88

99
describe('Component Migration 16_0_0', () => {
1010
let appTree: UnitTestTree;
11-
const collectionPath = path.join(__dirname, '../migration.json');
11+
const collectionPath = path.join(
12+
process.cwd(),
13+
'dist/modules/component/migrations/migration.json'
14+
);
1215
const pkgName = 'component';
1316

1417
beforeEach(() => {

modules/component/project.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@
2525
{
2626
"command": "pnpm exec tsc -p modules/component/tsconfig.schematics.json"
2727
},
28+
{
29+
"command": "pnpm exec rimraf node_modules/@ngrx/component"
30+
},
31+
{
32+
"command": "pnpm exec mkdirp node_modules/@ngrx/component"
33+
},
34+
{
35+
"command": "ncp dist/modules/component node_modules/@ngrx/component"
36+
},
2837
{
2938
"command": "cpy LICENSE dist/modules/component"
3039
}
3140
]
3241
},
33-
"outputs": ["{workspaceRoot}/dist/modules/component"]
42+
"outputs": [
43+
"{workspaceRoot}/dist/modules/component",
44+
"{workspaceRoot}/node_modules/@ngrx/component"
45+
]
3446
},
3547
"lint": {
3648
"executor": "@nx/eslint:lint",
@@ -43,12 +55,8 @@
4355
"outputs": ["{options.outputFile}"]
4456
},
4557
"test": {
46-
"executor": "@nx/jest:jest",
47-
"options": {
48-
"jestConfig": "modules/component/jest.config.ts",
49-
"runInBand": true,
50-
"passWithNoTests": false
51-
},
58+
"executor": "@analogjs/vitest-angular:test",
59+
"dependsOn": ["build"],
5260
"outputs": ["{workspaceRoot}/coverage/modules/component"]
5361
}
5462
}

modules/component/schematics-core/jest.config.js

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

modules/component/schematics-core/jest.config.ts

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

modules/component/schematics/ng-add/index.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { createWorkspace } from '@ngrx/schematics-core/testing';
99
describe('Component ng-add Schematic', () => {
1010
const schematicRunner = new SchematicTestRunner(
1111
'@ngrx/component',
12-
path.join(__dirname, '../collection.json')
12+
path.join(
13+
process.cwd(),
14+
'dist/modules/component/schematics/collection.json'
15+
)
1316
);
1417
const defaultOptions: SchemaOptions = {
1518
skipPackageJson: false,

modules/component/spec/core/potential-observable.spec.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ describe('fromPotentialObservable', () => {
4646

4747
testNonObservableInput([1, 2, 3], 'array');
4848

49-
it('should create observable from promise', (done) => {
50-
const promise = Promise.resolve(100);
51-
const obs$ = fromPotentialObservable(promise);
52-
53-
// promises cannot be tested with test scheduler
54-
obs$.subscribe((value) => {
55-
expect(value).toBe(100);
56-
done();
57-
});
58-
});
49+
it('should create observable from promise', () =>
50+
new Promise<void>((done) => {
51+
const promise = Promise.resolve(100);
52+
const obs$ = fromPotentialObservable(promise);
53+
54+
// promises cannot be tested with test scheduler
55+
obs$.subscribe((value) => {
56+
expect(value).toBe(100);
57+
done();
58+
});
59+
}));
5960

6061
it('should return passed observable', () => {
6162
const obs1$ = of('ngrx');

modules/component/spec/core/render-event/handlers.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest';
12
import { combineRenderEventHandlers } from '../../../src/core/render-event/handlers';
23
import {
34
CompleteRenderEvent,
@@ -11,7 +12,7 @@ describe('combineRenderEventHandlers', () => {
1112
function testRenderEvent<T>(event: RenderEvent<T>): void {
1213
describe(`when ${event.type} is emitted`, () => {
1314
it(`should call ${event.type} handler`, () => {
14-
const mockHandler = jest.fn();
15+
const mockHandler = vi.fn();
1516
const handleRenderEvent = combineRenderEventHandlers({
1617
[event.type]: mockHandler,
1718
});

0 commit comments

Comments
 (0)