javascript - How can we run jest unit tests along with npm start or npm build? - Stack Overflow

Each time we try to run Jest unit tests we have to run npm test. Is there any way with which I can run

Each time we try to run Jest unit tests we have to run npm test. Is there any way with which I can run these tests when I'm building my application (at time of npm start or npm build)

Each time we try to run Jest unit tests we have to run npm test. Is there any way with which I can run these tests when I'm building my application (at time of npm start or npm build)

Share Improve this question edited Nov 1, 2018 at 23:16 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Oct 11, 2018 at 8:23 AS1994AS1994 231 gold badge1 silver badge5 bronze badges 1
  • just use another terminal :) – Tu Nguyen Commented Oct 11, 2018 at 8:28
Add a ment  | 

3 Answers 3

Reset to default 2

You can bine multiple steps in package.json like this:

  "scripts": {
    "start": "sh start.sh",
    "test": "sh test.sh",
    "test_start": "npm test && npm start"
  }

while running your test, simply run

npm run test_start

This will ensure that your test is successful before it runs start.


Hope this helps!

Yes you can add the npm test step in your start mand in your package.json, like this for example:

"scripts": {
  "start": "npm run test && node server.js"
  "test": "jest"
}

I have these in my package.json and its really useful to have jest coverage will give you a detailed report on whether any of your files are missing tests.

"test": "jest --testPathPattern='/App/*'",
"test:coverage": "jest --coverage && open coverage/lcov-report/index.html || xdg-open coverage/lcov-report/index.html",
"test:updateSnapshot": "jest --updateSnapshot"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744393126a4572007.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信