ํ ์คํธ ๋ฐ/๋๋ ๋ชจ์ํ๋ ค๋ ๋ชจ๋์ ์ผ๋ถ ์ ์ญ ๋ณ์๋ฅผ ์ฌ์ฉํฉ๋๋ค.
์๋ฅผ ๋ค์ด, ๋ชจ๋์ ์์ค ์ฝ๋๋ ๋ณ์ session
์ ๋ํ ์ฐธ์กฐ๋ฅผ ๋ง๋ญ๋๋ค. ์ด ๋ณ์๋ ์ด๋์๋ ์ ์๋์ด ์์ง ์์ง๋ง ๋ฐํ์์๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
globals.js
๋ชจ๋์ ๊ณ ๋ คํ์ญ์์ค.
let globals = {
contextName: "DATA_PIPELINE",
reportContext: "report",
session: session
};
module.exports = globals;
session
์ ์ด ํ์ผ์ ์ ์๋์ด ์์ง ์์ง๋ง ๋ฐํ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๊ทธ๊ฒ์ ํ๊ฒฝ์ ์ ์ญ ๋ณ์์
๋๋ค(๋ด ํต์ ํ์ ์์ง ์์).
๊ฐ์ง ํ์ด๋จธ๋ฅผ ์ฌ์ฉํ์ฌ setTimeout๊ณผ ๊ฐ์ ์ ์ญ ํจ์ ๊ตฌํ์ ๋์ฒดํ ์ ์์์ต๋๋ค. ์ด๊ฒ์ ์ ์ญ ํจ์/๊ฐ์ฒด์ ์ด๋ป๊ฒ ์ ์ฉํ ์ ์์ต๋๊น?
์๋ง๋ sinon.replace(object, prop, replacement)
์ด(๊ฐ) ์ฐพ๊ณ ์๋ ๊ฒ์
๋๊น?
https://sinonjs.org/releases/v7.2.4/sandbox/#sandboxreplaceobject -property-replacement
์ฐ๋ฆฌ๋ GitHub ๋ฌธ์ ๋ชฉ๋ก์ ๊น๋ํ๊ฒ ์ ์งํ๊ณ ๋ฒ๊ทธ์ ๊ธฐ๋ฅ ํ ๋ก ์ ์ง์คํ๋ ค๊ณ ๋
ธ๋ ฅํ๊ณ ์์ต๋๋ค. ์ด ํฐ์ผ์ ์ฌ์ฉ ์ง๋ฌธ์ฒ๋ผ ๋ณด์
๋๋ค. ์ด๋ฅผ StackOverflow ์ ๊ฒ์ํ๊ณ sinon
ํ๊ทธ๋ฅผ ์ง์ ํ์ฌ ๋ ํฐ ์ปค๋ฎค๋ํฐ์์ ๊ทํ์ ์ง๋ฌธ์ ๋ต๋ณํ ์ ์๋๋ก ํ์ญ์์ค.
Node.js์์ ๋ค์๊ณผ ๊ฐ์ด ํ ์ ์์ต๋๋ค.
global.session = sinon.stub();
// Proceed to import the modules that use the session global and run the tests