Nest.jsのDDDでテストにSWCの導入
Jest
Nest.js
SWC
バックエンド
知識
運用
NestにてDDDを行う場合moduleが一つにまとまるが、defaultのjestだとmodule全てのトランスパイラを行うため実行速度がかなり遅くなる。
ts
beforeAll(async () => {
module = await appTestingModule();
accountRepository = module.get<AccountRepositoryInterface>(moduleConst.ACCOUNT_REPOSITORY);
});そのため、お手軽にSWCを導入して実行速度を上げた。
rc
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"target": "es2021",
"keepClassNames": true,
"baseUrl": "./",
"paths": {
"@hoge/*": [
"./src/*"
]
}
},
"module": {
"type": "commonjs",
"strict": true
},
"sourceMaps": true,
"exclude": [
"node_modules",
"dist"
]
}json
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": "src",
"testMatch": ["**/?(*.)+(spec|test).[jt]s?(x)"],
"transform": {
"^.+\\.(t|j)s$": [
"@swc/jest",
{
"sourceMaps": true,
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"target": "es2021",
"keepClassNames": true,
"baseUrl": "./",
"paths": {
"@hoge/*": ["./src/*"]
}
},
"module": {
"type": "commonjs",
"strict": true
}
}
]
},
"collectCoverageFrom": ["**/*.(t|j)s"],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"setupFiles": ["<rootDir>/test-utils/testSetup.ts"],
"moduleNameMapper": {
"^@hoge/(.*)$": "<rootDir>/$1"
},
"workerIdleMemoryLimit": "1024MB"
}