_์์ํ๊ธฐ_ ๊ฐ์ด๋์ ์ค๋ช ๋ ๊ฒ์ฒ๋ผ ๊ฐ์ฅ ๊ฐ๋จํ ํ๋ก์ ํธ๋ ์ด์ ์คํจํฉ๋๋ค.
์ํ ํ๋ก์ ํธ( 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๋ ํ์ฌ ์๋์ผ๋ก ๊ทธ๊ฒ์ ์ฌ์ฉํ ๊ฒ์
๋๋ค.
๊ณ ์น๋ค:
.babelrc
์ ๊ฑฐ๋! ์์ ๋๋ ํ ๋ฆฌ์ .babelrc
ํ์ผ์ด ์์๋๋ฐ ์ด๋ป๊ฒ ์๋์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค ๐
ํํธ๋ฅผ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ฌ์ ์ค์ ์ ํธ๋ฆฌ์ ์ด๋๊ฐ์์
.babelrc
๊ฐ์ ธ์์ผ ํฉ๋๋ค. ๊ฑฐ๊ธฐ์ ์๋ค๋ฉด Jest๋ ํ์ฌ ์๋์ผ๋ก ๊ทธ๊ฒ์ ์ฌ์ฉํ ๊ฒ์ ๋๋ค.