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
Add JS code coverage option to front end tests #3036
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3036 +/- ##
=======================================
Coverage 83.07% 83.07%
=======================================
Files 246 246
Lines 15429 15429
Branches 2886 2886
=======================================
+ Hits 12817 12818 +1
Misses 1695 1695
+ Partials 917 916 -1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect executable name on Mac, although that might be me installing things incorrectly.
Also worth noting that I had to upgrade my, somewhat old, cypress for this to work. I was on 3.2.
bin/browser-tests
Outdated
|
||
# Get a path for nyc | ||
my $nyc = 'nyc'; | ||
$nyc = abs_path("$wsl/../../../\@cypress/code-coverage/node_modules/nyc/bin/nyc.js") if $wsl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this gets installed as nyc.js
on my mac.
I also had to add the location to the path which was /Users/$username/node_modules/nyc/bin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be "nyc" in your /Users/$username/node_modules/.bin
I think?
Did you install "nyc" yourself or only the code-coverage package?
On mine it is in node_modules/@cypress/code-coverage/node_modules/.bin/nyc
and corresponding node_modules/@cypress/code-coverage/node_modules/nyc/bin/nyc.js
So if I know where cypress is installed I could do the relative path from that which should be , but do I know that with any certainty? Hmm.../../../@cypress/code-coverage/node_modules/.bin/nyc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, of course you have a hidden bin directory. That totally makes sense.
Anyway, it is indeed in /Users/$username/node_modules/.bin
so adding that to my path works fine. It's not in node_modules/@cypress/code-coverage/node_modules/.bin/
though.
I've uninistalled nyc and the code coverage module and then re-installed the code-coverage module to get this as the end result FWIW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, just for the record, here's the final skinny as I understand it.
Facts:
- All I want is a path to run nyc.
- The code already assumes (for non-WSL) cypress is on PATH, and you specify a path to cypress with WSL.
Where is nyc installed:
- If you install cypress and code-coverage with npm locally (no
-g
flag), with nothing else installed, then npm will install them in any node_modules directory it finds, up to your homedir. In that node_modules directory, cypress and nyc can be run fromnode_modules/.bin
. - However, if e.g. you already had an older version of nyc manually installed, then that version would be the one in
node_modules/.bin
and the code-coverage packaged version would be in@cypress/code-coverage/node_modules/.bin
! - If you install cypress and code-coverage with npm globally (with
-g
flag), then npm will install them in your "prefix" (probably /usr/local/lib/node_modules or AppData\npm\node_modules on Windows, or ~/.npm/node_modules for me because I have set that somewhere). It creates top-level executables in /usr/local/bin on Unix, or AppData\npm\ directly on Windows - so "nyc" doesn't get a executable as it's a dependency, all I have there is cypress. nyc can be found only as nyc.js in@cypress/code-coverage/node_modules/nyc/bin
Possible locations therefore of nyc or nyc.js:
$(npm prefix)/node_modules/@cypress/code-coverage/node_modules/.bin/nyc
$(npm prefix)/node_modules/.bin/nyc
$(npm prefix -g)/node_modules/@cypress/code-coverage/node_modules/.bin/nyc
$(npm prefix -g)/[bin/]nyc
(if you manually install nyc globally)
Possible locations of cypress, which you must have added to your path to get this to run previously anyway (or be using WSL like me):
$(npm prefix)/node_modules/.bin/cypress
$(npm prefix -g)/[bin/]cypress
I think easiest would be to ask the user to install nyc manually (globally or not), and then assume the right dir is on their PATH and then this script doesn't have to care.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I think if you are running a code coverage tool you should be tech savy enough to include node modules in your path.
Leaving a note here that I can‘t seem to get this working on my Mac.
That’s with
And the following versions of everything:
@dracos notes that our tests might not work with Cypress 4 yet, so I should probably downgrade to |
You need to install the @cypress/code-coverage package alongside cypress.
This PR adds a way to view code coverage of the JS we use locally if you'd like to do that. Works for me with WSL on Windows, asked for two reviews as I know e.g. Zarino uses Vagrant. Produces output like the screenshot.