How to do Coverage exports for vscode extensions

大兔子大兔子 提交于 2021-02-04 15:26:37

问题


I have seen a lot of tutorials how to make vscode extensions. Like:

https://code.visualstudio.com/docs/extensions/testing-extensions

And there is many tutorials how to do coverage exports, there many ways how to do it, but I didn't seen good examples which would follow the examples from their docs and work with vscode extensions (they need the extensionHost instead of nodejs).

I have all the tests written in the mocha which is bundled in the vscode as proposed by their documents.

I tried to experiment and I'm stuck, are there any hints or directions where I could continue and get my process working again?


回答1:


The answer which worked is in the comments to my original question. But to simplify and boil down what had to be done, and what steps I did personally. Not all steps are really essential and required, but these steps made it pretty convient:

  • installed istanbul, istanbul-coveralls, gulp, gulp-json-editor, coveralls to my package as the DEV dependencies
  • included the MS supplied istanbul test runner for vscode extension testing into my tests
  • modified the tests to run an istanbul runner instead of mocha runner directly (the tests itself could stay as they are).
  • attached reference to the istanbul runner now I had to read the coverconfig.json to know how to do the coverage itself (what parts to ignore, where is source, where to output results, what formats the results should be etc...).
  • added coverage to gitignore and to vscode project as so they will not annoy me in the UI and will not polute the repo.
  • added few visual studio launchers/tasks to make it easier for me to trigger them from the UI
  • installed vscode plugin to display the coverage in the gutters: https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters and then added to my project settings the "lcov.path": [ "coverage/lcov.info" ] (or whatever location you will have the line coverage) so the plugin can read and show the coverage directly in the UI.
  • setup gulp to delete old coverage results and start new ones on each run
  • added npm scripts for regular tests and for the coverage variant
  • changed travis steps so the coverage variant is running now instead of the generic non-coverage one. Added script step so the coveralls module is run and broadcasts the results from the coverage/lcov.info to the https://coveralls.io/ website. (i think signing in and doing the first-time setup is required to make it work on their website)

Now on each commit travis will do the work by itself and I can use coveralls banner inside my readme to give quick glipse how well is my coverage. And you can use gulp to watch it for changes and build/test locally and have fast feedback in the UI what lines were covered by your tests.

The setup is similar to the listed links:

https://github.com/Microsoft/vscode-mssql

https://github.com/kenhowardpdx/vscode-gist/pull/10



来源:https://stackoverflow.com/questions/44910485/how-to-do-coverage-exports-for-vscode-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!