ユーザーアイコン

mizuko

約1か月前

0
0

Nest.jsのDDDでテストにSWCの導入

Jest
Nest.js
SWC

NestにてDDDを行う場合moduleが一つにまとまるが、defaultのjestだとmodule全てのトランスパイラを行うため実行速度がかなり遅くなる。

beforeAll(async () => { module = await appTestingModule(); accountRepository = module.get<AccountRepositoryInterface>(moduleConst.ACCOUNT_REPOSITORY); });

そのため、お手軽にSWCを導入して実行速度を上げた。

{ "$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" ] }
{ "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" }