๐Ÿค ์€์ง€log ๐Ÿค

[CI/CD study] - 12. code coverage ( Jest ) ์„ค์น˜ ํ…Œ์ŠคํŠธ ๋ณธ๋ฌธ

๐Ÿ’š DevOps

[CI/CD study] - 12. code coverage ( Jest ) ์„ค์น˜ ํ…Œ์ŠคํŠธ

Eun_zii 2022. 10. 14. 23:49

 

code coverage ์ค‘ next, react์™€ ์—ฐ๊ด€์„ฑ์ด ๋†’์€ Jest๋ฅผ ์„ค์น˜ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

npm install --save-dev jest

 

Jest ์„ค์น˜

 

 

๊ทธ๋‹ค์Œ subtraction.js ์ด๋ผ๋Š” ํŒŒ์ผ ์ƒ์„ฑ

 

function subtraction(a, b) {
	return a - b;
}

module.exports = subtraction;

ํŒŒ์ผ์•ˆ์— ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ

 

 

๊ทธ ํ›„ subtraction.test.js ์ด๋ผ๋Š” ํŒŒ์ผ ์ƒ์„ฑ

 

const subtraction = require('./subtraction');
test('subtracts 4 - 2 to equal 2', () => {
	expect(subtraction(4, 2)).toBe(2);
});

์ฝ”๋“œ ์ž‘์„ฑ

 

{   
   "scripts": 
       {     
           "test": "jest"   
       } 
}

 

๊ทธ ๋‹ค์Œ package.json ํŒŒ์ผ๋กœ ๊ฐ€์„œ ์ฝ”๋“œ ์ถ”๊ฐ€

 

์œ„์™€ ๊ฐ™์ด ์ž‘์„ฑ

* "scripts" ์•ˆ์— ๋„ฃ์–ด์ฃผ๊ธฐ

 

 

โŒจ๏ธ npm run test

๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์ด PASS ๋ฌธ๊ตฌ๊ฐ€ ๋‚˜์˜จ๋‹ค๋ฉด

 

Jest ์„ค์น˜ ์™„๋ฃŒ โญ๏ธ

 

stage('Test') {
  steps {
    script {
     sh 'npm run test'
    }
  }
}

Jenkinsfile์— ์ฝ”๋“œ ์ถ”๊ฐ€

 

์ง€๊ธˆ ๊นŒ์ง€ ์ž˜ ๋”ฐ๋ผ ์˜ค์…จ๋‹ค๋ฉด ์ด๋Ÿฐ ๋ชจ์–‘์ด ๋‚˜์˜ต๋‹ˆ๋‹ค.

 

gitea์— push๋ฅผ ํ•ด์ฃผ๊ณ  Jenkins๋กœ ๋Œ์•„๊ฐ€๊ธฐ

 

sonarqube ๋’ค์— test๋ผ๋Š” ํ•ญ๋ชฉ์ด ์ƒ๊ธฐ๊ณ ,

๋นŒ๋“œ ์™„๋ฃŒ โญ๏ธ

 

 

 

โค๏ธ ๋„์›€์ฃผ์‹ ๋ถ„ : 

https://code00.tistory.com/

728x90

'๐Ÿ’š DevOps' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Front-end] CI/CD  (0) 2022.10.31
[CI/CD study] - 13. Docker-Compose ์™€ Nginx ์„ค์น˜  (0) 2022.10.19
[CI/CD study] - 11. NPM Build  (0) 2022.10.14
[CI/CD study] - 10. Jenkins์™€ Sonarqube ์—ฐ๋™ํ•˜๊ธฐ  (0) 2022.10.14
[CI/CD study] - 9. Jenkins File  (0) 2022.10.14