Jest: Babel์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ๋•Œ Jest๊ฐ€ ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2016๋…„ 10์›” 03์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: facebook/jest

_์‹œ์ž‘ํ•˜๊ธฐ_ ๊ฐ€์ด๋“œ์— ์„ค๋ช…๋œ ๊ฒƒ์ฒ˜๋Ÿผ ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ํ”„๋กœ์ ํŠธ๋„ ์ด์ œ ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค.

์ƒ˜ํ”Œ ํ”„๋กœ์ ํŠธ( sum.js ๋ฐ sum.spec.js )๋ฅผ ๋งŒ๋“  ๋‹ค์Œ Jest๋ฅผ ์‹คํ–‰ํ•˜๋ ค๊ณ  ํ•˜๋ฉด Couldn't find preset "es2015" relative to directory "/Users/ianp/Projects" ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค. ๋˜๋Š” ์ด ์š”์ง€๋ฅผ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค: https://gist.github.com/0e44151b16718ebc83bb25efb68a9395 .

๋””๋ฒ„๊ทธ ๊ตฌ์„ฑ(์•„๋ž˜)์—์„œ usesBabelJest ๋ฅผ true๋กœ ์„ค์ •ํ•˜๊ณ  ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋‚ด ํ”„๋กœ์ ํŠธ์—์„œ Babel์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์ด ๊ธฐ๋ณธ์ด ๋˜์–ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ํ™•์‹คํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. usesBabelTest: false ๋ฅผ package.json ์ถ”๊ฐ€ํ•˜๋ ค๊ณ  ์‹œ๋„ํ–ˆ์ง€๋งŒ ์ฐจ์ด๊ฐ€ ์—†์—ˆ์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ๋˜ํ•œ preset ๊ฐ€ ๊ตฌ์„ฑ์—์„œ null๋กœ ๋ณด์ด๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋Š” ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๋ฅผ ๊ฐ์•ˆํ•  ๋•Œ ์ด์ƒํ•˜๊ฒŒ ๋ณด์ž…๋‹ˆ๋‹ค ๐Ÿค”

jest version = 16.0.0
test framework = jasmine2
config = {
  "rootDir": "/Users/ianp/Projects/0e44151b16718ebc83bb25efb68a9395",
  "name": "-Users-ianp-Projects-0e44151b16718ebc83bb25efb68a9395",
  "setupFiles": [],
  "testRunner": "/Users/ianp/Projects/0e44151b16718ebc83bb25efb68a9395/node_modules/jest-jasmine2/build/index.js",
  "scriptPreprocessor": "/Users/ianp/Projects/0e44151b16718ebc83bb25efb68a9395/node_modules/babel-jest/build/index.js",
  "usesBabelJest": true,
  "automock": false,
  "bail": false,
  "browser": false,
  "cacheDirectory": "/var/folders/5p/qfkdcjcj343gnxdn0cy8_6l40000gn/T/jest",
  "clearMocks": false,
  "coveragePathIgnorePatterns": [
    "/node_modules/"
  ],
  "coverageReporters": [
    "json",
    "text",
    "lcov",
    "clover"
  ],
  "globals": {},
  "haste": {
    "providesModuleNodeModules": []
  },
  "mocksPattern": "__mocks__",
  "moduleDirectories": [
    "node_modules"
  ],
  "moduleFileExtensions": [
    "js",
    "json",
    "jsx",
    "node"
  ],
  "moduleNameMapper": {},
  "modulePathIgnorePatterns": [],
  "noStackTrace": false,
  "notify": false,
  "preset": null,
  "preprocessorIgnorePatterns": [
    "/node_modules/"
  ],
  "resetModules": false,
  "testEnvironment": "jest-environment-jsdom",
  "testPathDirs": [
    "/Users/ianp/Projects/0e44151b16718ebc83bb25efb68a9395"
  ],
  "testPathIgnorePatterns": [
    "/node_modules/"
  ],
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.jsx?$",
  "testURL": "about:blank",
  "timers": "real",
  "useStderr": false,
  "verbose": null,
  "watch": false,
  "cache": true,
  "watchman": true,
  "testcheckOptions": {
    "times": 100,
    "maxSize": 200
  }
}

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์‚ฌ์ „ ์„ค์ •์€ ํŠธ๋ฆฌ์˜ ์–ด๋”˜๊ฐ€์—์„œ .babelrc ๊ฐ€์ ธ์™€์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฑฐ๊ธฐ์— ์žˆ๋‹ค๋ฉด Jest๋Š” ํ˜„์žฌ ์ž๋™์œผ๋กœ ๊ทธ๊ฒƒ์„ ์‚ฌ์šฉํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋ชจ๋“  3 ๋Œ“๊ธ€

์‚ฌ์ „ ์„ค์ •์€ ํŠธ๋ฆฌ์˜ ์–ด๋”˜๊ฐ€์—์„œ .babelrc ๊ฐ€์ ธ์™€์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฑฐ๊ธฐ์— ์žˆ๋‹ค๋ฉด Jest๋Š” ํ˜„์žฌ ์ž๋™์œผ๋กœ ๊ทธ๊ฒƒ์„ ์‚ฌ์šฉํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๊ณ ์น˜๋‹ค:

  • .babelrc ์ œ๊ฑฐ
  • ES2015 ์‚ฌ์ „ ์„ค์ • ์„ค์น˜

๋„! ์ƒ์œ„ ๋””๋ ‰ํ† ๋ฆฌ์— .babelrc ํŒŒ์ผ์ด ์žˆ์—ˆ๋Š”๋ฐ ์–ด๋–ป๊ฒŒ ์™”๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜–

ํžŒํŠธ๋ฅผ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