JavaScript/TypeScript

[Jest] 절대 경로 적용법

KMSEOP 2021. 12. 18. 13:50
728x90

jest에서는 tsconfig에서 지정한 절대경로를 읽지 못함

package.json에 moduleNameMapper 추가

"jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "moduleNameMapper": {
      "^@/(.*)$": "<rootDir>/$1"
    },
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
728x90