Skip to content

Commit b619919

Browse files
B4nanclaude
andauthored
chore: use nodenext module resolution, update CI to Node 22 (#118)
* chore: use nodenext module resolution, update CI to Node 22 - Switch tsconfig module/moduleResolution to nodenext (fixes type resolution for @mikro-orm/core subpath exports like ./schema) - Update CI matrix to Node 22 only (MikroORM v7 requires >= 22.17.0) - Update lockfile for v7 dependencies Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: migrate from jest to vitest with swc, add Node 24 to CI - Replace jest/ts-jest with vitest + unplugin-swc - Add @swc-node/register and @swc/core - Remove @types/jest, ts-jest, ts-loader, tslint, webpack deps - Add Node 24 to CI matrix - Update test scripts to use vitest Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: fix vitest config for legacy decorators - Enable legacyDecorator + decoratorMetadata in SWC config - Set ReflectMetadataProvider explicitly (no longer default in v7) - Add reflect-metadata as vitest setup file Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: use dropDb in book test to match author test With isolate: false, both test suites share the process. The author test drops the DB via refresh({ dropDb: true }), so the book test needs to do the same to recreate it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: revert unnecessary dropDb in schema.refresh() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: use fileParallelism instead of isolate: false Each test file creates its own MikroORM instance against the same DB, so they need isolated processes (like jest's default behavior) but sequential execution to avoid conflicts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: use isolate: false instead of fileParallelism: false Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: use tmpfs for MySQL data and wait for healthcheck in CI Use tmpfs instead of named volume to ensure fresh MySQL state on every run. Add healthcheck and --wait to ensure MySQL is ready before tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: pre-create test database in MySQL docker service Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: use fileParallelism: false for sequential test execution Tests share the same database, so they need to run sequentially to avoid conflicts. Unlike the realworld example which uses mocked services, these tests use a real MySQL database. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a40f0ce commit b619919

File tree

7 files changed

+2325
-5454
lines changed

7 files changed

+2325
-5454
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
node-version: [ 20, 22 ]
17+
node-version: [ 22, 24 ]
1818
steps:
1919
- name: Checkout Source code
2020
uses: actions/checkout@v6
@@ -30,7 +30,7 @@ jobs:
3030
corepack prepare yarn@stable --activate
3131
3232
- name: Init docker
33-
run: docker compose up -d
33+
run: docker compose up -d --wait
3434

3535
- name: Install
3636
run: yarn

docker-compose.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
version: "3.4"
2-
31
services:
42
mysql:
53
container_name: mysql
64
image: mysql:9.6
7-
restart: unless-stopped
85
ports:
96
- "3307:3306"
107
environment:
118
MYSQL_ALLOW_EMPTY_PASSWORD: 1
12-
volumes:
13-
- mysql:/var/lib/mysql
14-
15-
volumes:
16-
mysql:
9+
MYSQL_DATABASE: nest-mikro-test-db
10+
tmpfs:
11+
- /var/lib/mysql
12+
healthcheck:
13+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
14+
interval: 5s
15+
timeout: 5s
16+
retries: 10

package.json

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
"prestart:prod": "rimraf dist && tsc",
1313
"start:prod": "node dist/main.js",
1414
"start:hmr": "node dist/server",
15-
"lint": "tslint -p tsconfig.json -c tslint.json",
16-
"test": "jest --runInBand",
17-
"test:watch": "jest --watch",
18-
"test:cov": "jest --coverage",
19-
"test:e2e": "jest --config ./test/jest-e2e.json",
20-
"webpack": "webpack --config webpack.config.js"
15+
"test": "vitest run",
16+
"test:watch": "vitest",
17+
"test:cov": "vitest run --coverage"
2118
},
2219
"dependencies": {
2320
"@mikro-orm/core": "^7.0.1",
@@ -36,36 +33,18 @@
3633
"devDependencies": {
3734
"@mikro-orm/cli": "^7.0.1",
3835
"@nestjs/testing": "^11.0.6",
36+
"@swc-node/register": "^1.11.1",
37+
"@swc/core": "^1.15.3",
3938
"@types/express": "^5.0.0",
40-
"@types/jest": "^30.0.0",
4139
"@types/node": "^24.0.0",
4240
"@types/supertest": "^7.0.0",
43-
"jest": "^30.0.0",
4441
"nodemon": "^3.0.3",
4542
"prettier": "^3.2.5",
4643
"rimraf": "^6.0.0",
4744
"supertest": "^7.0.0",
48-
"ts-jest": "^29.1.2",
49-
"ts-loader": "^9.5.1",
5045
"tsx": "^4.19.0",
51-
"tslint": "6.1.3",
52-
"webpack": "^5.104.1",
53-
"webpack-cli": "^6.0.0",
54-
"webpack-node-externals": "^3.0.0"
55-
},
56-
"jest": {
57-
"moduleFileExtensions": [
58-
"js",
59-
"json",
60-
"ts"
61-
],
62-
"rootDir": "src",
63-
"testRegex": ".spec.ts$",
64-
"transform": {
65-
"^.+\\.(t|j)s$": "ts-jest"
66-
},
67-
"coverageDirectory": "../coverage",
68-
"testEnvironment": "node"
46+
"unplugin-swc": "^1.5.9",
47+
"vitest": "^4.1.0"
6948
},
7049
"engines": {
7150
"node": ">= 22.17.0"

src/mikro-orm.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Logger } from '@nestjs/common';
22
import { SqlHighlighter } from '@mikro-orm/sql-highlighter';
33
import { defineConfig } from '@mikro-orm/mysql';
4+
import { ReflectMetadataProvider } from '@mikro-orm/decorators/legacy';
45
import { Author, BaseEntity, Book, BookTag, Publisher } from './entities';
56

67
const logger = new Logger('MikroORM');
@@ -10,6 +11,7 @@ export default defineConfig({
1011
dbName: 'mikro-orm-nest-ts',
1112
port: 3307,
1213
highlighter: new SqlHighlighter(),
14+
metadataProvider: ReflectMetadataProvider,
1315
debug: true,
1416
logger: logger.log.bind(logger),
1517
dynamicImportProvider: id => import(id),

tsconfig.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{
22
"compilerOptions": {
3-
"module": "commonjs",
3+
"module": "nodenext",
44
"declaration": true,
55
"noImplicitAny": false,
66
"removeComments": true,
77
"noLib": false,
88
"strict": true,
9-
"allowSyntheticDefaultImports": true,
109
"emitDecoratorMetadata": true,
1110
"experimentalDecorators": true,
12-
"target": "es6",
11+
"target": "es2022",
1312
"sourceMap": true,
14-
"outDir": "./dist",
15-
"baseUrl": "./src"
13+
"outDir": "./dist"
1614
},
1715
"include": [
1816
"src/**/*"

vitest.config.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { defineConfig } from 'vitest/config';
2+
import swc from 'unplugin-swc';
3+
4+
export default defineConfig({
5+
plugins: [
6+
swc.vite({
7+
jsc: {
8+
target: 'es2024',
9+
transform: {
10+
legacyDecorator: true,
11+
decoratorMetadata: true,
12+
},
13+
},
14+
sourceMaps: true,
15+
}),
16+
],
17+
test: {
18+
environment: 'node',
19+
include: ['src/**/*.spec.ts'],
20+
globals: true,
21+
setupFiles: ['reflect-metadata'],
22+
coverage: {
23+
reporter: ['clover', 'json', 'lcov', 'text'],
24+
include: ['src/**/*.ts'],
25+
},
26+
disableConsoleIntercept: true,
27+
clearMocks: true,
28+
fileParallelism: false,
29+
testTimeout: 60_000,
30+
},
31+
});

0 commit comments

Comments
 (0)