-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Demo getting coverage for JavaScript code #2264
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following steps show how we can get an estimate of coverage for JavaScript (JS) code. Unfortunately it's not possible to do this easily due to the fact that we execute all the tests for JavaScript via Ruby code, in order to accommodate the Rails Asset Pipeline. Instrument ========== First, we need to manually instrument all the JS code in the app, so that it will log coverage stats when we run it. Note that we can't instrument the top-level application.js file, as this causes the test runner to go into an infinite loop (for some reason!). Hopefully we have very little JS code in this file, or it should be easy to move it elsewhere temporarily. ``` mv app/assets/javascripts{,.bak} npx istanbul instrument app/assets/javascripts.bak app/assets/javascripts mv app/assets/javascripts.bak/application.js app/assets/javascripts/ ``` Run tests ========= We need to run these in the browser, so that we can extract the coverage data later on. govuk-docker run -p 8888:8888 finder-frontend-lite bundle exec rake jasmine Now go to localhost:8888 and watch the tests run to completion. Dump stats ========== Run the following in your browser console, and manually copy the output into a JSON file e.g. "coverage/coverage.json". ``` JSON.stringify(window.__coverage__) ``` Generate report =============== Run the following to generate final report in "coverage/". ``` npx istanbul report --include coverage/coverage.json
benthorner
pushed a commit
to alphagov/collections
that referenced
this pull request
Oct 26, 2020
Follows the method in [1]. [1]: alphagov/finder-frontend#2264
benthorner
pushed a commit
to alphagov/frontend
that referenced
this pull request
Oct 26, 2020
Following the method in [1]. Note that I also had to preserve the original (non-code) content of "all.js" to get the tests to run. [1]: alphagov/finder-frontend#2264
benthorner
pushed a commit
to alphagov/content-publisher
that referenced
this pull request
Oct 26, 2020
Following the method in [1]. Note that I also had to rescue to the comment at the top of "reorderable-list.js" for the tests to all pass. [1]: alphagov/finder-frontend#2264
benthorner
pushed a commit
to alphagov/manuals-frontend
that referenced
this pull request
Oct 26, 2020
Following the method in [1]. [1]: alphagov/finder-frontend#2264
benthorner
pushed a commit
to alphagov/publisher
that referenced
this pull request
Oct 26, 2020
Following the method in [1]. [1]: alphagov/finder-frontend#2264
benthorner
pushed a commit
to alphagov/service-manual-frontend
that referenced
this pull request
Oct 26, 2020
Following the method in [1]. [1]: alphagov/finder-frontend#2264
benthorner
pushed a commit
to alphagov/service-manual-publisher
that referenced
this pull request
Oct 26, 2020
Following the method in [1]. [1]: alphagov/finder-frontend#2264
benthorner
pushed a commit
to alphagov/transition
that referenced
this pull request
Oct 26, 2020
Following the method in [1]. [1]: alphagov/finder-frontend#2264
This was referenced Oct 26, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The following steps show how we can get an estimate of coverage for
JavaScript (JS) code. Unfortunately it's not possible to do this
easily due to the fact that we execute all the tests for JavaScript
via Ruby code, in order to accommodate the Rails Asset Pipeline.
Instrument
First, we need to manually instrument all the JS code in the app,
so that it will log coverage stats when we run it.
Note that we can't instrument the top-level application.js file,
as this causes the test runner to go into an infinite loop (for
some reason!). Hopefully we have very little JS code in this file,
or it should be easy to move it elsewhere temporarily.
Run tests
We need to run these in the browser, so that we can extract the
coverage data later on.
Now go to localhost:8888 and watch the tests run to completion.
Dump stats
Run the following in your browser console, and manually copy the
output into a JSON file e.g. "coverage/coverage.json".
Generate report
Run the following to generate final report in "coverage/lcov-report/".