console.log
์ถ๋ ฅ์ด ๋๋ฝ๋ ๋ฌธ์ ๊ฐ ์๋ ๊ฒฝ์ฐ Jest 24๋ฅผ ์ฌ์ฉํด ๋ณด์ญ์์ค.
๋ฌธ์ #2441์์ ๋ถ๊ธฐ
@cpojer ์ด ์ค์ (macOS)์์๋ console.log ์ถ๋ ฅ์ด ํ์๋์ง ์์ต๋๋ค.
$ node --version
v7.4.0
package.json
:
{
"dependencies": {
"@types/jest": "19.2.4",
"jest": "20.0.4",
"ts-jest": "20.0.6",
"typescript": "2.3.4"
}
}
__tests__/jestconfig.json
:
{
"rootDir": "../",
"globals": {
"__TS_CONFIG__": {}
},
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"transform": {
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "__tests__/.*test_.*\\.(ts|tsx|js)$"
__tests__/test_foo.ts
:
import {} from 'jest';
console.log('CONSOLE before test');
test('fail', () => {
console.log('CONSOLE inside test');
expect(true).toEqual(false);
console.log('CONSOLE end of test');
})
__tests__/test_bar.js
:
console.log('BAR CONSOLE before test');
test('fail', () => {
console.log('BAR CONSOLE inside test');
expect(true).toEqual(false);
console.log('BAR CONSOLE end of test');
})
$ jest -c __tests__/jestconfig.json
FAIL __tests__/test_foo.ts
โ fail
expect(received).toEqual(expected)
Expected value to equal:
false
Received:
true
at Object.<anonymous> (__tests__/test_foo.ts:6:16)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
FAIL __tests__/test_bar.js
โ fail
expect(received).toEqual(expected)
Expected value to equal:
false
Received:
true
at Object.<anonymous>.test (__tests__/test_bar.js:4:16)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
Test Suites: 2 failed, 2 total
Tests: 2 failed, 2 total
Snapshots: 0 total
Time: 1.379s
Ran all test suites.
๋จ์ผ JS ํ ์คํธ:
$ jest -c __tests__/jestconfig.json __tests__/test_bar.js
FAIL __tests__/test_bar.js
โ fail
expect(received).toEqual(expected)
Expected value to equal:
false
Received:
true
at Object.<anonymous>.test (__tests__/test_bar.js:4:16)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
โ fail (7ms)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 0.596s, estimated 1s
Ran all test suites matching "__tests__/test_bar.js".
๋จ์ผ TS ํ ์คํธ:
$ jest -c __tests__/jestconfig.json __tests__/test_foo.ts
FAIL __tests__/test_foo.ts
โ fail
expect(received).toEqual(expected)
Expected value to equal:
false
Received:
true
at Object.<anonymous> (__tests__/test_foo.ts:6:16)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
โ fail (116ms)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 1.27s
Ran all test suites matching "__tests__/test_foo.ts".
@thymikee ์ ์ด๋ฐ ์ผ์ด ์ผ์ด๋๋์ง ์์ญ๋๊น?
์ ๋ชจ๋ฅด๊ฒ ์ง๋ง ์๋ฅผ ๋ค์ด typescript๋ฅผ ์ ๊ฑฐํ์ฌ ์์ ๋ฅผ ์ต์ํํ๋ ค๊ณ ํฉ๋๋ค.
Typescript ์์ด ์ฌํํ ์ ์์ต๋๋ค.
๋
ธ๋ 7.4๊ฐ ์ฝ์ ๋ก๊ทธ๋ฅผ ๋จน๋ ๊ฒ์ ํ์ธํ ์ ์์ง๋ง ๋
ธ๋ 7.5.0, 7.10.0, 8.0.0 ๋ฐ 8.1.2์์ ์๋ํฉ๋๋ค.
๋
ธ๋ ๋ฒ์ ์ ์
๊ทธ๋ ์ด๋ํ์ญ์์ค. ํ์
@thymikee ํ์ฌ LTS ๋ฆด๋ฆฌ์ค์ธ Node 6์ ์ด๋ป์ต๋๊น? (์์ง ์ถฉ๋ถํ ๋๋ฒ๊น ํ์ง ์์์ง๋ง ์ด๊ฒ๋ ์น๋ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ๋ฌ๋ ์ง๊ธ์ LTS ๋ฆด๋ฆฌ์ค๋ก ์ ํ๋์ด ์์ผ๋ฏ๋ก ์ ๊ทธ๋ ์ด๋ํ ์ ์์ต๋๋ค.)
v6.11.0์์ ํ
์คํธํ์ง๋ง ์ฌ์ ํ console.log
๊ฐ ํ์๋ฉ๋๋ค.
์, ๋ค๋ฅธ ๋ฌธ์ ๊ฐ ์๊ฒผ์ ์๋ ์์ต๋๋ค. @thymikee ๊ฐ์ฌํฉ๋๋ค. ์ข ๋ ๋๋ฒ๊น ์ผ๋ก ๋์๊ฐ๊ฒ ์ต๋๋ค.
๋๋ ๋ชจ๋ฅด๊ฒ Node 7.3.0(n์ ํตํ ์๋ชป๋ ๋ฒ์ )์ ์คํํ๊ณ ์์๊ณ ๋ก๊น ์ด ๋์ง ์์์ต๋๋ค. 8.1.1๋ก ์ ํํ๊ณ ๋ค์ ๊ธฐ๋กํ์ต๋๋ค.
@thymikee - ๊ทธ๊ฒ์ด ์ด๋ป๊ฒ ํด๊ฒฐ์ฑ ์ธ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๊น? ...๋ ธ๋ ๋ฒ์ ์ ์ ๊ทธ๋ ์ด๋ํ ์ ์์ต๋๋ค.
๋๋ ์ด๊ฒ์ด ์ด๋ป๊ฒ ๋ ธ๋ ๋ฒ๊ทธ๋ก ๊ฐ์ฃผ๋๊ณ ์ ์ด๋ Jest ์์ฒด์ ๊ด๋ จ์ด ์๋์ง ์ฝ๊ฐ ํผ๋์ค๋ฝ๋ค๊ณ ์๊ฐํฉ๋๋ค. Jest v19.0.2์ ํจ๊ป Node v7.4.0์ ์ฌ์ฉํ๋ฉด ๋ด ํ ์คํธ์์ ์ฝ์ ๋ก๊น ์ด ํ์๋ฉ๋๋ค. ๋ค๋ฅธ ๊ตฌ์ฑ์ ๋ณ๊ฒฝํ์ง ์๊ณ Jest๋ฅผ v20.0.4๋ก ์ ๋ฐ์ดํธํ๊ธฐ๋ง ํ๋ฉด ์ฝ์ ๋ก๊น ์ด ๋ ์ด์ ํ์๋์ง ์์ต๋๋ค. ๋ด๊ฐ ๋์น๊ณ ์๋ ๊ฒ์ด ์์ต๋๊น?
@thymikee ๋ ธ๋ ๋ฒ์ ์ ์ ๊ทธ๋ ์ด๋ํ๋๋ฐ Node 8.2.1 Winx64 + Jest 20.0.4์ ์ฝ์ ๋ก๊ทธ๊ฐ ํ์๋์ง ์์ต๋๋ค. ์ง๊ธ์ ํด๋ฐฑ์ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
console.log = s => {
process.stdout.write(s + "\n");
};
์ด์ ๋ฒ์ ์๋ ์ด ๋ฌธ์ ๊ฐ ์์๊ธฐ ๋๋ฌธ์ Jest์์ ์์ ๋์ด์ผ ํ๋ค๊ณ ํ์ ํฉ๋๋ค.
@nowherenone ์ต์ ์ํ ๋ฆด๋ฆฌ์ค jest@test
์์ ๋ฐ์ํ๋์ง ํ
์คํธํ ์ ์์ต๋๊น?
@thymikee 8.2.1
๋
ธ๋์์ jest@test
๋ก ์๋ํ์ง๋ง ๊ฒฐ๊ณผ๋ ๊ฐ์ต๋๋ค. console.log
๋ฌธ์ ํญ์ ์ผ์ผ์ง๋๋ค.
@thymikee ์ฝ์ ์์ฑ์ ๋งค๊ฐ๋ณ์๊ฐ ์์ ๋งค๊ฐ๋ณ์์ ์ผ์นํ์ง ์๋ BufferedConsole ๋ชจ๋์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
PR์ ์ด์์ต๋๋ค. ์๋ง๋ ๋์์ด ๋ ๊ฒ์ ๋๋ค. https://github.com/facebook/jest/pull/4157
์ฌ๊ธฐ์ ๋ฌธ์ ๋ Jest๊ฐ ๋ฉ์์ง๋ฅผ ๋ฒํผ๋งํ์ง๋ง ๊ตฌ์ ๊ธ์ต(๋๋ ๋ฌดํ ๋ฃจํ ๋ฑ)์ ์ ๋ฐํ๋ ๋ฌด์ธ๊ฐ๊ฐ ์๋ค๋ ๊ฒ์
๋๋ค. ์ถ๋ ฅ ์คํธ๋ฆผ์ ์ง์ ๋ฉ์์ง๋ฅผ ์ธ์ํ๋ ค๋ฉด --verbose
๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
์ด๊ฒ์ ํฐ๋ฌด๋์๋ ์ผ์ ๋๋ค. @cpojer (๋ด๊ฐ ๊ฐ๋ ๋ชจ๋ ๋ฌธ์ ์ PR์์)์ ์ธ๋ฐ์๋ ์๋ต์ผ๋ก ์ธํด ์ด๋ฐ๋๊ณ ์ด๋ป๊ฒ๋ ์ฐ๋ฆฌ๊ฐ ์ถฉ๋ถํ ๋๋ํ์ง ์์ ๊ฒ์ฒ๋ผ ๋ค๋ฅธ ๋ชจ๋ ์ฌ๋์๊ฒ ๋ชจ๋ ๊ฒ์ ์ ์ฉํ๋ ค๊ณ ํฉ๋๋ค.
Jest๋ฅผ ์ฌ์ฉํ์ง ๋ง์ญ์์ค. ๊ถ๊ธํ์๋ค๋ฉด ์ ๋ต๋ณ์ ๋๋ค. ์๋ก์ด ํ ์คํธ ํ๋ ์์ํฌ๋ฅผ ์ฐพ์ผ์ญ์์ค.
describe('index', () => {
it('doesnt print anything', () => {
console.log('Hellllooo');
expect(true).toBe(true);
});
});
$ yarn test -- src/__tests__/index.spec.js --verbose
yarn test v0.27.5
warning package.json: No license field
$ jest "src/__tests__/index.spec.js" "--verbose"
PASS src/__tests__/index.spec.js
Index
โ doesnt print anything (2ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.969s, estimated 2s
$ jest "--version"
v20.0.4
$ node --version
v7.4.0
Node Lmao์ ์ต์ ๋ฒ์ ์ ์ค์นํ๋ผ๋ ๋ง์ ๋ฃ๊ฒ ๋ ๊ฒ์ด๋ผ๊ณ ํ์ ํฉ๋๋ค. ๋๋ด์ ๋๋ค ๐ ๐ ๐
@nf071590 ์ ์ฌํํ ์ ์์ผ๋ฉฐ ์ ํํ ๋์ผํ Jest ๋ฐ Node ๋ฒ์ ์ผ๋ก repl.it์์ ์๋ํฉ๋๋ค. https://repl.it/KYLc/0
ํ๋ก์ ํธ ๊ด๋ฆฌ์์ ๋ํด ํธ์ธ์ฅ๋ดํ๊ธฐ ์ ์ ์ง์งํ ๋ฐ๋ฐ์ ํด๋ณด์ธ์.
๊ฑด๋ฐฐ!
์ด์ ๋ํด ์ด๋ป๊ฒ ํด์ผ ํ ์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๋๋ ๋ง ๊ทธ๋๋ก ๋น์ ์ ์์ ๋ฅผ ํ์ผ์ ๋ถ์ฌ๋ฃ๊ณ Jest๋ฅผ ์คํํ๊ณ , 1๋ถ ์ Jest์ ์ต์ ๋ง์คํฐ ๋ฒ์ ๊ณผ ํจ๊ป ๋ด Mac์์ ๊ด๊ณ ๋ ๋๋ก ์๋ํฉ๋๋ค. ๋ณด๋ค:
Windows(๋
ธ๋ 8.4, jest 21.0.0-alpha.2)๋ฅผ ์ฌ์ฉ ์ค์ด๋ฏ๋ก console.log
๋ฅผ ์ฌ์ฉํ์ง ์์ผ๋ฉด --verbose
#$0$#$ ๊ฐ _๋๋๋ก_ ์จ๊ฒจ์ง์ง๋ง ์ผ๊ด๋๊ฒ ํ์๋๋ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ๊ฒ์ผ๋ก. ๋
ธ๋ 7๊ณผ ์์ ์ ์ธ ๋๋ด์ ์ฌ์ฉํ์ฌ ๊ฒฐ๊ณผ๋ฅผ ์
๋ฐ์ดํธํ๊ฒ ๋์ด ๊ธฐ์ฉ๋๋ค.
์ฌ๊ธฐ์ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
describe('index', () => {
it('doesnt print anything', () => {
console.log('Hellllooo');
expect(true).toBe(true);
});
});
$ node --version
v7.4.0
$ jest "--version"
v21.1.0
ํ์ฌ ๋ ธ๋ v8.7.0(npm v5.4.2)์์ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
์ด๊ฒ์ ์ฌ์ ํ โโโโ๋ฌธ์ ์ ๋๋ค
์ฌ์์ฐ์ ์ ๊ณตํ ์ ์์ต๋๊น?
FWIW, ๋๋ ๋๊ฐ์ ๋ฌธ์ ๊ฐ ์์๊ธฐ ๋๋ฌธ์ ์ฌ๊ธฐ์์ ๋๋ฌ์ต๋๋ค. ๋
ธ๋ v7.4.0. ๋ด ๋
ธ๋ ๋ฒ์ ์ ์
๊ทธ๋ ์ด๋ํ๊ณ $# --verbose
์์ด๋ ์ด์ ์์๋๋ก console.log
๊ฐ ์ธ์๋ฉ๋๋ค. V7.4.0์๋ง ์ด ๋ฌธ์ ๊ฐ ์๋ ๊ฒ์ ์๋์ง๋ง ๋ฒ์ ๊ณผ ๊ด๋ จ๋ ๊ฒ์ผ๋ก ๋ณด์ด๋ฉฐ ์ผ๋ถ Node ๋ฒ์ ์์๋ ๋ฌธ์ ๊ฐ ๋์ง ์์ต๋๋ค. ์ ๋ ์ด์ Node v8.3.0์ ์ฌ์ฉ ์ค์
๋๋ค. ์๋ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ฆ, ์ ๊ทธ๋ ์ด๋ํ๊ธฐ ์ ์ @nf071590 ๊ณผ ๋์ผํ ๋ฒ์ ๊ณผ ๋์ผํ ๋ฌธ์ ๊ฐ ์์์ต๋๋ค. repl.it์์๋ ์ ์ด๋ฐ ์ผ์ด ๋ฐ์ํ์ง ์๋์ง ์ ๋ชจ๋ฅด๊ฒ ์ง๋ง ๊ทธ์ ์ปดํจํฐ์์๋ง ์ผ์ด๋๋ ์ด์ํ ์ผ์ ์๋๋๋ค.
์ด๊ฒ์ node 8.9.0๊ณผ jest 21.2.1, macOS 10.12.6(16G1036)์ผ๋ก ์ฌํ ๊ฐ๋ฅ
@SimenB ํ ์ ์์ง๋ง ์ด ๋ฌธ์ ๋ ์ฌ๊ธฐ์ ๊ธฐ์ ์ฃฝ์ ์ ๋๋ก ๋
ผ์๋ ๊ฒ ๊ฐ์ต๋๋ค. jest์ ๋ค์ค(์์) ํ๋ก์ธ์ค ํน์ฑ์ console.logs
์ ๋ฎ์ด์ฐ๊ณ ๋ณ๊ฒฝ๋์ง ์๋ ๋๊ท๋ชจ ์ฌ์์ฑ ์์ด๋ ์๋ฏธํฉ๋๋ค. ์ด ์ค๋ ๋์ ์์ --verbose
console.log
๋ฅผ ์ฌ์ฉํ ๋๋ฒ๊น
์ ํ์ฉํ์ง ์๋ ๋ฌธ์ ๋ฅผ ํผํ๋ ค๋ฉด --watch
ํ๋๊ทธ๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์์ ์์
์ ํ๋ก์ธ์ค๋ฅผ ๋ฎ์ด์ฐ๋ ๊ฒ์ ๋ฐฉ์งํ๊ณ ์ฝ์ ๋ก๊ทธ์ ํจ๊ป ์์ธํ ์ถ๋ ฅ์ ๋ณผ ์ ์์ต๋๋ค. --watch
๋ ๋งค์ฐ ๋น ๋ฅด๊ณ ๋ณ๊ฒฝ๋ ํ
์คํธ์ ์ฝ๋์ ์ฃผ์๋ฅผ ์ง์คํ๊ณ ์ ์ฅ ์ ๋ณ๊ฒฝ๋ ํ
์คํธ๋ง ์คํํ์ฌ ๋ ๋ง์ ๊ฐ์น๋ฅผ ์ถ๊ฐํฉ๋๋ค.
์ ๊ฒฝ์ฐ์๋ ์ฅํฉํ ๋ฉ์์ง์ด ์ผ๋ถ console.log
๋ฉ์์ง๋ฅผ ๋จน์ง๋ง ์ผ๋ถ๋ ๋จน์ง ์๋๋ค๋ ๊ฒ์ ์์์ต๋๋ค. ์์ธํ ์ต์
์ ์ ๊ฑฐํ๋๋ฐ ์ด๋ ์ ๋ ์๋ํ๋ ๊ฒ ๊ฐ์ต๋๋ค!
๋ฐฉ๊ธ ๋ ธ๋ ๋ฒ์ ์ v6์์ v9๋ก ์ ๊ทธ๋ ์ด๋ํ์ผ๋ฉฐ ํ ์คํธ ํ์ผ ์ค ํ๋๊ฐ ์์์ด ๋ฉ๋๋ค.
๋๋ ๋ช ์ฃผ ๋์ ๊ทธ ๋ฌธ์ ์ ์จ๋ฆํ๊ณ ์๋ค. ์ด์ ์๋ํ๊ฒ ๋์ด ๊ธฐ์ฉ๋๋ค.
๋ฌธ์ ๋ --forceExit
์ ๊ฒฐํฉ ํ ๋ --verbose
์์ ์ฌ์ ํ ์ง์๋ฉ๋๋ค. ๊ทธ ์ด์ ๋ jest๊ฐ stderr
์ ์ฐ๋ ๋์ console.log
๊ฐ stdout
$๋ก ์ถ๋ ฅ๋๊ธฐ ๋๋ฌธ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. stderr
๋ฐ --forceExit
๋ $# stdout
์ ์ฝํ
์ธ ๊ฐ ์ฌ์ ํ ์์ ์ ์์ผ๋ฉฐ ํ๋ฌ์๋์ง ์์ต๋๋ค.
console.log๊ฐ ํ์๋์ง ์๊ณ /๋๋ console.log๊ฐ ๋ฒํผ๋ง๋์ด ์ค์๊ฐ์ผ๋ก ํ์๋์ง ์๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ๋ค์ ์๋ฃจ์
( --verbose
ํ์ ์์)์ ์ฐพ์์ต๋๋ค.
๋ช
๋ น
jest .... --forceExit --setupTestFrameworkScriptFile ./src/tests/jestShim.js
jestShim.js
์ ๋ด์ฉ
const { Console } = require('console');
global.console = new Console(process.stderr, process.stderr);
๋์ผํ ๋ฌธ์ - ๊ฒฐ์ฝ console.log ์ถ๋ ฅ์ ๋ณผ ์ ์์ต๋๋ค.
Node 9.80
Jest 22.4.2
Mac OS 10.13.3
์ฌ๊ธฐ์ ์ ์๋ ํด๊ฒฐ ๋ฐฉ๋ฒ ์ค ์ด๋ ๊ฒ๋ ํจ๊ณผ๊ฐ ์์์ต๋๋ค.
ํญ์ ๊ทธ๋ ๋ฏ์ด ํ ์คํธ๋ฅผ ์ํด ํ๋ค์ดํ ์ ์๋ ๋ณต์ ๋ฌผ์ ๋ง๋์ญ์์ค. ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ง ์์์ผ๋ฏ๋ก ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
@ledbit ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค.
NPM 5.3.0
๋๋ด 22.4.3
๋๋ ์ฌ์ ํ ๋ฒ์์ด ํ์ํ ์์ ์ ์์ต๋๋ค.
--forceExit
๋ค์ ๊นจ์ง ๊ฒ ๊ฐ์ง๋ง ํด๋น ํ๋๊ทธ๋ฅผ ์ฌ์ฉํ์ง ์์ ๋ ๋ฐ์ํ์ง ์์์ต๋๋ค.
[์ต์ Jest v23.0.0, ๋
ธ๋ v8.11.2๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด ๋ถ๊ธฐ๋ react-scripts
์ฌ์ฉ]
๋ง์ง๋ง์ผ๋ก ํน์ ๋ฌธ์์ด(์: @@@
)๋ก ๊ฐ ๋ก๊ทธ์ ํ๊ทธ๋ฅผ ์ง์ ํ๊ณ ๋ค์์ ์คํํ์ฌ ํ์ํ ๋ก๊ทธ๋ฅผ ์ป์์ต๋๋ค.
yarn test --verbose | grep '@@@'
์ด๊ฒ์ ๋์ฐํ ํดํน์
๋๋ค(๋ชจ๋ ์ฝ์ ์์์ ์๊ฒ ๋์ง๋ง ์ฌ์ ํ ํ
์คํธ ์คํจ์ ์ต์ข
ํ
์คํธ ์์ฝ์ ํ์๋จ). ๊ทธ๋ฌ๋ ์ง๊ธ๊น์ง ์๋ํ ์ ์ผํ ๋ฐฉ๋ฒ์
๋๋ค. ๋๋ ์์ ์๊ฒฌ์์ ๋ค๋ฅธ ๋ชจ๋ ๊ฒ์ ์๋ํ์ต๋๋ค. ์ด ์๋ฃจ์
์๋ --verbose
arg๊ฐ ํ์ํฉ๋๋ค( react-scripts
--watch
์ ์์์ ์ผ๋ก ๊ฒฐํฉ๋จ).
์ด๊ฒ์ ์ฌ์ ํ โโโโ๋ฌธ์ ์ ๋๋ค. Node 10.1.0์์ jest v22.4.3์ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ๋ด ์ฑ์ ์ฒซ ๋ฒ์งธ console.log ๋ฌธ๋ง ํ์๋๊ณ ๋๋จธ์ง๋ ๋ชจ๋ ๋ฌด์๋ฉ๋๋ค. ๋ด ๋ก๊น ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ stdout์ผ๋ก ์คํธ๋ฆฌ๋ฐํ๋๋ก ์ค์ ํ๋ฉด ์ผ๋ถ ๋ก๊ทธ๋ฅผ ๋ณผ ์ ์์ง๋ง ์ฌ๋ฐ๋ฅธ ์์๋ก ๋ํ๋์ง ์์ต๋๋ค.
ํ ์คํธ ์คํ์๋ก์ Jest์ ์๋ฌด๋ ์ฝ๋๋ฅผ ๋๋ฒ๊ทธํ๊ณ ์์ ํ๋ ๋ฐ ๋์์ ์ฃผ๋ ๊ฒ์ ๋๋ค. ๋ก๊ทธ ์์ด๋ ๋ฌ์ฑํ ์ ์์ต๋๋ค.
@thymikee ์ด ๋ฌธ์ ๋ฅผ ๋ค์ ์ด์ด์ฃผ์ธ์
@thanpolas ๋ ์ฐ๋ฆฌ๊ฐ ์กฐ์ฌํ ์ ์๋๋ก ๋ฒ๊ทธ๋ฅผ ํ์ํ๋ ์ ์ฅ์์ ํจ๊ป ์๋ก์ด ๋ฌธ์ ๋ฅผ ์์ ๋กญ๊ฒ ์์ฑํ ์ ์์ต๋๋ค. :) ๋ํ ์ต์ ๋ฒ์ ์ธ Jest 23์ ์ฌ์ฉํ์ญ์์ค.
๋ด ๋ฌธ์ ๋ฅผ ์์ ๋์ด์. stdout์ผ๋ก ์คํธ๋ฆฌ๋ฐํ๋ ๋ก๊ฑฐ๋ฅผ ํตํด ๋ก๊น ์ด ๋ฐ์ํ์ต๋๋ค. console.log๋ก ๋ฆฌ๋๋ ์ ๋ ๋ ์คํธ๋ฆผ ์์ฑ๊ธฐ ์ฝ๋ฐฑ์ ํธ์ถํ๋ ๊ฒ์ ์์ด๋ฒ๋ ค ์คํธ๋ฆผ์ด ๋ก๊ทธ ์ ์ก์ ์ค์งํ์ต๋๋ค.
๊ทธ๋งํ ๊ฐ์น๊ฐ ์๊ธฐ ๋๋ฌธ์ ํฐ๋ฏธ๋๊ณผ iTerm2์ ์ฐจ์ด์ ์ ๋ณด์์ต๋๋ค.
jest์๊ฒ stdout ๋ฐ console์์ ๋ง๋ฒ์ ์ฌ์ฉํ์ง ์๋๋ก ์ง์ํ๋ ์ต์ ์ ๋ชจ๋ ์ฌ๋์๊ฒ ๋งค์ฐ ์ ์ตํ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
๋ค์์ ๋ด๊ฐ ์ฌํํ ์ ์์๋ ๋ฒ๊ทธ์ ํ ์์ ๋๋ค. ์ฌ๋ฌ ์์ค๊ฐ ์๋์ง ํ์คํ์ง ์์ต๋๋ค.
https://github.com/spion/jest-logging-repro
yarn install; yarn repro
์ค์ : Jest๋ ๊ฐ์ ๋ชจ๋์ ์์ผ๋ฉฐ ์์ธ ํ๋๊ทธ๊ฐ ์ผ์ ธ ์๊ณ ์ต์ ๋ ๊ฐ์ ํ ์คํธ ํ์ผ์ด ์คํ ์ค์ ๋๋ค.
์ด๋ก : ์์ ์ ์ค ํ๋์ ์ถ๋ ฅ์ด ์ฝ์ ์ปค์๋ฅผ ์๋ชป๋ ์์น๋ก ์ด๋ํ์ฌ ์๋ชป๋ ๋ด์ฉ์ ๋ฎ์ด์๋๋ค.
์ฝ์์์ ๊ด์ฐฐ:
RUNS tests2/other-tests.js
RUNS lib/example.spec.js
PASS tests2/other-tests.js
bar
โ always is true (17ms)
PASS lib/example.spec.js
foo
โ adds 5 (5ms)
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.673s
Ran all test suites.
Watch Usage: Press w to show more.
์ฝ์ ๋ก๊ทธ๋ฅผ ์ ๊ฑฐํ๋ฉด ์๊ฐ์ ์ผ๋ก "RUNS"๊ฐ ์๋ํ ๋๋ก ๋ฎ์ด์ฐ์ฌ์ง๋๋ค.
PASS lib/example.spec.js
foo
โ adds 5 (5ms)
PASS tests2/other-tests.js
bar
โ always is true (5ms)
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.597s
Ran all test suites.
Watch Usage: Press w to show more.
3๊ฐ์ ์ฝ์ ๋ก๊ทธ๋ฅผ ์ถ๊ฐํ๋ ๊ฒฝ์ฐ:
PASS lib/example.spec.js
foo
โ adds 5 (5ms)
RUNS tests2/other-tests.js
Test Suites: 1 passed, 1 of 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
console.log tests2/other-tests.js:5
JEST
PASS tests2/other-tests.jsests.js:6
bar
โ always is true (19ms)
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 totalTime: 1.788sRan all test suites.
Watch Usage: Press w to show more.
๋ ธ๋ ๋ฒ์ :
30656 % node --version
v8.11.2
@spion ์ด ๊ทธ๊ฒ์ ๋ํด ๊ฐ๊ณ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ข์ ์ฌ์ด ์ฌํ.
์ด๊ฒ์ด Node v8.11.1 LTS์์ ๋ฐ์ํ๊ณ watch
๋ฐ watchAll
๋ชจ๋์์๋ง ๋ฐ์ํจ์ ํ์ธํ ์ ์์ต๋๋ค. ์๊ณ ๋ชจ๋๊ฐ ์์ด๋ ๊ด์ฐฎ์ต๋๋ค.
Node v10.6.0 ๋ฐ Jest 23.4.1๊ณผ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
์ ๋๋. -w 1
์ด @spion ์ ๊ฐ์ค์ ๋ง๋ ๋ก๊น
์ด ๋ค์ ์๋ํ๋ ๊ฒ์ ๋ฐ๊ฒฌํ์ต๋๋ค.
๋
ธ๋ 8.11.3
๋๋ด 23.4.0
ํ์ผ ์ ๊ท์ ์ผ์น๋ฅผ ์ผค ๋( watch
p
๋๋ฆ) ์ด ๋ฌธ์ ๋๋ ์ต์ํ ์ ์ฌํ ๋ฌธ์ ๋ฅผ ๋ฐ๊ฒฌํ์ต๋๋ค. all
๋ฅผ ์ผ๋ฉด ๋ก๊ทธ๊ฐ ์์๋๋ก ์ธ์๋ฉ๋๋ค. ์ฐธ๊ณ --verbose
๋ ์ฌ๊ธฐ์ ์์ต๋๋ค.
it.only(`should display a ErrorMessage component if state.validated is 'error'`, () => {
const fV = shallow(<FormValidator/>);
console.log('r1');
console.error('r2');
console.error('r3');
...
all
์์ฒญ ์( log
๋ฐ error
๋ชจ๋ ์ธ์:
PASS src/components/__tests__/FormValidator.js
โ Console
console.log src/components/__tests__/FormValidator.js:56
r1
console.error src/components/__tests__/FormValidator.js:57
r2
console.error src/components/__tests__/FormValidator.js:58
r3
file regex
๋ชจ๋์์( error
๊ฐ ์๋ ์ฒซ ๋ฒ์งธ log
๋ง ์ธ์):
Test Suites: 0 of 1 total
Tests: 0 total
Snapshots: 0 total
console.log src/components/__tests__/FormValidator.js:56
r1
PASS src/components/__tests__/FormValidator.jsidator.js:57
FormValidator
โ skipped 3 tests
FormValidator.displayMessage
โ should display a ErrorMessage component if state.validated is 'error' (32ms)
โ skipped 5 tests
FormValidator.render
โ skipped 1 test
it.only(`should display a ErrorMessage component if state.validated is 'error'`, () => {
const fV = shallow(<FormValidator/>);
console.log('r1');
console.error('r3');
...
all
(์์๋๋ก log
๋ฐ error
๋ชจ๋ ์ธ์):
PASS src/components/__tests__/FormValidator.js
โ Console
console.log src/components/__tests__/FormValidator.js:56
r1
console.error src/components/__tests__/FormValidator.js:59
r3
watch
(์์ ์ฝ๋๋ก ์๋ฌด ๊ฒ๋ ์ธ์๋์ง ์์):
Snapshots: 0 total
PASS src/components/__tests__/FormValidator.jsator.js:56
FormValidator
โ skipped 3 tests
FormValidator.displayMessage
โ should display a ErrorMessage component if state.validated is 'error' (20ms)
โ skipped 5 tests
FormValidator.render
โ skipped 1 test
Test Suites: 1 passed, 1 total
it.only(`should display a ErrorMessage component if state.validated is 'error'`, () => {
const fV = shallow(<FormValidator/>);
console.log('r1');
console.log('r2');
console.log('r3');
console.log('r4');
...
all
(์์๋๋ log
4๊ฐ ๋ชจ๋ ์ธ์):
PASS src/components/__tests__/FormValidator.js
โ Console
console.log src/components/__tests__/FormValidator.js:56
r1
console.log src/components/__tests__/FormValidator.js:57
r2
console.log src/components/__tests__/FormValidator.js:58
r3
console.log src/components/__tests__/FormValidator.js:59
r4
watch
(์ฒ์ ๋ ๊ฐ์ log
์์ ์ฝ๋๋ก ์ธ์๋จ):
Snapshots: 0 total
console.log src/components/__tests__/FormValidator.js:56
r1
console.log src/components/__tests__/FormValidator.js:57
r2
PASS src/components/__tests__/FormValidator.jsator.js:58
FormValidator
โ skipped 3 tests
FormValidator.displayMessage
โ should display a ErrorMessage component if state.validated is 'error' (31ms)
โ skipped 5 tests
FormValidator.render
โ skipped 1 test
Test Suites: 1 passed, 1 total
๋ด๊ฐ ๋ฌด์์ ํ๋์ง ๋ชจ๋ฅด๊ฒ ์ง๋ง ๋๋ด์ ์ค์ ํ๋ ์์๊ฐ ์ค์ํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ผ๋ถ ๊ตฌ์ฑ์ ์๋ก ๋ฎ์ด์ธ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ํ ์คํธ์ ๋ก๊ทธ ์ถ๋ ฅ์ ๋ชจ๋ ์ป๊ณ ์์ต๋๋ค.
node -v
v8.11.2
jest -v
23.4.0
์๋๋ ๋ด package.json์ ๋๋ด ๊ตฌ์ฑ์ ๋๋ค.
```
"๋๋ด": {
"๋ณํ ๋ฌด์ ํจํด": [
"
],
"์ค์ ํ์ผ": [
"
],
"testEnvironment": "jsdom",
"์์ธํ": ์ฌ์ค,
"ํ๋ก์ ํธ": [
{
"๋์คํ๋ ์ด ์ด๋ฆ": " ๊ตฌ์ฑ ์์ ",
"์ค์ ํ์ผ": [
"
],
"๋ชจ๋ ๊ฒฝ๋ก": ["
"ํ
์คํธ ์ผ์น": ["๊ฐ์๊ธฐ ","์ค์ ํ์ผ": ["
},
{
"๋์คํ๋ ์ด ์ด๋ฆ": " ์์
",
"์ค์ ํ์ผ": [
"
],
"๋ชจ๋ ๊ฒฝ๋ก": ["
"ํ
์คํธ ์ผ์น": ["
}
]
},
Here are my dependencies
"์ข
์์ฑ": {
"babel-core": "^6.26.3",
"๋ฐ๋ฒจ ๋๋ด": "^23.4.0",
"๋ฐ๋ฒจ ๋ก๋": "^7.1.5",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"dotenv": "^6.0.0",
"์ต์คํ๋ ์ค": "^4.16.3",
"๋๋ด": "^23.4.0",
"๋ฐ์": "^16.4.1",
"react-dom": "^16.4.1",
"๋ฐ์ redux": "^5.0.7",
"๋ฐ์ ์คํฌ๋ฆฝํธ": "1.1.4",
"redux": "^4.0.0",
"์ฌ์๊ธฐ ๋ฐํ์": "^0.12.0"
},
output from just running jest
ํจ์ค ๋ฆฌ๋์ src/reducers/__tests__/comments/index.test.js
โ SAVE_COMMENT(4ms) ์ ํ์ ์์
์ ์ฒ๋ฆฌํฉ๋๋ค.
โ ์ ์ ์๋ ์ ํ์ ์์
์ ์ฒ๋ฆฌํฉ๋๋ค.
์์
์ ๋ฌ src/actions/__tests__/ index.test.js
๋๊ธ ์ ์ฅ
โ ์ฌ๋ฐ๋ฅธ ์ ํ(1ms)์ด ์์ต๋๋ค.
โ ์ฌ๋ฐ๋ฅธ ํ์ด๋ก๋(1ms)๊ฐ ์์ต๋๋ค.
๊ตฌ์ฑ ์์ ์ ๋ฌ src/components/__tests__/App/index.test.js
โ CommentList๋ฅผ ํ์ํด์ผ ํจ(5ms)
โ CommentBox๋ฅผ ํ์ํด์ผ ํจ(1ms)
๊ตฌ์ฑ ์์ ์ ๋ฌ src/components/__tests__/CommentBox/index.test.js
โ ํ
์คํธ ์์ญ์ด ์์(23ms)
โ ๋ฒํผ์ด ์์(3ms)
ํ
์คํธ ์์ญ
โ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ์ ์๋ ํ
์คํธ ์์ญ์ด ์์ต๋๋ค(9ms).
โ ์์์ด ์ ์ถ๋๋ฉด ํ
์คํธ ์์ญ์ด ๋น์์ง๋๋ค(5ms).
๊ตฌ์ฑ ์์ ์ ๋ฌ src/components/__tests__/CommentList/index.test.js
โ ์ฃผ์๋น ํ๋์ LI ์์ฑ(32ms)
ํ
์คํธ ์ค์ํธ: 5๊ฐ ํต๊ณผ, ์ด 5๊ฐ
ํ
์คํธ: 11๊ฐ ํต๊ณผ, ์ด 11๊ฐ
์ค๋
์ท: ์ด 0๊ฐ
์๊ฐ: 3.79์ด
3๊ฐ์ ํ๋ก์ ํธ์์ ๋ชจ๋ ํ
์คํธ ์ค์ํธ๋ฅผ ์คํํ์ต๋๋ค.
console.log src/components/__tests__/CommentList/index.test.js:26
0
console.log src/components/__tests__/CommentList/index.test.js:27
ํ
์คํธ
```
์ด ๋ฌธ์ ๋ ๋ค์ ์ด๋ ค์ผ ํ๊ณ ์ฝ์ ์ถ๋ ฅ๋ jest์ ์ํด ์ผ์ผ์ ธ์ผ ํฉ๋๋ค. ์ ํ๊ฒฝ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
โ ๋
ธ๋ --๋ฒ์
v8.11.3
โ npx jest --๋ฒ์
23.4.1
๋๋ ๊นจ๋ํ ์ค์ ์ผ๋ก ์๋ํ๊ณ ๋ชจ๋ ๊ฒ์ด ์ ์๋ํฉ๋๋ค.
// console.test.js
describe('jest should console output', () => {
test('should console.log output be print', () => {
console.log('console.log')
expect(1).toBe(1)
})
test('should console.error output be print', () => {
console.error('console.error')
expect(1).toBe(1)
})
test('should console.info output be print', () => {
console.info('console.info')
expect(1).toBe(1)
})
})
์ฐ์ถ:
๊ทธ๋์ ๋๋ ๋ฌธ์ ๊ฐ ๋ด ๋๋ด ๊ตฌ์ฑ๊ณผ ๊ด๋ จ์ด ์๋ค๊ณ ์๊ฐํ์ต๋๋ค.
{
"globals": {
"API_SERVER_PLACEHOLDER": "SOME_API_ADDRESS"
},
"moduleFileExtensions": [
"js",
"jsx"
],
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
"moduleNameMapper": {
"\\.(css|less|sass|scss|png)$": "<rootDir>/__mocks__/styleMock.js",
"\\.(gif|ttf|eot|svg|png)$": "<rootDir>/__mocks__/fileMock.js"
}
}
๋ด ๋ณธ๋ฅ์ verbose
๋ฅผ ํ์ธํ๋ผ๊ณ ๋งํ๊ณ ์ ๊ฑฐํ ํ์๋ ๋ชจ๋ ๊ฒ์ด ์ ์์
๋๋ค.
verbose
๊ตฌ์ฑ์ด $#$ true
$#$๋ก ์ค์ ๋ jest ๋ฒ์ 23.4.1์ ์ฝ์ ์ถ๋ ฅ์ ์ผํฌ ์ ์์ต๋๋ค.
๊ธฐ๋ณธ ์ถ๋ ฅ ์คํธ๋ฆผ์ stdout
๋ก ๋ณ๊ฒฝ ์ ์: https://github.com/noscripter/jest/pull/1
๋ ๋งํ์ด?! ์ ๊ณ์ ๊นจ์ง๋ ๊ฑธ๊น์?
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.
expect(str).toBe("not this");
๐ฌ
package.json์ verbose: true
๊ฐ ์๊ฑฐ๋ --verbose
ํ๋๊ทธ๋ก jest๋ฅผ ์คํ ์ค์ธ ๊ฒฝ์ฐ(๋๋ ๋ ๋ค?) ์ ๊ฑฐํด ๋ณด์ญ์์ค.
๋ ์ด์ ๋์์ด ๋์ง ์์ต๋๋ค.
๋๋ ์ข
์ข
์ ์ฒด ํ
์คํธ ์์ฝ์ด ์ฝ์์ ์ธ์๋๊ธฐ _์ _ ์ด ๋์์ ๋ก๊ทธ ์ถ๋ ฅ์ ๋ณผ ์ ์์ต๋๋ค. ์ถ๋ ฅ์ ํ์ํ๋ ค๋ฉด ์ฐ์์ผ๋ก console.log
๋ฅผ ์ฝ 4-5ํ ๋ฐ๋ณตํด์ผ ํ๋ฉฐ, ๊ทธ ํ์๋ ๋ง์ง๋ง ๋ก๊ทธ๋ ์ ๋ฐ์ผ๋ก ์๋ฆฝ๋๋ค(์: ํฐ ๊ฐ์ฒด๋ฅผ ์ธ์ํ ๋ ์ฒซ ๋ฒ์งธ ์ ๋ฐ๋ง ๋ง์ง๋ง ์ธ์๋ ๋ก๊ทธ์์ ๋ณผ ์ ์์).
๋ํ ์์ธกํ๊ธฐ๊ฐ ๋งค์ฐ ์ด๋ ต์ต๋๋ค. ๋๋ก๋ ํ๋ ๋๋ ๋ ๊ฐ์ console.log
๋ก ์ถฉ๋ถํ์ง๋ง ๋ค๋ฅธ ๊ฒฝ์ฐ์๋ ์ฐ์์ผ๋ก 3~5๊ฐ๋ฅผ ์
๋ ฅํด์ผ ํฉ๋๋ค. ๋ด ๋ก๊ทธ๊ฐ ํ
์คํธ ์ค์ธ ์ฝ๋์ ์๋์ง ์๋๋ฉด ํ
์คํธ ์ผ์ด์ค ์์ฒด์ ์๋์ง๋ ์ค์ํ์ง ์์ต๋๋ค.
jest๊ฐ ๋ก๊ทธ๋ฅผ ์ธ์ํ ๋ค์ ์ค์ ๋ก ํด๋น ๋ก๊ทธ๋ฅผ ์ ์งํด์ผ ํ ๋ ์ ์ฒด ํ ์คํธ ์์ฝ์ ์ธ์ํ๊ธฐ ์ ์ ์ถ๋ ฅ์ ์ง์ฐ๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ด ์์ ์์ ์ฝ์์์ ๋ก๊ทธ๋ฅผ ๋ณด๋ ค๋ฉด ๋ก๊ทธ๋ฅผ ์ฌ๋ฌ ๋ฒ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ์ด์ผ ํ๋ค๋ ์ ์ ์ธ์ ํ์ต๋๋ค.
console.log
๋ ํน์ ํ
์คํธ ํ์ผ๋ง ์คํํ๋ฉด ์๋ํฉ๋๋ค.
yarn test <your-test-file-name>
์
yarn test FormValidator
์ฐธ๊ณ ๋ก ๋ค์ ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ์ฌํ์ ์คํํฉ๋๋ค.
script -qfc 'yarn repro' /dev/null > raw.log
zsh - bash์์ script -qfce
๋ฅผ ์ํ ์ ์์ต๋๋ค.
๊ทธ๋ฐ ๋ค์ cat -vet raw.log
๋ก๊ทธ๋ฅผ ๋ณด์์ต๋๋ค. ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
^[[2K^[[1G^[[1myarn run v1.7.0^[[22m^M$
^[[2K^[[1G^[[2m$ jest --watch^[[22m^M$
^[[2J^[[3J^[[H^[[1m^[[2mDetermining test suites to run...^[[1m^[[22m^[[999D^[[K^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^[[0m^[[7m^[[1m^[[32m PASS ^[[39m^[[22m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A foo^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A ^[[32mM-bM-^\M-^S^[[39m ^[[2madds 5 (4ms)^[[22m^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^[[999D^[[K ^[[2mconsole.log^[[22m ^[[2mtests2/other-tests.js:5^[[22m^M$
JEST^M$
^M$
^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^[[0m^[[7m^[[1m^[[32m PASS ^[[39m^[[22m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A bar^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A ^[[32mM-bM-^\M-^S^[[39m ^[[2malways is true (15ms)^[[22m^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^[[999D^[[K^[[1mTest Suites: ^[[22m^[[1m^[[32m2 passed^[[39m^[[22m, 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m2 passed^[[39m^[[22m, 2 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1.128s^M$
^[[2mRan all test suites^[[22m^[[2m related to changed files^[[22m^[[2m.^[[22m^M$
^M$
^[[1mWatch Usage^[[22m^M$
^[[2m M-bM-^@M-: Press ^[[22ma^[[2m to run all tests.^[[22m^M$
^[[2m M-bM-^@M-: Press ^[[22mf^[[2m to run only failed tests.^[[22m^M$
^[[2m M-bM-^@M-: Press^[[22m p ^[[2mto filter by a filename regex pattern.^[[22m^M$
^[[2m M-bM-^@M-: Press^[[22m t ^[[2mto filter by a test name regex pattern.^[[22m^M$
^[[2m M-bM-^@M-: Press^[[22m q ^[[2mto quit watch mode.^[[22m^M$
^[[2m M-bM-^@M-: Press ^[[22mEnter^[[2m to trigger a test run.^[[22m^M$
๋์์ด ๋์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค. ํน์ ์ง์ ์์ ์ ์ด ์ฝ๋๊ฐ ์๋ชป ๊ณ์ฐ๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ต์ข ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
PASS lib/example.spec.js
foo
โ adds 5 (4ms)
RUNS tests2/other-tests.js
PASS tests2/other-tests.js2 total
bar
โ always is true (15ms)
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.128s
Ran all test suites related to changed files.
Watch Usage
โบ Press a to run all tests.
โบ Press f to run only failed tests.
โบ Press p to filter by a filename regex pattern.
โบ Press t to filter by a test name regex pattern.
โบ Press q to quit watch mode.
โบ Press Enter to trigger a test run.
์ฝ์ ๋ผ์ธ์ด ๋๋ฝ๋์๊ณ ํจ์ค๊ฐ ๋๋ฌด ์๋์ ๋ ์ค๋ก ์์ฑ๋์์ต๋๋ค. ์๋ง๋ "PASS"๋ฅผ ํ์ํ๊ธฐ ์ํด ์ฌ๋ผ๊ฐ ๋ ๊ณ ๋ ค๋์ง ์์ console.log์์ ์ฝํ ๋๋ฌธ์ผ ๊ฒ์ ๋๋ค.
ํธ์ง: ์ฌ์ด ๊ฒ์ ๋ฐ ์กฐ์์ ์ํด ์ด ์์ฝ์ ์์ ์ ์ถ๊ฐํ์ต๋๋ค: https://gist.github.com/spion/bbb34c5abc1230a37ad5f4f01336b8df
ps ํ์ฌ ๋ง์คํฐ๋ก ์ด๊ฒ์ ์ฌํํ๋ ค๋ฉด ์ฝ๊ฐ์ ๊ฐ์ ๊ฐ ํ์ํ ์ ์์ต๋๋ค. ๊ฐ์ ๋ชจ๋์ ๋ค์ด๊ฐ ๋ ์ ์ ๋์ "a"๋ฅผ ๋๋ฅด๊ณ ์์ผ์ญ์์ค. console.logs๋ ์ด๋ ์์ ์์ ํต์ ๋ถ๋ฅ ์ํ๊ฐ ๋๊ธฐ ์์ํฉ๋๋ค(์๊ธฐ์น ์์ ์ฅ์์ ์๊ฐ์ ๋ํ๋จ).
๋ํ ๋๋ ์์ด ๋ฒ๋ ธ์ต๋๋ค. WRT ํฐ๋ฏธ๋ ๋์์ ์ฐจ์ด๊ฐ ์๋ค๋ฉด ์ฐ๋ถํฌ ๋ฐ์ด์ค๋์ ์์ต๋๋ค.
% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
๋๋. @spion ์ ๋ด๊ฐ๋ณด๊ณ ์๋ ๊ฒ์ ๋ชป ๋ฐ์์ต๋๋ค. ๋๋ฆฐ ๋น๋๊ธฐ ์ฝ๋์ ๋ํ ํ ์คํธ๊ฐ ์์๊ธฐ ๋๋ฌธ์ ๋ฐ๊ฒฌํ์ต๋๋ค. ์ฝ์ ์ถ๋ ฅ์ ๋ณธ ๋ค์ ํ ์คํธ ๊ฒฐ๊ณผ ์์ฝ์ผ๋ก ๋ฎ์ด์๋๋ค.
๊ทธ๋งํ ๊ฐ์น๊ฐ ์๊ธฐ ๋๋ฌธ์ [email protected]
๋ก ๋๋๋ ธ๊ณ ์ด๋ ๊ฒ ํ๋ฉด [email protected]
์ ์ฝ์ ์ถ๋ ฅ ์์ ์์ฑ๋๋ ํ
์คํธ ์์ฝ ์ถ๋ ฅ๊ณผ ๊ด๋ จ๋ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๋ค.
์ ๋ฐ์ดํธ - ์ฝ๊ฐ์ ์ง์ ์ด ์๋ ์ต์ํ์ ํจ์น๋ฅผ ์ฐพ์๋ค๊ณ ์๊ฐํ์ง๋ง Jest ๊ธฐ์์ ์ํ ์์ฑ๊ธฐ ๊ฐ์ ์ํธ ์์ฉ์ ์ดํดํ๋ ๋ฐ ์๊ฐ์ด ๊ฑธ๋ ธ์ต๋๋ค.
Jest๋ ํ๋ก์ธ์ค stderr ๋ฐ stdout ์คํธ๋ฆผ์ ์ฐ๊ธฐ ๋ฐฉ๋ฒ์ ์์ฒด ์์ฑ๊ธฐ๋ก ์์ญ์ด ํจ์นํฉ๋๋ค. ํด๋น ์์ฑ์๋ ์งํ ์ค์ธ ํ ์คํธ ์, ์งํ๋ฅ ํ์์ค, ๊ฒฝ๊ณผ ์๊ฐ ๋ฑ๊ณผ ๊ฐ์ ํญ๋ชฉ์ด ํฌํจ๋ jest-cli Status.js์ ์ถ๋ ฅ์ ๊ธฐ๋กํฉ๋๋ค.
ํด๋น ์คํธ๋ฆผ์ ์ฐ๊ธฐ ๋ช ๋ น์ด ์์ ๋๋ง๋ค ํด๋น ๋ช ๋ น์ ์ํ์ ๋ํ "์ญ์ " ๋ช ๋ น(ANSI ์ ์ด ์ฝ๋๋ฅผ ์ฌ์ฉํ์ฌ ์์น), ์๋ ์ฐ๊ธฐ ๋ฐ "์ํ ๋ค์ ์ฐ๊ธฐ" ๋ช ๋ น์ผ๋ก ๋์ฒด๋ฉ๋๋ค. ๋ฐ๋ผ์ ์ํ๊ฐ ํญ์ ํ๋ฉด ๋งจ ์๋์ ์๋ ๋ฐ๋ฉด ํ ์คํธ๋ ํ๋ฉด ์๋ก ์คํฌ๋กค๋๋ค๋ ํ์์ ๋๋ค.
(๋ฌผ๋ก , ๊ทธ๊ฒ๋ณด๋ค ์กฐ๊ธ ๋ ๋๋ํฉ๋๋ค. ์ฐ๊ธฐ๊ฐ ๋ฒํผ๋ง๋๊ณ ๋ฒํผ๋ง๋ ๋ฐ์ดํฐ๋ ์ํ์ ํจ๊ป 100ms๋ง๋ค ํ ๋ฒ๋ง ์ค์ ๋ก ๊ธฐ๋ก๋ฉ๋๋ค.)
๊ทธ๋ฌ๋ ๋ณ๋ ฌ ํ
์คํธ ๋ฌ๋( runInBand
๋ฅผ false๋ก ์ค์ ํ๋ ๊ฐ์ ๋ชจ๋์์ ์ฌ์ฉ๋จ)๋ ๋ค๋ฅธ ์์
์๋ฅผ ์คํํฉ๋๋ค. ์ด๋ฌํ ์์
์๋ ์๋ ํ๋ก์ธ์ค์ stdio ์คํธ๋ฆผ์ "์์"ํ๋๋ก ์ค์ ๋ฉ๋๋ค. ๋ถํํ๋ ์ํ๋ฅผ ์
๋ฐ์ดํธํ๋ ํจ์น๋ ๋ฒ์ ์ ์์ํ๋ค๋ ์๋ฏธ๋ ์๋๋๋ค! ์ด๋ฌํ ์ฐ๊ธฐ๊ฐ ๋ฐ์ํ๋ฉด
ํจ์น๋ ๋ฒ์ ์ด ์ด๋ฌํ tty ์ฐ๊ธฐ๋ฅผ ์์ ํ๋๋ก ํ๋ ค๋ฉด ์์ ํ๋ก์ธ์ค ์คํธ๋ฆผ์ "์์" ๋ชจ๋์์ "ํ์ดํ" ๋ชจ๋๋ก ์ ํํด์ผ ํฉ๋๋ค. ์ด๋ฐ ์์ผ๋ก ํ๋ก์ธ์ค ์ถ๋ ฅ์ ๊ธฐ๋ณธ stdout/stderr๋ก ์ง์ ์ด๋ํ๋ ๋์ ์์ ํ๋ก์ธ์ค์์ ์คํธ๋ฆผ์ผ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค. ๋ํ ์คํธ๋ฆผ์ ์๋์ผ๋ก ํ์ดํํด์ผ ํฉ๋๋ค.
diff --git a/packages/jest-runner/src/index.js b/packages/jest-runner/src/index.js
index 2f4dd724..618a8cbf 100644
--- a/packages/jest-runner/src/index.js
+++ b/packages/jest-runner/src/index.js
@@ -97,11 +97,14 @@ class TestRunner {
// $FlowFixMe: class object is augmented with worker when instantiating.
const worker: WorkerInterface = new Worker(TEST_WORKER_PATH, {
exposedMethods: ['worker'],
- forkOptions: {stdio: 'inherit'},
+ forkOptions: {stdio: 'pipe'},
maxRetries: 3,
numWorkers: this._globalConfig.maxWorkers,
});
+ worker.getStdout().pipe(process.stdout);
+ worker.getStderr().pipe(process.stderr);
+
const mutex = throat(this._globalConfig.maxWorkers);
// Send test suites to workers continuously instead of all at once to track
์คํธ๋ฆผ์ ์๋์ผ๋ก ํ์ดํํ๋ฉด ์์ญ์ด ํจ์น ์ฐ๊ธฐ๊ฐ ๋ ธ๋์์ ํธ์ถ๋ฉ๋๋ค.
์ด๊ฒ์ ๋ง์ ํตํฉ ํ ์คํธ๋ฅผ ์ค๋จํ์ง๋ง ์ฃผ๋ก ๋๋ฝ๋ ์์์ผ๋ก ์ธํด ์ค๋จ๋์์ต๋๋ค. ํ์
diff --git a/packages/jest-worker/src/worker.js b/packages/jest-worker/src/worker.js
index 5eee64af..5e5126eb 100644
--- a/packages/jest-worker/src/worker.js
+++ b/packages/jest-worker/src/worker.js
@@ -94,6 +94,8 @@ export default class {
{
cwd: process.cwd(),
env: Object.assign({}, process.env, {
+ // $FlowFixMe: Does not know about isTTY
+ FORCE_COLOR: process.stdout.isTTY,
JEST_WORKER_ID: this._options.workerId,
}),
// Suppress --debug / --inspect flags while preserving others (like --harmony).
๊ทธ ์์น๋ฅผ ํฌ๊ฒ ๋ฎ์ถ์ง๋ง ์ฌ์ ํ ๊ฝค ๋์ต๋๋ค.
Test Suites: 51 failed, 232 passed, 283 total
Tests: 149 failed, 7 skipped, 2706 passed, 2862 total
Snapshots: 19 failed, 17 obsolete, 996 passed, 1015 total
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ๋ฐฉ๋ฒ์ด ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋ ๋ง์ ์ฐ๊ธฐ ์์ ์ด ์ด์ ์ํ ์ ๋ฐ์ดํธ๋ฅผ ์ถ๊ฐํ๊ฒ ๋๋ฏ๋ก ์ถ๋ ฅ์ด ํฌ๊ฒ ๋ณ๊ฒฝ๋ฉ๋๋ค.
ํธ์ง: ๋ํ ์์ ํ๋ก์ธ์ค๊ฐ ๋ถ๋ชจ์๊ฒ ์ฑ๊ณต ๋ฉ์์ง๋ฅผ ๋ณด๋ธ ํ ์ค๋ ์๊ฐ์ด ์ง๋ ํ ํน์ ์ํฉ์์ ๋๋ฌด ๋ฆ๊ฒ ์ถ๋ ฅ ์คํธ๋ฆผ์ ํ๋ฌ์ํ๋ ๋ ธ๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
๊ณ ์ณ์ฃผ์ธ์, ์ด๊ฒ์ ๋๋ด์ผ๋ก ์์ฐ์ฑ์ ์ ๋ง ํด์นฉ๋๋ค
[email protected] ์ผ๋ก ๋ค์ด๊ทธ๋ ์ด๋ํ๋ฉด ์ฝ์ ๋ก๊ทธ ์ถ๋ ฅ์ด ๋ค์ ๋ํ๋ฉ๋๋ค. ๊ทธ๋๋ ์๋ํ๋ ค๋ฉด --env ๋ ธ๋๋ฅผ ์ค์ ํด์ผ ํ์ต๋๋ค. ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ธ์.
ํ์ฌ ์ ๋ขฐํ ์ ์๋ ์ฝ์ ๋ก๊น ์ ์ป์ ์ ์๋ ์ ์ผํ ๋ฐฉ๋ฒ์ ๋์ผํ ๊ฒ์ ์ฐ์ 3-4๋ฒ ๋ก๊น ํ๋ ๊ฒ ๊ฐ์ต๋๋ค. Jest๋ ํน์ ์ซ์๋ง ์ฐจ๋จํฉ๋๋ค. ์ฌ์ ํ ๋งค์ฐ ์ง์ฆ๋ฉ๋๋ค.
์ด์ ๋ํ ์ ๋ฐ์ดํธ๊ฐ ์์ต๋๊น? jest 23.4.1 ๋ฐ ๋ ธ๋ 9.11.1์ ์คํ ์ค์ด๋ฉฐ ์ฝ์ ๋ก๊ทธ ์ถ๋ ฅ์ด ๋ํ๋ ๋๋ ์๊ณ ๊ทธ๋ ์ง ์์ ๋๋ ์์ต๋๋ค.
2๋ ๋์ ์ฝ์ ๋ก๊ทธ๊ฐ ์์๊ธฐ ๋๋ฌธ์ ๋ ๋์ ๊ฐ๋ฐ์๊ฐ ๋์์ต๋๋ค. Jest ํ ๊ฐ์ฌํฉ๋๋ค!
์ด๊ฒ์ด ์ฌ์ ํ ๋ฌธ์ ๋ผ๋ ๊ฒ์ด ๋ฏฟ๊ธฐ์ง ์์ต๋๋ค. ์ ์ด์๊ฐ ์ข ๋ฃ๋์๋์?
๋ด ๋ง์, ๋๊ฐ ์คํจํ ํ ์คํธ๋ฅผ ๋๋ฒ๊ทธํ๊ณ ์ถ์ดํ๊ฒ ์ต๋๊น?
@jonogilmour๊ฐ ์ธ๊ธํ๋ฏ์ด ํ ๋ฒ ๊ธฐ๋กํ๋ฉด ํ์๋์ง ์์ง๋ง ๋ ๋ฒ ๊ธฐ๋กํ๋ฉด ๊ทธ ์ค ํ๋๊ฐ ํ์๋ฉ๋๋ค.
FWIW, --verbose=false ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์ ์๊ฒ ํจ๊ณผ์ ์
๋๋ค. ๋ด package.json
:
"scripts": {
...
"test": "react-scripts test --env=jsdom --verbose=false",
๋ค๋ฅธ ๊ด์ฐฐ:
์๋
๋จ์/์ฌ์,
--watch ๋ชจ๋์์ ํ
์คํธ๋ฅผ ์คํํ ๋ ์ ๋ช
ํ jest ์ฝ์ ๋ก๊ทธ ๋ฌธ์ ๋ ๋ง๋ฌ์ต๋๋ค.
ํด๊ฒฐ์ฑ
์ --watch ๋์ --watchAll์ ์ฌ์ฉํ๋ ๊ฒ์
๋๋ค. ํ
์คํธ ์์ฝ์ด ๋ ๋ณด๊ธฐ ํํด์ก์ง๋ง ๋ก๊ทธ๋ ์์๋๋ก ํ์๋์์ต๋๋ค.
macOS ํ์ด ์์๋ผ
๋
ธ๋ v8.11.3
๋๋ด: 23.6.0
ts-jest: 23.10.4
๋์๊ฒ ์ด๊ฒ์ beforeAll
console.log = s => {
process.stdout.write(s + "\n");
};
๊ทธ๋ฆฌ๊ณ ์ด๊ฒ์ ์์์ ์์ ์ ์ํํ์ต๋๋ค.
yarn test > test.log
์ ์๊ฒ๋ mocha
๋ก ์ ํํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค. DSL์ด ๋งค์ฐ ์ ์ฌํ๊ธฐ ๋๋ฌธ์ ์ ํํ๋ ๊ฒ์ ๋งค์ฐ ๊ฐ๋จํฉ๋๋ค. JEST์ ์์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ณ์ ์ฌ์ฉํ ์๋ ์์ต๋๋ค. https://www.npmjs.com/package/expect
jest
๋ฅผ ์ ๊ฑฐํ๊ณ mocha
$ ๋ฅผ ์ค์นํ๋ ๊ฒ๋งํผ ์ฝ์ต๋๋ค.
ํธ์ง: ์คํธ ์ฌ๋ถ, ์ฌ๊ธฐ์์ ๊ฐ์ฅ ์ฌ์ด ์๋ฃจ์ ์ ๋๋ค.
์ด ๋ฌธ์ ๋ ์ ๋ง ๊ณ ํต์ค๋ฝ์ต๋๋ค. Jest๋ ์์ฐ์ฑ์ ๋์ด๊ธฐ ์ํ ๊ฒ์ด์ง ๊ทธ ๋ฐ๋์ ๋ชฉ์ ์ด ์๋๊ธฐ ๋๋ฌธ์ ์ ์ง ๊ด๋ฆฌ์๊ฐ ๊ฐ๋ฅํ ํ ๋นจ๋ฆฌ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
์ด์จ๋ , ๋ค์์ ์ง๊ธ ์ฐ๊ธฐ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๋๋ค.
export const log = (s: any) => {
console.log(s);
console.log(s);
console.log(s);
process.stdout.write(s + "\n");
};
์คํธ๋ฉ์ผ์ ๋ณด๋ด์ผ ํฉ๋๋ค.
--verbose=false
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋์ง ํ์ธํ์ต๋๋ค.
--verbose=false
๋ฒ์ ์ด 23.6.0
์์๋ ์๋ํ์ง ์์ต๋๋ค.
์ธ์์ ์ด๊ฑด ๊ณ ํต์ด์ผ :/ 2018๋ 11์
์ด ๋ฌธ์ ๋ฅผ ๋ค์ ์ด์ด์ฃผ์ธ์
silent: false
in jest.config.js
... ์ ๊ฒฝ์ฐ์๋ ๋์์ด ๋์์ต๋๋ค.
์ด๋ค ์๋ฃจ์
๋ ์๋ํ์ง ์์ต๋๋ค.
๋
ธ๋JS: v8.12.0
๋๋ด: v23.4.1
๋๋ Jest๋ฅผ ๋ช ๋ฌ ๋์ ์ฌ์ฉํด ์์ผ๋ฉฐ ํ๋ฅญํ๊ณ ์ด ๋ฒ๊ทธ๊ฐ _๋งค์ฐ ์ง์ฆ๋๋_ ๋ฐ๋ฉด์ ๋ด๊ฐ ํญ์ ์ฌ์ฉํ๋ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋งค๋ฒ ์ฝ์์ ๊ธฐ๋ก๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ ํฌ ์ด์ค์ ์ ๋ง๋๋ ๊ฒ์ ๋๋ค.
์๋ฅผ ๋ค์ด ๋ชจ์ ํธ์ถ์ ๋ก๊ทธ์์ํ๋ ค๊ณ ํ ๋:
expect('hello').toEqual(childFunc.mock.calls[0])
์ถ๋ ฅ:
์ด์์ ์ด์ง๋ ์์ง๋ง ์์ ์ ์๋ฃํ๊ณ ํ ์คํธ ์์ฑ์ ๋ง์น ์ ์์ต๋๋ค.
--watch ํ๋๊ทธ๋ก Jest๋ฅผ ์คํํฉ๋๋ค.
Jest ๋ฒ์ 23.5.0
๋
ธ๋ ๋ฒ์ 8.11.3
์ด๊ฒ์ ํ๋ ์๋์์ ์งํ๋๋ "๋๋ฌด ๋ง์ ๋ง๋ฒ"๊ณผ ๋ฌด์ธ๊ฐ ์๋ชป๋์์ ๋์ ๊ฒฐ๊ณผ์ ๋ํ ์ ์ ํ ์์ ๋๋ค. ๋๋ console.log ์ถ๋ ฅ์ ๊ทธ๋ฃนํํ๋ ๊ฒ์ด console.log ๋ฌธ์ ๋๋ฝํ ๊ฒ๋ณด๋ค 1๋ ๋ฐ์ ๊ฐ์น๊ฐ ์๋ค๊ณ ํ์ ํ์ง ์์ต๋๋ค. ๐
์์ ๋ด์ฉ์ ๋์ํ์ญ์์ค. ์ด๊ฒ์ ์์ฃผ ๋๋ผ์ด ๊ฒ์ ์๋์ง๋ง ์์ ํ ๋ถํ์ํ ๋ฐฉ์์ผ๋ก Jest๋ฅผ ๊ณ ํต์ค๋ฝ๊ฒ ๋ง๋ญ๋๋ค.
๋ด "ํด๊ฒฐ ๋ฐฉ๋ฒ"์ ๋ง์ ๋
ผ๋ฆฌ๊ฐ log4js
๋ฅผ ์ฌ์ฉํ๋ค๋ ๊ฒ์ด๋ฏ๋ก Jest๋ฅผ ์๋ฒ ์ธก ์ฝ๋๋ก ๊ตฌ๋ถ๋ฆฌ๋ ๊ฒฝ์ฐ์๋ ์ข์ต๋๋ค. ์ฌํ๊ฒ๋ ๋๋ ๊ฒฐ๊ตญ ๊ทธ๋ค ์ค ํ๋๊ฐ ๋ํ๋๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๊ธฐ ๋๋ฌธ์ ์ผ๋ฐ์ ์ผ๋ก ๊ฐ console.log
์ ์ฌ๋ณธ 4๊ฐ๋ฅผ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ๋ ๋ง์ ์์ ํด๋ผ์ด์ธํธ ์ธก ์ฝ๋๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.
expect
๋ฅผ ์ฌ์ฉํ์ฌ ์ ๋ณด๋ฅผ ๊ธฐ๋กํ๋ ๊ฒ์ ํ
์คํธ ๋ด์์ ๋ก๊ทธ์ธํ๋ ๊ฒฝ์ฐ ๊ด์ฐฎ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด์ง๋ง(ํนํ ํธ์ง๊ธฐ์์ logjest
์ ๊ฐ์ ํค์๋๋ก ์ค๋ํซ์ ๋ง๋ค ์ ์๊ธฐ ๋๋ฌธ์) ํ
์คํธ๊ฐ ํธ์ถํ๋ ์ค์ ํจ์ ๋ด์์ ๋ ๊น์ด ํ๊ณ ๋ค๊ณ ๊ธฐ๋กํด์ผ ํ ๋๋ง๋ค ๋ถ์กฑํฉ๋๋ค.
CI=true yarn run test
๋ ์ด๋ป์ต๋๊น?
์ ์ ๋งํด์ ๋ฏธ์ํ์ง๋ง ํ
์คํธ ์ผ์ด์ค์ ์ ๋ชฉ ์์ด๋ ์ ์๋ํฉ๋๋ค. "--verbose" ์ต์
์ด ์์ผ๋ฉด --verbose๊ฐ ์ผ์ข
์ ํ์ ์ง์ ์ ์ํํ๊ณ stdout ์คํธ๋ฆผ์ ๋์ฒดํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
๊ทธ๋์ ์ ๋ 2๊ฐ์ ์ ๋ ๋์๊ณ ๋ชจ๋ ๊ฒ์ด ์ ์๋ํ๊ณ ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋๊ตฐ๊ฐ ๊ทธ ์ต์
์ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด npm ๋ช
๋ น์๋ง ์ถ๊ฐํ์ญ์์ค: npm run test:integration -- --watchAll --verbose --coverage --etc
๋ฌธ์ ๊ฐ ์๋ ์ฌ์ฉ์๊ฐ [email protected]
๋ฅผ ํ
์คํธํ ์ ์์ต๋๊น? ์ฌ๊ธฐ์๋ #6871์ด ํฌํจ๋ฉ๋๋ค.
@jamesta696 ์๋
ํ์ธ์. ์ฌ๊ธฐ ํ ๋ก ์ "๋ฌธ์ "์ ๋ํ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ฌ๊ธฐ ์ "์ฅ๋" ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ StackOverflow์ ๊ทธ๋ฐ ์ข
๋ฅ์ ์ง๋ฌธ์ ๊ฒ์ํด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ๊ทธ๋ผ์๋ ๋ถ๊ตฌํ๊ณ ๋๊ตฐ๊ฐ๊ฐ ๋น์ ์ ๋์ธ ์ ์๋ค๋ ๊ฒ์ ์๊ณ ์์ง๋ง ์ฌ๊ธฐ ๋ฌธ์ ๋ ์ฃผ์ ๋ฌธ์ ๊ฐ ๋
ผ์๋์ง ์๊ธฐ ๋๋ฌธ์ ๋ซํ๋๋ค.
๊ทธ๋ฆฌ๊ณ ์ง๊ธ์ผ๋ก์๋ ๋ฐ์๊ณผ ํ๋ก ํธ์๋๋ฅผ ์ํ ๋ฌด์ธ๊ฐ๋ฅผ ๊ฐ๋ฐํ๊ณ ์์ง ์๊ธฐ ๋๋ฌธ์ ๊ทธ ์ง๋ฌธ์ ๋ํ ๋ต์ ๋๋ฆด ์ ์์ต๋๋ค. ๋ํ ์ ๋ ๋๋ด์ ์ผ์์ด ์๋์ง๋ง ๊ท์น์ ๋ฐ๋ฅด๋๋ก ๋
ธ๋ ฅํฉ์๋ค.
@SimenB ๋๋ jest๋ฅผ (๊ทํ์ ์ธ๊ธ๋ ๋ฒ์ ์ผ๋ก) ์
๋ฐ์ดํธํ๊ณ ๋ฌธ์ ๊ฐ ์๋ ๋ด ํ๋ก์ ํธ์ ๋ช ๊ฐ์ง console.log
๋ฌธ์ ๋ฐฐ์นํ๋ ค๊ณ ์๋ํ์ต๋๋ค. ์ง๊ธ๊น์ง๋ ์์ ๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ชจ๋ console.log
๊ฐ ๋ํ๋ฉ๋๋ค. ๊ณ์ ์ฌ์ฉํ๊ณ ๋ฌธ์ ๊ฐ ๋ค์ ๋ฐ์ํ๋ฉด ์๋ ค ๋๋ฆฌ๊ฒ ์ต๋๋ค.
์ฐธ๊ณ ๋ก ์ ๋ jest --watchAll
๋ฅผ ์ฌ์ฉํ๊ณ ์์์ต๋๋ค.
@tobyhinloopen @SimenB ๋ฅผ ์ธ๊ธํ ์งํ ์ํฉ์ ์ฆ๊ฑฐ๋ฅผ ๋ณด๋ ๋ฐ๊ฐ ์ต๋๋ค.
๋ฉ์ง๋ค์ @tobyhinloopen!
๋ํ [email protected] ๊ฐ ์ ์๋ํ๊ณ --verbose=false ์์ด ๋ชจ๋ ์ฝ์ ๋ก๊ทธ๋ฅผ ๋ณผ ์ ์์์ ํ์ธํ ์ ์์ต๋๋ค.
๋ํ [email protected] ๊ฐ ์ ์๋ํ๊ณ --verbose=false ์์ด ๋ชจ๋ ์ฝ์ ๋ก๊ทธ๋ฅผ ๋ณผ ์ ์์์ ํ์ธํ ์ ์์ต๋๋ค.
+1. ํ์ธํ ์๋ ์์ต๋๋ค. ์ด๊ฒ์ด ์๋ํ๋ ๊ฒ์ ๋ณด๊ฒ๋์ด ๊ธฐ์ฉ๋๋ค. ์ํ์ด์, Jest ์ฌ๋ฌ๋ถ! ๐
๋๋ ํ์ธํ ์ ์์ด! ๋ง์น ํฌ๋ฆฌ์ค๋ง์ค ๊ฐ๋ค. ๐
๐
create-react-app ์ ๋ฐ์ดํธ๊น์ง ๊ธฐ๋ค๋ฆด ํ์๊ฐ ์์ต๋๋ค.
๋๋ jest ๋ฒ์ 24.0.0
์ ์คํํ๊ณ ์์ง๋ง ์ฌ์ ํ console.log
๋๋ console.error
๋ณผ ์ ์์ต๋๋ค. ๋ด๊ฐ ๋ฌด์์ ์๋ชปํ๊ณ ์๋์ง ๊ถ๊ธํฉ๋๋ค.
๊ทธ๋ค์ด ์กฐ๋กฑ๋ฐ์ง ์์๋์ง ํ์ธํ์ญ์์ค
์ ๋ง ์ด์ํฉ๋๋ค. ๋น๋๊ธฐ ์ฒ๋ฆฌ์ ๋ฌธ์ ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ค๋ฅ๋ฅผ ํ์ํ ์ ์์ต๋๋ค. try/catch
๋ธ๋ก์ผ๋ก ๋ํํด๋ ์ค๋ฅ๊ฐ ๋ณด์ด์ง ์์ต๋๋ค.
generator
๋งค๊ฐ๋ณ์๋ ํ์คํ ์ ํํฉ๋๋ค. ๋น๋๊ธฐ ํจ์ ํธ์ถ์ ์ ๊ฑฐํ๋ฉด ์ฌ๋ฐ๋ฅด๊ฒ ๊ธฐ๋ก๋ฉ๋๋ค. ๋ํ for ๋ฃจํ ์ธ๋ถ์ ์์ ๋ ์ฌ๋ฐ๋ฅธ ๋ฌธ์์ด์ ๋ฐํํฉ๋๋ค.
Jest ๋ฒ์ ์ 24.0.0
, ๋
ธ๋๋ 10.5
@tiborsaas console.log
๊ฐ ์คํ๋๊ธฐ ์ ์ ํ
์คํธ๊ฐ ์๋ฃ๋์์ ๊ฒ์
๋๋ค.
changedGenerators
๋ฐ๋ณต์ ๊ธฐ๋ค๋ฆฌ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ ๊ฒ์ด ํ์ํฉ๋๋ค.
await Promise.all(changedGenerators.map(async (generator) => {/* ... */}))
๋ต์ฅ์ ๋ณด๋ด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. ํ์ง๋ง ์ค์ ๋ก๋ ๊ทธ๋ ์ง ์์ต๋๋ค. ์ผ๋ถ ์ค๋ฅ๋ก ์ธํด console.log
๊ฐ ํ์๋์ง ์์ต๋๋ค. forEach
์ฝ๋ฐฑ์์ ํธ์ถํ๋ฉด console.log
์ ์ ์๋ํ๋ ๋ ๋ค๋ฅธ ๋น๋๊ธฐ ํจ์๊ฐ ์์ต๋๋ค.
ํธ์ง : ์ค์ ๋ก ์ค ๋จ์ ๋๋ฒ๊น ์ผ๋ก ๋ฌธ์ ๊ฐ ์๋ค๋ ๊ฒ์ ์๊ณ ์์ต๋๋ค.
const archives = await fs.readdir(archiveDir);
๊ทธ๋ฌ๋ ์ด ๋๋ด ๋ฌธ์ ๋ ๋ก๊น ์ ๊ดํ ๊ฒ์ ๋๋ค. ๋ํ๋ฅผ ๋ฐฉํดํ๊ณ ์ถ์ง ์์ต๋๋ค.
์ฌ์ ํ ๋ฒ๊ทธ๊ฐ ๋ฐ์ํ๊ณ ์์์ง๋ ๋ชจ๋ฆ ๋๋ค. (์ ํํ ์ฝ๋๋ฅผ ๋ชจ๋ฅธ ์ฑ) ์ผ๋ฐ์ ์ผ๋ก ํ ์คํธ๊ฐ ์๋ฃ๋ ํ ๊ฑฐ๋ถ๋ ์ ์๊ธฐ ๋๋ฌธ์ ๊ธฐ๋ค๋ฆฌ์ง ์๊ณ ์ด์ ๊ฐ์ ํ๋ผ๋ฏธ์ค๋ฅผ ํฌํฌํ๋ ๊ฒ์ ์ผ๋ฐ์ ์ผ๋ก ๋์ ์๊ฐ์ด๋ผ๋ ์ ์ ์ง์ ํ๊ณ ์ถ์์ต๋๋ค. )
๋์ํฉ๋๋ค. ํ์ง๋ง forEach
์์ expect
ํธ์ถ์ ์คํํ๊ณ ์ถ์ต๋๋ค. ์๋ํ๋ฉด ์ผ๋ง๋ ๋ง์ ๋ณ๊ฒฝ ์ฌํญ์ ์ฒ๋ฆฌํด์ผ ํ๋์ง ๋ฏธ๋ฆฌ ์์ง ๋ชปํ๊ธฐ ๋๋ฌธ์
๋๋ค.
๋ถํํ๋ Promise.all
์ ๊ทผ ๋ฐฉ์์ ์๋ฌด ๊ฒ๋ ์์ ํ์ง ์์์ต๋๋ค.
forEach
map
๋ฅผ ์ฌ์ฉํ์
จ์ต๋๊น? ์์ ์ Promise.all
์ ๋ํ ์ฝ์ ๋ฐฐ์ด์ ๋ฐํํ๋ ๊ฒ์
๋๋ค.
@SimenB ๋ค, ์๋๋ค.
์ค๋ฅ๊ฐ ์์ผ๋ฉด ๋ณผ ์ ์์ต๋๋ค.
@tiborsaas Promise.all
๊ฐ ์๋ฃ๋๊ธฐ๋ฅผ ๊ธฐ๋ค๋ฆฌ์ง ์์ต๋๋ค: await Promise.all(...)
์ฌ์ฉ
๊ทธ๊ฒ๋ ๋๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ. :(
promise.all
await new Promise((resolve) => setTimeout(resolve, 1000))
๋ฅผ ์ถ๊ฐํ๋ฉด ์ด๋ป๊ฒ ๋ ๊น์?
์ฌ์์ฐ์ผ๋ก ์๋ก์ด ๋ฌธ์ ๋ฅผ ์ด โโ์ ์์ต๋๊น? OP์์ ๋ณด๊ณ ํ ๋ฌธ์ ๋ ๋ค๋ฅธ ๋ฌธ์ ๋ฅผ ๋ณด๊ณ ์๋ ๋์ ์์ ๋์๋ค๊ณ ์๊ฐํฉ๋๋ค(๋น๋๊ธฐ๋ฅผ ์ฌ๋ฐ๋ฅด๊ฒ ์ฒ๋ฆฌํ๋์ง ์ฌ๋ถ์ ๊ด๊ณ์์ด ์ฌ์ ํ ๋ก๊ทธ ๋ฌธ์ ๋ณผ ์ ์์ด์ผ ํจ)
๋ค, ์ฐธ์ผ๋ก ์ด์ํฉ๋๋ค.
test('stuff', () => {
setTimeout(() => console.log('hi', 500));
})
์ผ๋ฐ์ ์ผ๋ก ์ฌ์ ํ ์ด๋ค ๋ฐฉ์์ผ๋ก๋ ์ธ์๋ฉ๋๋ค.
๊ทธ๋ Promise.all([...], callback)
์ ๋ ๋ฒ์งธ ์ธ์๋ก ์ฝ๋ฐฑ ํจ์๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๊ทธ๋ Promise.all([...]).then(callback)
๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค. ์๋ง๋ ๊ทธ๊ฒ์ด ๊ทธ์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค๊ณ ์๊ฐํฉ๋๋ค .all
์ ๋ ๋ฒ์งธ ์ธ์๋ ๋ฌด์๋๊ณ ์คํ๋์ง ์์ต๋๋ค(๋ฐ๋ผ์ ๋ก๊ทธ๊ฐ ์คํ๋์ง ์์). @tiborsaas
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
์, ํ๋ ธ์ต๋๋ค. ํ์ง๋ง ๋ก๊ทธ ๋ฌธ์ ์ฌ์ ํ โโํ์๋์ด์ผ ํฉ๋๋ค.
@SimenB ์๋์, ๋ ๋ฒ์งธ ์ธ์๋ ๋ฌด์๋ฉ๋๋ค.
> Promise.all([Promise.resolve(true)], () => console.log("hi")).then(console.log, console.error);
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
// output:
// [ true ]
์, ํผ๋ํ์ต๋๋ค. ์ฃ์กํฉ๋๋ค. Thx @tobyhinloopen
const lol = await Promise.all(versions);
์ด ์์๋๋ก ์๋ํ์ต๋๋ค.
์ด ๊ฒฝ์ฐ ํจ์๊ฐ ํธ์ถ๋์ง ์๊ธฐ ๋๋ฌธ์ ๋ก๊ทธ ๋ฌธ์ด ์์ค๋ ์ ์์ง๋ง ๋
ธ๋๊ฐ ํ๋ก์ธ์ค๋ฅผ ์ข
๋ฃํ๊ธฐ ์ ์ ํ๋ผ๋ฏธ์ค๊ฐ ์๋ฃ๋ ๋๊น์ง ๊ธฐ๋ค๋ฆฌ๋ฏ๋ก ์๋ forEach
์ ๊ฒฝ์ฐ ๋ก๊ทธ ๋ฌธ์ด ๊ณ์ ํ์๋์ด์ผ ํฉ๋๋ค. ๊ทธ๋์ ์ฌ์ฉ์ ์ค๋ฅ์ธ๋ฐ๋ ์ฌ์ ํ ๋ฒ๊ทธ์
๋๋ค.
ํ๋ณด: # 7731
https://www.npmjs.com/package/debug ๋ฅผ ์ฌ์ฉํ์ฌ ๋ก๊น ์ ์ํํฉ๋๋ค. Jest์ ํจ๊ป ํ๋ฉด ๋ ๊น์?
์๋์, #6524๋ฅผ ํ ๋๊น์ง๋ ์๋๋๋ค.
ํ
์คํธ์์ debug
๋ฅผ ์กฐ๋กฑํ๊ณ ํ
์คํธํ๋ ค๋ฉด console.log
๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
์ฐธ๊ณ ๋ก ์ฝ์ ๋ฉ์์ง๋ ํ ์คํธ๊ฐ ์๋ฃ๋ ํ ์ถ๋ ฅ๋ ๊ฒฝ์ฐ ์์ค๋ ์ ์์ต๋๋ค. #7731 ํ๋จ์ ์ฃผ์์ ์ฐธ์กฐํ์ธ์. ์ด๊ฒ์ด ์ผ๋ถ ์ด์ ์ผ ์ ์์ง๋ง ์ฌ๊ธฐ์ ๋ณด๊ณ ๋ ๋๋ฝ๋ ์ฝ์ ๋ฉ์์ง์ ์ ๋ถ๋ ์๋ ์ ์์ต๋๋ค.
--verbose ๋๋ฅผ ์ํด ์ผํ์ต๋๋ค. --verbose๋ฅผ ์ฌ์ฉํ๊ธฐ ์ ์๋ ๋ชจ๋ ๋ฉ์์ง๊ฐ ์๋ ์ผ๋ถ ๋ฉ์์ง๊ฐ ์์ค๋์์ต๋๋ค. ๋ ธ๋ v10.15.3 ๋ฐ jest v21.2.1์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
์ฌ์ ํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์ฝ์ ๋ก๊ทธ๊ฐ Jest์ ํ์๋์ง ์์ต๋๋ค.
๋ฌธ์ ๊ฐ ๋ง์นจ๋ด ํด๊ฒฐ๋์๋ค๋ ๋ธ๋ก๊ทธ์ ์ต์ ๋ฐํ์๋ ๋ถ๊ตฌํ๊ณ ๋ฌธ์ ๋ ์ฌ์ ํ ์กด์ฌํ๊ณ ๋๋ก๋ ์ฝ์ ๋ก๊ทธ๊ฐ ๋ค์ ํ์๋์ง ์์ต๋๋ค. ์ ๋ jest v24.8.0
๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ์ ์ํ์ ๊ด์ฐฎ์ต๋๋ค ๐คทโโ๏ธ. ์กฐ์ฌํ ์ ์๋ ๋ณต์ ๋ฌผ์ ๊ฒ์ํ์ญ์์ค. ์ฐ๋ฆฌ๋ ๋ง๋ฒ์ฌ๊ฐ ์๋๋ฏ๋ก ์ถ๋ ฅ์ ๊ธฐ๋กํ์ง ๋ชปํ๋ ์ฝ๋๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
์ค์ ๋ก ์กฐ์ฌ ํ API ํ ์คํธ(์: supertest)์ ๊ด๋ จ๋ ๋ก๊ทธ๊ฐ ์๋ํ์ง ์์ต๋๋ค. ์์๋๋ :/
@thymikee ์ด๊ฒ์ ์ผ๊ด๋์ง ์๊ฒ ๋ฐ์ํ๋ฏ๋ก ์ฌํํ๊ธฐ๊ฐ ์ ๋ง ์ด๋ ต์ต๋๋ค. ์์:
ํ
์คํธ์์ ๋จ์ผ ํ์ผ์ ์ ํํ์ฌ ๋ค์ ์คํ( ์ต์
p )
์ด์ ๋์ผํ ๋จ๊ณ๋ฅผ ๋ณต์ ํ๋ ค๊ณ ์๋ํ์ง๋ง ๊ฒฐ๊ณผ๊ฐ ์ผ์นํ์ง ์์ต๋๋ค.
JEST ์ง์์ด ๋๋ฒ๊น ์ ๋์ธ ์ ์๋๋ก ์๋ํ์ง ์๋ ์ํ ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ์ ๊ณตํ์ธ์. @ํฌ๋ ์ฌ๋ฆฌ
await
๋๋ ๋น๋๊ธฐ console.log
๊ฐ ๋๋ถ๋ถ ๋๋ฝ๋ ์ฌ์ฉ์ ์ค๋ฅ ๊ฐ๋ฅ์ฑ๋ ๋ง์ด ์์ต๋๋ค.
๊ทธ ๋ ์ด๊ฒ์ ์ฌํํ๋ ์๊ฐ์ ์ฐพ๋๋ก ๋ ธ๋ ฅํ๊ฒ ์ต๋๋ค. ๊ทธ๋๊น์ง ๋๋ ์๋์์ ๋ณผ ์ ์๋ฏ์ด ๋ด ๋ก๊ทธ๊ฐ ๊ฒฐ๊ณผ์ ์ํด ๋จนํ๋ ๊ฒ์ ๋ฐ๊ฒฌํ์ต๋๋ค. FAIL์ด ํ์๋๊ธฐ ์ ์ 2๊ฐ์ ๋ก๊ทธ๋ฅผ ๋ณผ ์ ์์ต๋๋ค. ๋ํ 2๊ฐ์ ๋ก๊ทธ๋ง ์ ๊ฑฐ๋๋ค๋ ์ ๋ ์ธ๊ธํ ๊ฐ์น๊ฐ ์์ต๋๋ค. ์๋ก ์๋์ 10๊ฐ์ ๋ก๊ทธ๋ฅผ ์ถ๊ฐํ๋ฉด 8๊ฐ๊ฐ ํ์๋ฉ๋๋ค. ์ข์ ์์์ธ ๊ฒ ๊ฐ์์ :)
ํํธ, ์๋ํ๋ ํฌ๊ด์ ์ธ ์์ ์ด ํ์ํ ๊ฒฝ์ฐ winston
์ ๊ฐ์ ๊ฒ์ ์ฌ์ฉํ์ฌ ํ์ผ๊ณผ ์ฝ์์ ๋ชจ๋ ๊ธฐ๋กํ ์ ์์ต๋๋ค. ์ฝ์ ๋ฉ์์ง๊ฐ ํ์๋์ง ์๋๋ผ๋ ํ์ผ์ ๊ธฐ๋ก๋ฉ๋๋ค.
winston
๋ฅผ ์ฌ์ฉํ๋ฉด ์ด๋์ ๊ธฐ๋กํ ๊ฒ์ธ์ง ๊ตฌ์ฑํ ์ ์์ผ๋ฉฐ ๋ค์ค ์ ์ก์ ์ง์ํ๊ณ ์ฌ์ฉ์๊ฐ ์ง์ ๊ตฌํํ ์ ์์ต๋๋ค.
const logger = winston.createLogger({
level: "verbose",
format: winston.format.json(),
defaultMeta: {},
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: "combined.log" }),
],
});
logger.error(stuff)
์๋ง๋ winston์ ๋ก๊ฑฐ์ ๋ํด ์ ์ญ์ ์ผ๋ก console.*
๋ฅผ ์ฌ์ ์ํ๋ ๊ฒ๊ณผ ๊ฐ์ ๋๋ฌ์ด ์ผ์ ํ ์๋ ์์ต๋๋ค.
@kresli ๋น์ ์ ๋๋ด์ ์ด๋ค ๋ฒ์ ์ธ๊ฐ์? v23 ๋์์ฒ๋ผ ๋ณด์ ๋๋ค.
์ด๊ฒ์ jest v^24.6.0
๋ฐ node v10.14.2
์์ ๊ณ์ ๋ฐ์ํฉ๋๋ค. ์ด์ ๋ฅผ ์๊ฒ ์ด์?
@yaelz ์ด๊ฒ์ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉ์ ์ค๋ฅ๋ก ์ธํด ๋ฐ์ํ์ง๋ง ๋ฒ๊ทธ๋ฅผ ์ฌํํ๊ธฐ ์ด๋ ค์ด ์ด๋ ฅ์ด ์๋ ์๊ณ ํ ๋ฌธ์ ์ ๋๋ค.
๊ธฐ์ฌ์๋ค์ด ์์ ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ์ ๊ณตํ์ฌ ์ฌํ ๊ฐ๋ฅํ ์ฌ๋ก๋ฅผ ์ ๊ณตํ๊ฑฐ๋ ๋ฌธ์ ๋ฅผ ์ฌํํ ์ ์๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ ๊ฒ์ด ์ ๋ง ๋์์ด ๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
๋น ๋ฅธ ์๋ต ๊ฐ์ฌํฉ๋๋ค!
ํ์ฌ ๋ฆฌํฌ์งํ ๋ฆฌ๊ฐ ๋ด ์กฐ์ง์์ ๋น๊ณต๊ฐ์ด๊ธฐ ๋๋ฌธ์ ์ด๋ ค์ธ ๊ฒ์
๋๋ค... ์๊ฒ ๋๋ฉด ์๋ ค ๋๋ฆฌ๊ฒ ์ต๋๋ค. :)
์ด๊ฒ์
jest v^24.6.0
๋ฐnode v10.14.2
์์ ๊ณ์ ๋ฐ์ํฉ๋๋ค. ์ด์ ๋ฅผ ์๊ฒ ์ด์?
์ต๊ทผ์ ํ๋ก์ ํธ์์ ์ผ๋ถ ์ข ์์ฑ์ ์ ๊ทธ๋ ์ด๋ํ๋๋ฐ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ํ ๋ฌ ์ ์ ์ง๋ฉดํ์ง๋ง ์ต์ ๋ฒ์ ์์๋ ํด๊ฒฐ๋์์ต๋๋ค.
๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๋ฉด ์ง๊ธ ์ฌ์ฉ ์ค์ธ ๋ฒ์ ์ ๊ณต์ ํด ์ฃผ์๊ฒ ์ต๋๊น?
2019๋
8์ 5์ผ ์์์ผ ์คํ 12:43 Norman Enmanuel [email protected]
์ผ๋ค:
๋น ๋ฅธ ์๋ต ๊ฐ์ฌํฉ๋๋ค!
ํ์ฌ ์ ์ฅ์๊ฐ ๋ด ์กฐ์ง์์ ๋น๊ณต๊ฐ์ด๊ธฐ ๋๋ฌธ์ ์ด๋ ค์ธ ๊ฒ์ ๋๋ค.
๋ด๊ฐ ๊ทธ๊ฒ์ ๋๋ฌํ๋ฉด ๋น์ ์ ์๊ณ ์์ต๋๋ค :)์ต๊ทผ์ ํ๋ก์ ํธ์์ ์ผ๋ถ ์ข ์์ฑ์ ์ ๊ทธ๋ ์ด๋ํ๋๋ฐ ์๋ฌด๋ฐ ์ข ์์ฑ์ด ์์ต๋๋ค.
๋ฌธ์ , ๋๋ ํ ๋ฌ ์ ์ ์ด๊ฒ์ ์ง๋ฉดํ์ง๋ง ์ต์ ๋ฒ์ ์์ ํด๊ฒฐ๋์์ต๋๋ค.
๋ฏฟ๋ค...โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/facebook/jest/issues/3853?email_source=notifications&email_token=AB6F4PAE3CHUMEBP7IYXRPLQC7Y2DA5CNFSM4DPZ3JSKYY3PNVWWK3TUL52HS4DFVREXG43VMXHJKTDNMV
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/AB6F4PFXDSRHBW5CMTT2DKDQC7Y2DANCNFSM4DPZ3JSA
.
๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๋ฉด ์ง๊ธ ์ฌ์ฉ ์ค์ธ ๋ฒ์ ์ ๊ณต์ ํด ์ฃผ์๊ฒ ์ต๋๊น?
ํ์ ํ๋:
๋๋ด
^24.8.0
๋ ธ๋ -v
v10.16.0
๊ทธ๋ฆฌ๊ณ ์ด๊ฒ์ e2e, ํตํฉ, ๋จ์ ๋ฐ ์๋ฝ์ ๋ชจ๋ ์คํํ๋ ๋ฐ ์ฌ์ฉํ๋ ๋ช ๊ฐ์ง npm ์คํฌ๋ฆฝํธ์ ๋๋ค.
"scripts": {
"test": "NODE_ENV=test npm run test:unit && npm run test:integration:both",
"test:unit": "NODE_ENV=test jest --config test/jest.config.unit.js --detectOpenHandles",
"test:integration": "NODE_ENV=test MOCK=false jest --config test/jest.config.integration.js --runInBand --detectOpenHandles",
"test:integration:mock": "NODE_ENV=test MOCK=true jest --config test/jest.config.integration.js --runInBand --detectOpenHandles",
"test:integration:both": "NODE_ENV=test npm run test:integration:mock -- --coverage; npm run db:migration:test; npm run test:integration -- --coverage;",
"test:report": "open docs/test/report/index.html",
"test:report:coverage": "open docs/test/coverage/lcov-report/index.html"
}
์ด๊ฒ์ jest.config์ ๋๋ค.
"use strict";
module.exports = {
"bail": true,
"verbose": false,
"collectCoverage": false,
"expand": true,
"testURL": "http://localhost:3000/",
"coverageDirectory": "./docs/test/coverage",
"testEnvironment": "node",
"rootDir": "../",
"setupFilesAfterEnv": [
"./test/jest.setup.js"
],
"jest.showCoverageOnLoad": true,
"watchPathIgnorePatterns": ["node_modules"],
"transform": {
"^.+\\.js$": "babel-jest",
'^.+\\.tsx?$': 'ts-jest',
},
"reporters": [
"default",
["./node_modules/jest-html-reporter", {
"pageTitle": "...",
"outputPath": "./docs/test/report/index.html",
"includeFailureMsg": true,
"sort": "titleAsc",
"dateFormat": "yyyy-mm-dd HH:MM:ss"
}]
]
};
๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
๊ทธ ๋ ์ด๊ฒ์ ์ฌํํ๋ ์๊ฐ์ ์ฐพ๋๋ก ๋ ธ๋ ฅํ๊ฒ ์ต๋๋ค. ๊ทธ๋๊น์ง ๋๋ ์๋์์ ๋ณผ ์ ์๋ฏ์ด ๋ด ๋ก๊ทธ๊ฐ ๊ฒฐ๊ณผ์ ์ํด ๋จนํ๋ ๊ฒ์ ๋ฐ๊ฒฌํ์ต๋๋ค. FAIL์ด ํ์๋๊ธฐ ์ ์ 2๊ฐ์ ๋ก๊ทธ๋ฅผ ๋ณผ ์ ์์ต๋๋ค. ๋ํ 2๊ฐ์ ๋ก๊ทธ๋ง ์ ๊ฑฐ๋๋ค๋ ์ ๋ ์ธ๊ธํ ๊ฐ์น๊ฐ ์์ต๋๋ค. ์๋ก ์๋์ 10๊ฐ์ ๋ก๊ทธ๋ฅผ ์ถ๊ฐํ๋ฉด 8๊ฐ๊ฐ ํ์๋ฉ๋๋ค. ์ข์ ์์์ธ ๊ฒ ๊ฐ์์ :)
@kresli ์ฌ๊ธฐ์ ์๋ ์ํ ํ์์ค๊ณผ ์๊ฐ ์ถ๋ ฅ์ ๋ฌด์์
๋๊น? ํ
์คํธ ์ค์ํธ๋ฅผ ์คํํ ๋ _RUN HARNESS test-harness/index.js_๊ฐ ํ์๋๊ณ ๋ชจ๋ ๊ฒ์ด ์คํ๋ ๋๊น์ง ์๋ฌด๊ฒ๋ ํ์๋์ง ์์ต๋๋ค. ๊ทธ๋ฐ ๋ค์ ๋งจ ๋์ ๋ด console.log ๋ฉ์์ง๊ฐ ํ์๋๊ณ _RUN HARNESS..._ ํ์ด _๋ก ๋ณ๊ฒฝ๋ฉ๋๋ค.
์ ๋ฐ์ดํธ: ๋ฌด์ํ์ญ์์ค. ๋ด ์ฝ๋์ ๋ฌธ์ ๋ก ํ๋ช ๋์์ต๋๋ค.
MacOS์ ๋ ธ๋ v12.16.1, jest 25.5.4, typescript 3.8.3์์ ์ฌ์ ํ ์ด ๋ฌธ์ ์ ์ง๋ฉดํ๊ณ ์์ต๋๋ค. --runInBand ์ฌ์ฉ, ์์ธํ ์ ๋ณด ๋นํ์ฑํ/ํ์ฑํ, --silent=true ์ฌ์ฉ์ ๋ํ ๊ถ์ฅ ์ฌํญ์ ์๋ํ์ง๋ง ๋์์ด ๋์ง ์์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
2๋ ๋์ ์ฝ์ ๋ก๊ทธ๊ฐ ์์๊ธฐ ๋๋ฌธ์ ๋ ๋์ ๊ฐ๋ฐ์๊ฐ ๋์์ต๋๋ค. Jest ํ ๊ฐ์ฌํฉ๋๋ค!