Skip to content

Commit 5246ee4

Browse files
chore: Switched out jest for Vitest to get performance gains
1 parent 0a5fa00 commit 5246ee4

15 files changed

+1586
-2326
lines changed

.eslintrc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
"tsconfigRootDir": ".",
77
"sourceType": "module"
88
},
9-
"plugins": ["@typescript-eslint", "sonarjs", "jest", "prettier"],
9+
"plugins": ["@typescript-eslint", "sonarjs", "prettier"],
1010
"extends": [
1111
"eslint:recommended",
12+
"plugin:@typescript-eslint/recommended",
1213
"airbnb-base",
1314
"airbnb-typescript/base",
14-
"plugin:jest/recommended",
1515
"plugin:sonarjs/recommended",
1616
"plugin:@typescript-eslint/strict-type-checked",
1717
"plugin:@typescript-eslint/stylistic-type-checked",
1818
"plugin:prettier/recommended"
1919
],
2020
"ignorePatterns": ["**/node_modules/**", "dist/**", "*.graphql"],
2121
"rules": {
22-
"jest/prefer-expect-assertions": "error",
23-
"jest/no-identical-title": "error",
24-
"jest/valid-expect": "error",
22+
"@typescript-eslint/lines-between-class-members": "off",
23+
"@typescript-eslint/no-throw-literal": "off",
24+
"@typescript-eslint/restrict-template-expressions": "off",
25+
"@typescript-eslint/no-duplicate-enum-values": "off",
2526
// These rules are for reference only.
2627
//#region eslint
2728
"class-methods-use-this": "off",
@@ -68,11 +69,6 @@
6869
"error",
6970
{ "assertionStyle": "angle-bracket" }
7071
],
71-
"@typescript-eslint/lines-between-class-members": [
72-
"error",
73-
"always",
74-
{ "exceptAfterSingleLine": true }
75-
],
7672
"@typescript-eslint/naming-convention": [
7773
"error",
7874
{ "selector": "default", "format": ["strictCamelCase"] },

.github/workflows/test-action.yml

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ on: [pull_request, push]
88
jobs:
99
test:
1010
# Job display name
11-
name: Running the jest tests
11+
name: Running Vitest tests
1212

1313
# Runs on a Linux based OS
1414
runs-on: ubuntu-latest
1515

16-
# Run the job on 2 different versions of Node (12, 14)
16+
# Run the job on Node 18 and 20 which better support modern testing frameworks
1717
strategy:
1818
matrix:
19-
node-version: [12.x, 14.x]
19+
node-version: [18.x, 20.x]
2020

2121
# Steps involved for this particular task
2222
steps:
@@ -30,35 +30,36 @@ jobs:
3030
with:
3131
node-version: ${{ matrix.node-version }}
3232

33-
# Cache the node_modules
34-
- name: Cache node modules
35-
uses: actions/cache@v2
33+
# Enable Corepack for Yarn
34+
- name: Enable Corepack
35+
run: corepack enable
3636

37-
# Defining the cache env config ie the key
38-
env:
39-
cache-name: cache-node-modules
37+
# Set Yarn version
38+
- name: Set Yarn version
39+
run: yarn set version 4.2.2
4040

41-
# Caching options (https://github.com/actions/cache)
41+
# Cache the yarn dependencies
42+
- name: Cache yarn dependencies
43+
uses: actions/cache@v2
44+
env:
45+
cache-name: cache-yarn-dependencies
4246
with:
43-
# npm cache files are stored in `~/.npm` on Linux/macOS
44-
path: ~/.npm
45-
46-
# Key for caching the files initally
47-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
48-
49-
# Restore keys
47+
path: |
48+
.yarn/cache
49+
.yarn/unplugged
50+
.yarn/build-state.yml
51+
.yarn/install-state.gz
52+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
5053
restore-keys: |
51-
${{ runner.os }}-build-${{ env.cache-name }}-
52-
${{ runner.os }}-build-
53-
${{ runner.os }}-
54+
${{ runner.os }}-yarn-
5455
55-
# Installs all the project dependencies e.g. prettier, eslint etc via a custom project script
56-
- name: Install Node.js dependencies
57-
run: npm run allDependencies
56+
# Install dependencies using Yarn
57+
- name: Install dependencies
58+
run: yarn install
5859

59-
# Run the react-testing-library tests
60+
# Run the Vitest tests
6061
- name: Run all tests
6162
env:
6263
OPEN_MOVIE_DB_API_URI: ${{ secrets.OPEN_MOVIE_DB_API_URI }}
6364
OPEN_MOVIE_DB_API_KEY: ${{ secrets.OPEN_MOVIE_DB_API_KEY }}
64-
run: npm run test
65+
run: yarn test

.yarn/install-state.gz

-92.9 KB
Binary file not shown.

package.json

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"start:dev": "nest start --watch",
1616
"start:debug": "nest start --debug --watch",
1717
"start:prod": "node dist/main",
18-
"test": "jest",
19-
"test:watch": "jest --watch",
20-
"test:cov": "jest --coverage",
21-
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
22-
"test:e2e": "jest --config ./test/jest-e2e.json",
18+
"test": "vitest",
19+
"test:watch": "vitest --watch",
20+
"test:cov": "vitest --coverage",
21+
"test:debug": "vitest --inspect",
22+
"test:e2e": "vitest --config ./test/vitest-e2e.config.ts",
2323
"prepare": "husky install",
2424
"gql-to-interfaces": "cd ./src/scripts && ts-node schema-to-typings.ts"
2525
},
@@ -33,60 +33,45 @@
3333
"@nestjs/graphql": "^12.1.1",
3434
"@nestjs/mapped-types": "*",
3535
"@nestjs/platform-express": "^10.0.0",
36+
"@swc/core": "^1.7.40",
37+
"@vitest/coverage-v8": "^2.1.4",
38+
"@vitest/eslint-plugin": "^1.1.7",
3639
"axios": "^1.7.2",
3740
"date-fns": "^3.6.0",
41+
"eslint-plugin-vitest": "^0.5.4",
3842
"graphql": "^16.8.1",
3943
"joi": "^17.13.3",
4044
"reflect-metadata": "^0.1.13",
4145
"rxjs": "^7.8.1",
4246
"ts-morph": "^22.0.0",
47+
"unplugin-swc": "^1.5.1",
48+
"vitest": "^2.1.4",
4349
"zod": "^3.23.8"
4450
},
4551
"devDependencies": {
4652
"@nestjs/cli": "^10.0.0",
4753
"@nestjs/schematics": "^10.0.0",
4854
"@nestjs/testing": "^10.0.0",
4955
"@types/express": "^4.17.17",
50-
"@types/jest": "^29.5.2",
5156
"@types/node": "^20.3.1",
5257
"@types/supertest": "^2.0.12",
53-
"@typescript-eslint/eslint-plugin": "^6.0.0",
54-
"@typescript-eslint/parser": "^6.0.0",
58+
"@typescript-eslint/eslint-plugin": "^8.12.2",
59+
"@typescript-eslint/parser": "^8.12.2",
5560
"eslint": "^8.56.0",
5661
"eslint-config-airbnb-base": "^15.0.0",
5762
"eslint-config-airbnb-typescript": "^17.1.0",
5863
"eslint-config-prettier": "^9.1.0",
5964
"eslint-plugin-import": "^2.29.1",
60-
"eslint-plugin-jest": "^27.6.0",
6165
"eslint-plugin-prettier": "^5.1.2",
6266
"eslint-plugin-sonarjs": "^0.23.0",
6367
"husky": "^8.0.0",
64-
"jest": "^29.5.0",
6568
"prettier": "^3.0.0",
6669
"source-map-support": "^0.5.21",
6770
"supertest": "^6.3.3",
68-
"ts-jest": "^29.1.0",
6971
"ts-loader": "^9.4.3",
7072
"ts-node": "^10.9.1",
7173
"tsconfig-paths": "^4.2.0",
7274
"typescript": "^5.1.3"
7375
},
74-
"jest": {
75-
"moduleFileExtensions": [
76-
"js",
77-
"json",
78-
"ts"
79-
],
80-
"rootDir": "src",
81-
"testRegex": ".*\\.spec\\.ts$",
82-
"transform": {
83-
"^.+\\.(t|j)s$": "ts-jest"
84-
},
85-
"collectCoverageFrom": [
86-
"**/*.(t|j)s"
87-
],
88-
"coverageDirectory": "../coverage",
89-
"testEnvironment": "node"
90-
},
9176
"packageManager": "yarn@4.2.2"
9277
}

