ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • TIL | Mar 30(Wed), 2022
    Developer blah blah/TIL _ WIL 2022. 3. 31. 00:18

     

    ๐Ÿ‘‰TODAY

    1. 07:30 ๊ธฐ์ƒ

    2. ์ด๋ฒˆ ์Šคํ”„๋ฆฐํŠธ์˜ ์ฃผ์š” task ์ค‘ ํ•˜๋‚˜์ธ test code ์ž‘์„ฑ

    3. cron ๊ด€๋ จ ์ฝ”๋“œ ์ธ์ˆ˜์ธ๊ณ„

     

     

    ๐Ÿ“ŒTOMORROW

    1. ์ด๋ฒˆ์ฃผ ๊ธˆ์š”์ผ์— ํšŒ๊ณ  ๋ฐ ์ฐจ์ฃผ๋ถ€ํ„ฐ ์ƒˆ๋กœ์šด ์Šคํ”„๋ฆฐํŠธ๊ฐ€ ์‹œ์ž‘๋˜๋ฏ€๋กœ ์ง€๋‚œ์ฃผ๋ถ€ํ„ฐ ํ–ˆ๋˜ ๊ฒƒ ์ •๋ฆฌํ•ด ๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Œ

    2. cron ์ฝ”๋“œ ์ˆ™์ง€ ๋ฐ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ๋ณด์ถฉํ•ด๋„ ์ข‹์„๋“ฏ

     

     

    ๐Ÿ”จWhat I Learned?

    ๐Ÿ“š

    1) Jest ์…‹ํŒ… ๋ฐ ์‚ฌ์šฉ๋ฒ•(mock data/function ์‚ฌ์šฉ ๋ฐ ์ƒํ™ฉ์— ๋งž๋Š” matcher ์ ์šฉ)

    ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์กฐ๊ฑด ๋˜๋Š” ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์„ค์ •ํ•˜๊ณ , ํ•ด๋‹น ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋์„ ๋•Œ์˜ ๊ฒฐ๊ณผ๊ฐ€ ๊ธฐ๋Œ€ํ•œ ๊ฒฐ๊ณผ์™€ ๋งž๋Š”์ง€ ํ™•์ธํ•˜๋ฉด ํ…Œ์ŠคํŠธํ•˜๋ฉด ๋œ๋‹ค.

    ๊ทธ ๊ณผ์ •์—์„œ ํ…Œ์ŠคํŠธ์˜ ์กฐ๊ฑด์ด ์ฐธ/๊ฑฐ์ง“, ๋‹จ์ˆœ ์ผ์น˜, ์ˆซ์ž ๋น„๊ต ๋“ฑ์ด ๋  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋ฅผ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ matcher์ด๋‹ค.

    ๊ทธ ์ค‘ toBe(), toEqual()์ด ์ฃผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ๊ฒƒ ๊ฐ™๊ณ  toBeNull()๊ณผ ๊ฐ™์ด null์ด return ๋˜๋Š” ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ํ™•์ธ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

     

    ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด์•ผํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ๋‚˜๋ฆ„๋Œ€๋กœ ์‹œ๋‚˜๋ฆฌ์˜ค/์ผ€์ด์Šค๋ฅผ ์ž‘์„ฑํ•ด ๋ณด์•˜๋‹ค.

    ๊ทธ๋ฆฌ๊ณ  ๊ฐ ํ…Œ์ŠคํŠธ๋งˆ๋‹ค ์–ด๋–ค์‹์œผ๋กœ ๊ตฌ์„ฑํ•ด์•ผํ•˜๋Š”์ง€(mock data ๋˜๋Š” function์ด ํ•„์š”ํ•œ์ง€, ์–ด๋–ค matcher๋ฅผ ์จ์•ผํ•˜๋Š”์ง€ ๋“ฑ) ์ƒ๊ฐํ•˜๊ณ  ํ•™์Šตํ–ˆ๋‹ค. ์‚ฌ์‹ค ์‚ฌ์ „์— ํ•™์Šต์„ ํ•œ๋‹ค๊ณ  ํ•ด๋„ ์‹ค์ œ๋กœ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์งœ๊ณ  ๋Œ๋ ค๋ณด๋ฉด์„œ ๋‚˜์˜ค๋Š” ์—๋Ÿฌ๋“ค์„ ๊ฐ€์ง€๊ณ  ๋‹ค์‹œ ๋ฌดํ•œ ๊ตฌ๊ธ€๋ง์„ ํ•ด์•ผํ•˜๊ธฐ์—, ๊ธฐ๋ณธ ์…‹ํŒ…๊ณผ ์–ด๋–ค์‹์œผ๋กœ ๋Œ์•„๊ฐ€๋Š”์ง€๋งŒ ์•Œ์•„๋‘๋ฉด ๋  ๊ฒƒ ๊ฐ™๋‹ค.

     

    Anyway,

    ๋‚ด๊ฐ€ ์ •ํ•œ ์ฒซ๋ฒˆ์งธ๋Š” ํ…Œ์ŠคํŠธ ์‹œ๋‚˜๋ฆฌ์˜ค๋Š” 'getSearch()๋ผ๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ, ํ•ด๋‹น ํ•จ์ˆ˜๊ฐ€ ์ ์–ด๋„ 100๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์™€์•ผํ•˜๋Š”๋ฐ ์ด๋ฅผ ์ž˜ ๊ฐ€์ง€๊ณ  ์˜ค๋Š”์ง€' ํ…Œ์ŠคํŠธํ•ด์•ผํ–ˆ๋‹ค.

    ์ฒ˜์Œ์—๋Š” ๋”ฑ 100๊ฐœ๋งŒ ๊ฐ€์ ธ์˜ค๋Š”์ค„ ์•Œ์•˜๋Š”๋ฐ, ํ•ด๋‹น ํ•จ์ˆ˜๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” api์—์„œ ํŠน์ • ๊ฐ’์˜ ํƒ€์ž…์ด string๊ณผ numberํƒ€์ž…์œผ๋กœ ๋˜์–ด์žˆ์–ด์„œ 100๊ฐœ ์ด์ƒ์ด ๋‚˜์˜ค๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์—ˆ๋‹ค. 

    ๊ทธ๋ž˜์„œ ์ฒ˜์Œ์—๋Š” expect(data).toHaveLength(100) ๊ณผ ๊ฐ™์ด 'ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ ํ–ˆ์„ ๋•Œ, data๊ฐ€ 100๊ฐœ์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ๋‚˜์˜จ๋‹ค.'๋ผ๋Š” ์‹์œผ๋กœ ํ–ˆ๋‹ค๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ๋„ ์žˆ์–ด์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ–ˆ๋‹ค.

    ์‚ฌ์‹ค Object ํ˜•์‹์œผ๋กœ ์˜ค๋Š” data์˜ length๋ฅผ ํ•œ ๋ฒˆ์— ํ™•์ธํ•˜๋Š” matcher๊ฐ€ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์„œ ์ฐพ์•„๋ณด๋‹ค๊ฐ€ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ฒ€์ฆํ•œ ์ฝ”๋“œ๊ฐ€ ์žˆ์–ด์„œ ๊ฐ€์ ธ์™”๋‹ค. 

    => ๋ฐฐ์—ด์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ ๊ฑฐ๊ธฐ์— data๋ฅผ ๋„ฃ์–ด์ฃผ๊ณ  expect ๋ถ€๋ถ„์—์„œ length๋กœ ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์‰ฝ๊ณ  ๊ฐ„๋‹จํ–ˆ๋Š”๋ฐ, matcher์—๋งŒ ๊ฝ‚ํ˜€์„œ ๋‹ค๋ฅธ ๊ณณ์„ ๋‘˜๋Ÿฌ๋ณด์ง€ ๋ชปํ–ˆ๋‹ค :(

     

    https://www.newthings.co/blog/structuring-tests-using-given-when-then/

     

    Structuring tests using Given-When-Then

    Systematic structure for unit, integration and end-to-end tests

    www.newthings.co

     

    describe('GIVEN an empty array', () => {
        const array = new CustomArray();
    
        describe('WHEN an item is pushed', () => {
            array.push("item"); // ๋ฐฐ์—ด์— ๋‹ด์Œ
    
            test('THEN the length of the array is one', () => {
                expect(array.length).toBe(1);
            });
        });
    });

     

     

    ์•„๋ž˜ ์‚ฌ์ดํŠธ์—์„œ ๊ตญ๋ฌธ์œผ๋กœ ์ผ๋ถ€ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค.

    https://mulder21c.github.io/jest/docs/en/next/using-matchers

     

    Jest · ๐Ÿƒ Delightful JavaScript Testing

    ๐Ÿƒ Delightful JavaScript Testing

    mulder21c.github.io

     

    ์•„๋ž˜ ์‚ฌ์ดํŠธ๋Š” ์˜๋ฌธ์œผ๋กœ ์ž‘์„ฑ๋œ ๊ณต์‹๋ฌธ์„œ์ด๋‹ค.

    https://jestjs.io/docs/expect#tohavereturned

     

    Expect · Jest

    When you're writing tests, you often need to check that values meet certain conditions. expect gives you access to a number of "matchers" that let you validate different things.

    jestjs.io

     

     

    2)  ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ์ฒด ์†์„ฑ: writable, enumerable, configurable + value

    ์ด ๋ถ€๋ถ„์€ MDN ๋ฌธ์„œ๋ฅผ ๋ณด๋‹ค๊ฐ€ 'use strict'์— object.defindProperty(), writable ์ด ๋‚˜์™€์„œ ๋”ฐ๋กœ ํฌ์ŠคํŒ…ํ•˜๋ ค๊ณ  ๋นผ๋’€๋‹ค.

    ๋ธ”๋กœ๊ทธ ๊ธ€์„ ๋ณด๋ฉด์„œ console.log ๋กœ ๋ช‡๊ฐœ ํ…Œ์ŠคํŠธ๋งŒ ํ•ด๋ดค๋‹ค.

     

    https://im-developer.tistory.com/140

     

    [JS/Object] ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ, ๊ฐ์ฒด์˜ ํ”„๋กœํผํ‹ฐ(Property)์— ๋Œ€ํ•˜์—ฌ (Object.defineProperty()์™€ getter, setter์‚ฌ์šฉ

    Object ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ Object, ์ฆ‰ ๊ฐ์ฒด๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€์˜ ์ž๋ฃŒ(Data)๋“ค๊ณผ ํ•จ์ˆ˜(Function)๋“ค์˜ ์ง‘ํ•ฉ์ด๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” ์›์‹œ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ธ Number, String, Boolean, Null, Undefined๋ฅผ ์ œ์™ธํ•œ ๋ชจ๋“  ๊ฒƒ๋“ค์„ ๋‹ค..

    im-developer.tistory.com

     

    https://developer-talk.tistory.com/277

     

    [JavaScript]๊ฐ์ฒด ์†์„ฑ(writable, enumerable, configurable)

    ์†์„ฑ์˜ ๋ณธ์งˆ์ ์ธ ์†์„ฑ ์„ค๋ช…์ž JavaScript์˜ ๊ฐ์ฒด๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด : ์Œ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ์กด์žฌ์ž…๋‹ˆ๋‹ค. const userInfo = { name: 'Kang JaeSeong', age: 30, address: 'Busan' } name์ด๋ผ๋Š” key๋Š” 'Kang JaeSeong' valu..

    developer-talk.tistory.com

     

     

    ๐Ÿง™‍โ™‚๏ธReivew

    ์ง„์งœ ์ •์‹ ์—†์ด ์ฒซ๋ฒˆ์งธ ์Šคํ”„๋ฆฐํŠธ๊ฐ€ ์ง€๋‚˜๊ฐ”๋‹ค. ์ž…์‚ฌ ๋‹น์ผ์— ์ฃผ์–ด์ง„ ์—…๋ฌด ๊ฒธ ๊ณผ์ œ๊ฐ€ (๋‚˜ํ•œํ…Œ๋Š”)์–ด๋ ค์›Œ์„œ ์ขŒ์ ˆํ–ˆ์—ˆ๋Š”๋ฐ, ์ด๋ฒˆ ์Šคํ”„๋ฆฐํŠธ ๋•Œ ์ธ์ˆ˜์ธ๊ณ„ ๋ฐ›์€ ์ฝ”๋“œ๋Š” ๊ณ„์† ๋ณด๋‹ค ๋ณด๋‹ˆ๊นŒ ๋ˆˆ์— ์ต์€ ๊ฒƒ ๊ฐ™๋‹ค. ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํ‡ด๊ทผํ•˜๊ณ ๋„ ์ง‘์—์„œ 2-3์‹œ๊ฐ„์”ฉ ๋ณด๊ณ ... ๊ฑฐ์˜ ํ•˜๋ฃจ์ข…์ผ ๋ณด๋‹ˆ๊นŒ ์ต์ˆ™ํ•ด์ ธ์•ผ์ง€ ๋ญ..

    ์–ด๋””์„œ ์ด๋Ÿฐ ๋Œ“๊ธ€์„ ๋ดค๋‹ค. -> '์‹ ์ž…์ด 120% ํ•˜๋ ค๋Š” ๊ฒƒ ๋งŒํผ ๋ฌด์„œ์šด ์ผ์ด ์—†๋‹ค'๋ผ๊ณ  

    ์‹œ๊ฐ„์ด ์ง€๋‚  ์ˆ˜๋ก ๋ชจ๋ฅด๋Š”๊ฒŒ ๋„ˆ๋ฌด ๋งŽ์•„์„œ ์–ด๋””์„œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์•ผํ• ์ง€๋„ ๋ชจ๋ฅด๊ฒ ๋‹ค. ์‚ฌ์‹ค ๊ณ„์† ๋ญ”๊ฐ€๋ฅผ ํ•˜๊ณ  ์žˆ๊ธฐ๋Š” ํ–ˆ๋Š”๋ฐ ๋ง์ด๋‹ค.

    ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์— ๋Œ€ํ•ด์„œ๋„ ๋ชจ๋ฅด๋Š”๊ฒŒ ๋งŽ์•˜๊ณ , ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ + ์ฒ˜์Œํ•ด๋ณด๋Š” Nest.js๋„ ์•„์ง์€ ๋‚ฏ์„ค๊ณ (๊ทธ๋ž˜๋„ ์Šคํ”„๋ง ํ•ด๋ด์„œ ์ฌ๊ธˆ ์ต์ˆ™), ๋ฐ•๋ฌผ๊ด€์— ๊ธฐ์ฆ๋˜์–ด์•ผํ•˜๋Š” 2012๋…„ ๋งฅ๋ถ์œผ๋กœ๋Š” ์ธํ„ฐ๋„ท ์„œํ•‘ํ•˜๋Š๋ผ ์œˆ๋„์šฐ ๋žฉํƒ‘์œผ๋กœ ๊ฐœ๋ฐœ์„ ํ–ˆ๊ธฐ์— macOS๋กœ ๊ฐœ๋ฐœํ•˜๋Š” ๊ฒƒ๋„ ์•„์ง ๋‚ฏ๊ฐ€๋ฆผ.

    ๋„คํŠธ์›Œํฌ, ๋ฆฌ๋ˆ…์Šค ํ™˜๊ฒฝ, ์›น ๋ธŒ๋ผ์šฐ์ €, ๋ช…๋ น์–ด๋กœ ๋ฒ„์ „๊ด€๋ฆฌ(git), ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์งœ๊ธฐ, DB ๋“ฑ ๊ณต๋ถ€ํ• ๊ฑฐ ๋งŽ์•„์„œ ์ •๋ง ์ข‹๋‹ค.

     

    ๋„คํŠธ์›Œํฌ๋‚˜ ๋ฆฌ๋ˆ…์Šค ๊ด€๋ จํ•ด์„œ ๋‘˜ ์ค‘ ํ•˜๋‚˜๋Š” ์ฃผ๋ง์— ํ•™์› ๋‹ค๋‹ˆ๋ฉฐ ๋ฐฐ์šธ ์ƒ๊ฐ์ธ๋ฐ, makmakํ•˜๋‹ค :/)

    ์˜ค๋Š˜๋กœ์„œ ๋”ฑ 2์ฃผ๋๋Š”๋ฐ, ๊ทธ๋ž˜๋„ ์ด์ œ๋Š” ์ƒˆ๋กœ์šด ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ์–ด๋–ป๊ฒŒ ๋Œ์•„๊ฐ€๋Š”์ง€ ๋”ฑ ์•Œ ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค!

     

     

    'Developer blah blah > TIL _ WIL' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

    WIL | Apr 4 - Apr 10, 2022  (0) 2022.04.10
    WIL | Mar 28 - Apr 3, 2022  (0) 2022.04.03
    WIL | Mar 21- 27, 2022  (0) 2022.03.28
    TIL | Mar 23(WED), 2022  (0) 2022.03.24
    TIL | Mar 21(MON), 2022  (0) 2022.03.22

    ๋Œ“๊ธ€

Designed by Tistory.