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
3 Answers
Reset to default 2You 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条)