Skip to content

Commit

Permalink
chore: replace jest by vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
7185 committed Nov 28, 2024
1 parent d9cffdc commit 9e1b886
Show file tree
Hide file tree
Showing 37 changed files with 9,784 additions and 6,777 deletions.
9 changes: 0 additions & 9 deletions action-parser/jest.config.ts

This file was deleted.

22 changes: 12 additions & 10 deletions action-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"type": "module",
"scripts": {
"build": "tsc --build",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"test:cov": "NODE_OPTIONS=--experimental-vm-modules jest --coverage",
"test": "vitest run",
"test:watch": "vitest",
"test:cov": "vitest run --coverage",
"test:debug": "vitest --inspect-brk --inspect --logHeapUsage --no-file-parallelism",
"lint": "eslint \"{src,test}/**/*.ts\"",
"format": "prettier --write \"**/*.{t,mj}s\""
},
Expand All @@ -16,18 +18,18 @@
"chevrotain": "^11.0.3"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.10.0",
"@swc/core": "^1.9.2",
"@swc/jest": "^0.2.37",
"@types/jest": "^29.5.14",
"@swc/core": "^1.9.3",
"@typescript-eslint/eslint-plugin": "^8.10.0",
"@typescript-eslint/parser": "^8.10.0",
"eslint": "^9.14.0",
"@vitest/coverage-v8": "^2.1.6",
"eslint": "^9.15.0",
"globals": "^15.12.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"prettier": "^3.4.1",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
"typescript": "^5.7.2",
"unplugin-swc": "^1.5.1",
"vitest": "^2.1.6"
}
}
4 changes: 2 additions & 2 deletions action-parser/src/action.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export class ActionParser extends CstParser {
moveCommand = this.RULE('moveCommand', () => {
this.CONSUME(Move)
this.AT_LEAST_ONE({
GATE: () => /[+-]?(\d*[.])?\d+/.test(this.LA(1).image),
GATE: () => /[+-]?([0-9]*[.])?[0-9]+/.test(this.LA(1).image),
DEF: () => this.CONSUME(Resource)
})
this.OPTION(() => this.SUBRULE(this.moveArgs))
Expand All @@ -338,7 +338,7 @@ export class ActionParser extends CstParser {
rotateCommand = this.RULE('rotateCommand', () => {
this.CONSUME(Rotate)
this.AT_LEAST_ONE({
GATE: () => /[+-]?(\d*[.])?\d+/.test(this.LA(1).image),
GATE: () => /[+-]?([0-9]*[.])?[0-9]+/.test(this.LA(1).image),
DEF: () => this.CONSUME(Resource)
})
this.OPTION(() => this.SUBRULE(this.moveArgs))
Expand Down
4 changes: 2 additions & 2 deletions action-parser/src/action.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ActionVisitor extends BaseActionVisitor {
targetName: params.shift(),
animation: params.shift()
})
if (params.some((value) => !/^\d+$/.test(value))) {
if (params.some((value) => !/^[0-9]+$/.test(value))) {
return {}
}
Object.assign(res, {
Expand Down Expand Up @@ -320,7 +320,7 @@ class ActionVisitor extends BaseActionVisitor {
const worldName = resource[0]
let [, coordA, coordB, coordC, coordD] = resource

if (/^[+-\d]/.test(worldName)) {
if (/^[0-9-+]/.test(worldName)) {
// Relative teleport
coordD = coordC
coordC = coordB
Expand Down
20 changes: 20 additions & 0 deletions action-parser/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import swc from 'unplugin-swc'
import {configDefaults, defineConfig} from 'vitest/config'

export default defineConfig({
test: {
globals: true,
root: './',
coverage: {
exclude: [
...configDefaults.coverage.exclude ?? [],
'*/*.interfaces.ts'
]
}
},
plugins: [
swc.vite({
module: {type: 'es6'}
})
]
})
14 changes: 0 additions & 14 deletions backend/jest.config.ts

This file was deleted.

53 changes: 27 additions & 26 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,71 @@
"license": "MIT",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"format": "prettier --write \"src/**/*.{m,}ts\" \"test/**/*.{m,}ts\"",
"nest": "nest",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,test}/**/*.ts\"",
"lint:fix": "eslint \"{src,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"lint:fix": "eslint \"{src,test}/**/*.{m,}ts\" --fix",
"test": "vitest run",
"test:watch": "vitest",
"test:cov": "vitest run --coverage",
"test:debug": "vitest --inspect-brk --inspect --logHeapUsage --no-file-parallelism",
"test:e2e": "vitest run --config ./test/vitest.config.mts",
"postinstall": "prisma generate --generator client"
},
"dependencies": {
"@fastify/cookie": "^9.4.0",
"@fastify/static": "^7.0.4",
"@nestjs/axios": "^3.1.2",
"@nestjs/cache-manager": "^2.3.0",
"@nestjs/common": "^10.4.7",
"@nestjs/core": "^10.4.7",
"@nestjs/common": "^10.4.11",
"@nestjs/core": "^10.4.11",
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-fastify": "^10.4.7",
"@nestjs/platform-ws": "^10.4.7",
"@nestjs/platform-fastify": "^10.4.11",
"@nestjs/platform-ws": "^10.4.11",
"@nestjs/serve-static": "^4.0.2",
"@nestjs/websockets": "^10.4.7",
"@nestjs/websockets": "^10.4.11",
"@prisma/client": "^5.22.0",
"axios": "^1.7.7",
"axios": "^1.7.8",
"cache-manager": "^5.7.6",
"class-validator": "^0.14.1",
"nestjs-pino": "^4.1.0",
"pino-http": "^10.3.0",
"pino-pretty": "^12.1.0",
"pino-pretty": "^13.0.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"ws": "^8.18.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.13.0",
"@nestjs/cli": "^10.4.7",
"@nestjs/cli": "^10.4.8",
"@nestjs/schematics": "^10.2.3",
"@nestjs/testing": "^10.4.7",
"@swc/cli": "^0.5.0",
"@swc/core": "^1.9.2",
"@types/jest": "^29.5.14",
"@types/node": "^20.17.6",
"@nestjs/testing": "^10.4.11",
"@swc/cli": "^0.5.1",
"@swc/core": "^1.9.3",
"@types/node": "^20.17.7",
"@types/supertest": "^6.0.2",
"@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "^8.10.0",
"@typescript-eslint/parser": "^8.10.0",
"eslint": "^9.14.0",
"@vitest/coverage-v8": "^2.1.6",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.12.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"prettier": "^3.4.1",
"prisma": "^5.22.0",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "^5.6.3"
"typescript": "^5.7.2",
"unplugin-swc": "^1.5.1",
"vitest": "^2.1.6"
}
}
7 changes: 4 additions & 3 deletions backend/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {vi} from 'vitest'
import {Test, TestingModule} from '@nestjs/testing'
import type {FastifyReply} from 'fastify'
import {AppController} from './app.controller'
Expand All @@ -18,11 +19,11 @@ describe(AppController.name, () => {
describe('unknown api route', () => {
it('should return a 404 status code', () => {
const statusResponseMock = {
send: jest.fn((x) => x)
send: vi.fn((x) => x)
}
const responseMock = {
status: jest.fn().mockReturnValue(statusResponseMock),
send: jest.fn((x) => x)
status: vi.fn().mockReturnValue(statusResponseMock),
send: vi.fn((x) => x)
} as unknown as FastifyReply
appController.notImplemented(responseMock)
expect(responseMock.status).toHaveBeenCalledWith(404)
Expand Down
8 changes: 4 additions & 4 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import {config} from './app.config'
userAgent: req.headers['user-agent']
}),
customLogLevel: function (_req, res, err) {
if (res.statusCode >= 400 && res.statusCode < 500) {
return 'warn'
} else if (res.statusCode >= 500 || err) {
if (res.statusCode >= 500 || err) {
return 'error'
} else if (res.statusCode >= 300 && res.statusCode < 400) {
} else if (res.statusCode >= 400) {
return 'warn'
} else if (res.statusCode >= 300) {
return 'silent'
}
return 'info'
Expand Down
3 changes: 2 additions & 1 deletion backend/src/db/db.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {vi} from 'vitest'
import {Test, TestingModule} from '@nestjs/testing'
import {DbService} from './db.service'

Expand All @@ -18,7 +19,7 @@ describe('DbService', () => {

describe('onModuleInit', () => {
it('should call $connect', async () => {
const spy = jest
const spy = vi
.spyOn(DbService.prototype, '$connect')
.mockImplementation(async () => Promise.resolve())

Expand Down
3 changes: 2 additions & 1 deletion backend/src/proxy/proxy.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {vi} from 'vitest'
import {Test, TestingModule} from '@nestjs/testing'
import {HttpModule} from '@nestjs/axios'
import {CACHE_MANAGER} from '@nestjs/cache-manager'
Expand All @@ -15,7 +16,7 @@ describe('ProxyController', () => {
ProxyService,
{
provide: CACHE_MANAGER,
useFactory: jest.fn()
useFactory: vi.fn()
}
]
}).compile()
Expand Down
3 changes: 2 additions & 1 deletion backend/src/proxy/proxy.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {vi} from 'vitest'
import {Test, TestingModule} from '@nestjs/testing'
import {HttpModule} from '@nestjs/axios'
import {CACHE_MANAGER} from '@nestjs/cache-manager'
Expand All @@ -13,7 +14,7 @@ describe('ProxyService', () => {
ProxyService,
{
provide: CACHE_MANAGER,
useFactory: jest.fn()
useFactory: vi.fn()
}
]
}).compile()
Expand Down
43 changes: 22 additions & 21 deletions backend/src/user/user.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {vi} from 'vitest'
import {Test, TestingModule} from '@nestjs/testing'
import {JwtModule} from '@nestjs/jwt'
import {User} from './user'
Expand Down Expand Up @@ -42,12 +43,12 @@ describe(UserController.name, () => {
describe('authLogin', () => {
it('should return username and id', () => {
const statusResponseMock = {
send: jest.fn((x) => x)
send: vi.fn((x) => x)
}
const responseMock = {
status: jest.fn().mockReturnValue(statusResponseMock),
setCookie: jest.fn(),
send: jest.fn((x) => x)
status: vi.fn().mockReturnValue(statusResponseMock),
setCookie: vi.fn(),
send: vi.fn((x) => x)
} as unknown as FastifyReply
offlineController.authLogin(
{
Expand All @@ -67,22 +68,22 @@ describe(UserController.name, () => {
describe('authSession', () => {
it('should return 401', () => {
const statusResponseMock = {
send: jest.fn((x) => x)
send: vi.fn((x) => x)
}
const responseMock = {
status: jest.fn().mockReturnValue(statusResponseMock),
send: jest.fn((x) => x)
status: vi.fn().mockReturnValue(statusResponseMock),
send: vi.fn((x) => x)
} as unknown as FastifyReply
offlineController.authSession('cookie', responseMock)
expect(responseMock.status).toHaveBeenCalledWith(401)
})
it('should return 200', () => {
const statusResponseMock = {
send: jest.fn((x) => x)
send: vi.fn((x) => x)
}
const responseMock = {
status: jest.fn().mockReturnValue(statusResponseMock),
send: jest.fn((x) => x)
status: vi.fn().mockReturnValue(statusResponseMock),
send: vi.fn((x) => x)
} as unknown as FastifyReply
expect(controller.authSession('cookie', responseMock)).toStrictEqual({
id: 'dummy',
Expand All @@ -94,12 +95,12 @@ describe(UserController.name, () => {

describe('authLogout', () => {
const statusResponseMock = {
send: jest.fn((x) => x)
send: vi.fn((x) => x)
}
const responseMock = {
status: jest.fn().mockReturnValue(statusResponseMock),
clearCookie: jest.fn(),
send: jest.fn((x) => x)
status: vi.fn().mockReturnValue(statusResponseMock),
clearCookie: vi.fn(),
send: vi.fn((x) => x)
} as unknown as FastifyReply
it('should return empty', () => {
expect(
Expand All @@ -112,23 +113,23 @@ describe(UserController.name, () => {
describe('authRenew', () => {
it('should return 401', () => {
const statusResponseMock = {
send: jest.fn((x) => x)
send: vi.fn((x) => x)
}
const responseMock = {
status: jest.fn().mockReturnValue(statusResponseMock),
send: jest.fn((x) => x)
status: vi.fn().mockReturnValue(statusResponseMock),
send: vi.fn((x) => x)
} as unknown as FastifyReply
offlineController.authRenew('cookie', responseMock)
expect(responseMock.status).toHaveBeenCalledWith(401)
})
it('should return 200', () => {
const statusResponseMock = {
send: jest.fn((x) => x)
send: vi.fn((x) => x)
}
const responseMock = {
status: jest.fn().mockReturnValue(statusResponseMock),
setCookie: jest.fn(),
send: jest.fn((x) => x)
status: vi.fn().mockReturnValue(statusResponseMock),
setCookie: vi.fn(),
send: vi.fn((x) => x)
} as unknown as FastifyReply
expect(controller.authRenew('cookie', responseMock)).toStrictEqual({
id: 'dummy',
Expand Down
Loading

0 comments on commit 9e1b886

Please sign in to comment.