src/core/entertainment/entertainment.service.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpService } from '@nestjs/axios';
22
import { ConfigService } from '@nestjs/config';
33
import { Test, TestingModule } from '@nestjs/testing';
44
import { of } from 'rxjs';
5+
import { describe, it, expect, beforeEach, vi } from 'vitest';
56

67
import { EntertainmentService } from './entertainment.service';
78
import {
@@ -19,21 +20,21 @@ describe('EntertainmentService', () => {
1920
let service: EntertainmentService;
2021

2122
const mockHttpService = {
22-
get: jest.fn()
23+
get: vi.fn()
2324
};
2425

2526
const mockConfigService = {
26-
get: jest.fn()
27+
get: vi.fn()
2728
};
2829

2930
const mockUtilsService = {
30-
getFullImageUrlPath: jest.fn(),
31-
getNumberAsPercentage: jest.fn(),
32-
getGender: jest.fn()
31+
getFullImageUrlPath: vi.fn(),
32+
getNumberAsPercentage: vi.fn(),
33+
getGender: vi.fn()
3334
};
3435

3536
const mockSocialsService = {
36-
getSocials: jest.fn()
37+
getSocials: vi.fn()
3738
};
3839

3940
beforeEach(async () => {
@@ -60,7 +61,7 @@ describe('EntertainmentService', () => {
6061
}).compile();
6162

6263
service = module.get<EntertainmentService>(EntertainmentService);
63-
jest.clearAllMocks();
64+
vi.clearAllMocks();
6465
});
6566

6667
it('should be defined', () => {

src/core/socials/socials.service.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpService } from '@nestjs/axios';
22
import { ConfigService } from '@nestjs/config';
33
import { Test, TestingModule } from '@nestjs/testing';
44
import { of } from 'rxjs';
5+
import { describe, it, expect, beforeEach, vi } from 'vitest';
56

67
import { SocialsService } from './socials.service';
78
import { ENTERTAINMENT_TYPES } from '../../graphql/generated/schema';
@@ -10,11 +11,11 @@ describe('SocialsService', () => {
1011
let service: SocialsService;
1112

1213
const mockHttpService = {
13-
get: jest.fn()
14+
get: vi.fn()
1415
};
1516

1617
const mockConfigService = {
17-
get: jest.fn()
18+
get: vi.fn()
1819
};
1920

2021
beforeEach(async () => {
@@ -33,7 +34,7 @@ describe('SocialsService', () => {
3334
}).compile();
3435

3536
service = module.get<SocialsService>(SocialsService);
36-
jest.clearAllMocks();
37+
vi.clearAllMocks();
3738
});
3839

3940
it('should be defined', () => {

src/modules/discover/filtering/discover-filtering.service.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HttpService } from '@nestjs/axios';
22
import { ConfigService } from '@nestjs/config';
33
import { Test, TestingModule } from '@nestjs/testing';
4+
import { describe, it, expect, beforeEach, vi } from 'vitest';
45

56
import { DiscoverFilteringService } from './discover-filtering.service';
67
import { ENTERTAINMENT_TYPES } from '../../../graphql/generated/schema';
@@ -11,20 +12,20 @@ describe('DiscoverFilteringService', () => {
1112
let service: DiscoverFilteringService;
1213

1314
const mockHttpService = {
14-
get: jest.fn()
15+
get: vi.fn()
1516
};
1617

1718
const mockConfigService = {
18-
get: jest.fn()
19+
get: vi.fn()
1920
};
2021

2122
const mockUtilsService = {
22-
getFullImageUrlPath: jest.fn()
23+
getFullImageUrlPath: vi.fn()
2324
};
2425

2526
const mockFilteringOptionsService = {
26-
getAvailabilityOptions: jest.fn(),
27-
getReleaseTypeOptions: jest.fn()
27+
getAvailabilityOptions: vi.fn(),
28+
getReleaseTypeOptions: vi.fn()
2829
};
2930

3031
beforeEach(async () => {

0 commit comments

Comments
 (0)