์๋ ํ์ธ์, ์ ๋ ์ผ๋ฐ์ ์ผ๋ก typescript์ mocha/chai๋ฅผ ์ฒ์ ์ ํ์ต๋๋ค. ์ง ์ปดํจํฐ(Windows 10)์์ ์์ ๊ตฌ์ฑ(Windows 8)์ ๋ณต์ ํ๋ ค๊ณ ํ๋๋ฐ ์ปดํ์ผ๋ฌ์์ ๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค(์ง์ฅ์์๋ ๋ชจ๋ ์ ์๋ํจ).
C:\dev\bookapi\mocha-api-test>tsc
node_modules/@types/chai/index.d.ts(1244,15): ์ค๋ฅ TS2451: ๋ธ๋ก ๋ฒ์ ๋ณ์ 'chai'๋ฅผ ๋ค์ ์ ์ธํ ์ ์์ต๋๋ค.
test/get-books-200ok.test.ts(24,5): ์ค๋ฅ TS2451: ๋ธ๋ก ๋ฒ์ ๋ณ์ 'chai'๋ฅผ ๋ค์ ์ ์ธํ ์ ์์ต๋๋ค.
์ด๊ฒ์ ๋ด package.json์
๋๋ค.
{
"์ด๋ฆ": "๋ชจ์นด API ํ
์คํธ",
"๋ฒ์ ": "1.0.0",
"๋น๊ณต๊ฐ": ์ฌ์ค,
"์ค๋ช
": "BookAPI",
"์คํฌ๋ฆฝํธ": {
"ํ
์คํธ": "๋ชจ์นด --reporter mocha-junit-reporter -r ts-node/๋ ์ง์คํฐ ํ
์คํธ/ */ .test.ts"
},
"๋ผ์ด์ผ์ค": "ISC",
"์ข
์์ฑ": {
"@types/chai": "^3.4.35",
"@types/chai-http": "0.0.30",
"@types/chai-json-schema": "^1.4.2",
"@types/mocha": "^2.2.39",
"@์ ํ/๋
ธ๋": "^7.0.5",
"์ฐจ์ด": "^3.5.0",
"chai-http": "^3.0.0",
"chai-json-schema": "^1.4.0",
"๋ชจ์นด": "^3.2.0",
"mocha-junit-reporter": "^1.13.0",
"ts-๋
ธ๋": "^3.1.0",
"typescript": "^2.4.1"
}
}
์ด๊ฒ์ tsconfig.ts์
๋๋ค.
{
"์ปดํ์ผ๋ฌ ์ต์
": {
"๋ชจ๋": "commonjs",
"๋์": "es6",
"noImplicitAny": ๊ฑฐ์ง,
"sourceMap": ๊ฑฐ์ง,
"outDir": "./๋น๋",
"์ ํ๋ฃจํธ": [
"node_modules/@types"
],
"์ ํ": [
"๋ชจ์นด",
"๋ง๋",
"์ฐจ์ด",
"์ฐจ์ด-http",
"chai-json-์คํค๋ง"
]
},
"์ ์ธ": [
"๋
ธ๋ ๋ชจ๋",
"์ง๋ค"
]
}
๋์์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
์ด์จ๋ ๋๋ถ์ ํด๊ฒฐ์ฑ ์ ์ฐพ์์ต๋๋ค. ๋ซ์ ์ ์์ต๋๋ค.
์ด ์ค๋ฅ์ ๋ํ ์์ ์ฌํญ์ ์๋ ค์ฃผ์๊ฒ ์ต๋๊น?
์ด ๋ฌธ์ ๊ฐ ์๋ ์ฌ๋์ด ์์ผ๋ฉด ts-node
์ฌ๋ฌ ๋ฒ ๊ฐ์ ธ์ค์ง ์๋์ง ๋ค์ ํ์ธํ์ธ์. ์ ๊ฒฝ์ฐ์๋ ๋ช
๋ น( mocha -r ts-node/register
)๊ณผ mocha.opts
( --require ts-node/register
)๋ก ๊ฐ์ ธ์์ต๋๋ค.