Skip to content
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

yarn and coverage with Istanbul #6746

Closed
jeremad opened this issue Nov 30, 2018 · 20 comments
Closed

yarn and coverage with Istanbul #6746

jeremad opened this issue Nov 30, 2018 · 20 comments
Assignees
Labels

Comments

@jeremad
Copy link

jeremad commented Nov 30, 2018

Using nyc (aka istanbul) and yarn with a version newer than 1.10.1 does not give me the coverage result.

package.json:

{
...
    "scripts": {
        "coverage": "nyc --reporter=lcov --reporter=text-summary yarn test"
    }
    "devDependencies": {
        "nyc": "13.1.0"
    }
...
}

With yarn:

$ yarn coverage
...
=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================

using nyc directly:

$ ./node_modules/.bin/nyc --reporter=lcov --reporter=text-summary yarn test
...
=============================== Coverage summary ===============================
Statements   : 85.01% ( 2689/3163 )
Branches     : 73.39% ( 979/1334 )
Functions    : 92.45% ( 722/781 )
Lines        : 85.14% ( 2612/3068 )
================================================================================

using npm (or changing package.json to use npm test instead of yarn test)

$ npm run coverage
...
=============================== Coverage summary ===============================
Statements   : 85.01% ( 2689/3163 )
Branches     : 73.39% ( 979/1334 )
Functions    : 92.45% ( 722/781 )
Lines        : 85.14% ( 2612/3068 )
================================================================================

I use nodejs 10.14 and ubuntu 18.04.
This looks like:
#6650
#6678
#6608

@ghost ghost assigned arcanis Nov 30, 2018
@ghost ghost added the triaged label Nov 30, 2018
@nadavye
Copy link

nadavye commented Nov 30, 2018

Watching..

shakeelmohamed pushed a commit to splunk/splunk-cloud-sdk-js that referenced this issue Dec 7, 2018
By downgrading to an older version of yarn, we can avoid
this bug
yarnpkg/yarn#6746
Until that issue is resolved, we'll use v1.9 of yarn
@shakeelmohamed
Copy link

Confirmed, downgraded to 10.9 and fixed this issue

shakeelmohamed pushed a commit to splunk/splunk-cloud-sdk-js that referenced this issue Dec 7, 2018
By downgrading to an older version of yarn, we can avoid
this bug
yarnpkg/yarn#6746
Until that issue is resolved, we'll use v10.9 of yarn
shakeelmohamed pushed a commit to splunk/splunk-cloud-sdk-js that referenced this issue Dec 7, 2018
By downgrading to an older version of yarn, we can avoid
this bug
yarnpkg/yarn#6746
Until that issue is resolved, we'll use v1.9 of yarn
@JackTiber
Copy link

Can confirm this is the case with Node 11.4.0 and yarn 1.12.3, nyc 13.1.0. Switched back to npm, and coverage report returned to expected output.

@arcanis
Copy link
Member

arcanis commented Dec 11, 2018

Will be fixed in the next release, by the end of the week (fixed in #6747)

@jeremad
Copy link
Author

jeremad commented Dec 12, 2018

Great, thanks.

@quentinvernot
Copy link

Btw, I tested 1.13.0 pre-release with nyc, and it works now!

@quentinvernot
Copy link

Alright, upon upgrading the real yarn on my machine, it doesn't work. Since I had 2 yarns running, I hardcoded the path in the package.json, like so:

{
...
    "scripts": {
        "coverage": "nyc --reporter=lcov --reporter=text-summary /home/quentin/.npm-packages/bin/yarn test"
    }
...
}

And it worked, but not for the reason I though. If I don't hardcode the path to yarn, even with 1.13.0, it doesn't report coverage with nyc. If I make nyc run which yarn, it gives me this:

$ yarn coverage
yarn run v1.13.0
$ nyc --reporter=lcov --reporter=text-summary which yarn
/tmp/yarn--1547824229222-0.5258100608719858/yarn

This /tmp/yarn--1547824229222-0.5258100608719858/yarn contains:

#!/bin/sh

exec "/usr/bin/node" "/usr/bin/yarn" "$@"

Which looks like the same problem that was linked by @jeremad. I just accidentally bypassed it by hardcoding the path to yarn.

jmbtutor added a commit to groupby/storefront that referenced this issue Jan 24, 2019
This pins the version of node to 11.6.0 and yarn 1.12.3. node 11.7.0 or
yarn 1.13.0 causes nyc to report 0% coverage.

istanbuljs/nyc#921
yarnpkg/yarn#6746

circleci/node:11.6.0
Digest: sha256:1a3a10a092bdfa3d92d48850818a5526b5770a58592156f6f8e6a5f7d946ac43
Created 2019-01-18T00:14:29.784667795Z
NODE_VERSION=11.6.0
YARN_VERSION=1.12.3
@sjl2
Copy link

sjl2 commented Jan 29, 2019

I'm still getting Unknown% ( 0/0 ) for converage when calling a yarn command with nyc.

I'm using yarn 1.13.0 and nyc v13.1.0.

Is there another idea for a fix? Has anyone found a good work-around?

The absolute path to yarn work-around might not work in my case due to this library being run by different developers on different environments where yarn lives on different paths.

@quentinvernot
Copy link

@sjl2 It looks like it has something to do with the new node version, it works in 11.6 and not in 11.7. -> istanbuljs/nyc#921 (comment)

Haven't looked into it myself yet, I'll see if I can make it work.

@sjl2
Copy link

sjl2 commented Feb 1, 2019

Interesting. Well, I can confirm it's also occurring on node 8.10.0 as well. Unfortunately, upgrading Node (besides minor versions) will not be an option because this is for an AWS Lambda service.

@clphillips
Copy link

Confirmed issue on node 8.11.1 as well, so doesn't appear to be node related, especially considering npm can run it fine.

@AnanyaJha
Copy link

I'm seeing the same issue in npm as well FWIW

@chrisdolendo
Copy link

same. yarn + nyc not showing coverage :(

chrisdolendo added a commit to SFDigitalServices/sf-dahlia-lap that referenced this issue Feb 26, 2019
- yarn + istanbul turns out do not work well together: yarnpkg/yarn#6746
@kilianc
Copy link

kilianc commented Mar 12, 2019

Same over here! What's the workaround other than calling nyc npm test

bkaney added a commit to Vermonster/fhir-kit-client that referenced this issue Jun 24, 2019
vstrateman added a commit to Vermonster/fhir-kit-client that referenced this issue Jul 16, 2019
vstrateman added a commit to Vermonster/fhir-kit-client that referenced this issue Jul 16, 2019
jeremad pushed a commit to TankerHQ/sdk-js that referenced this issue Aug 2, 2019
Add some Node configurations (10 & 12 on both mac & linux)
Use a workaround to have a working coverage command
yarnpkg/yarn#6746
jeremad pushed a commit to TankerHQ/sdk-js that referenced this issue Aug 2, 2019
Add some Node configurations (10 & 12 on both mac & linux)
Use a workaround to have a working coverage command
yarnpkg/yarn#6746
jeremad pushed a commit to TankerHQ/sdk-js that referenced this issue Aug 2, 2019
Add some Node configurations (10 & 12 on both mac & linux)
Use a workaround to have a working coverage command
yarnpkg/yarn#6746
jeremad pushed a commit to TankerHQ/sdk-js that referenced this issue Aug 2, 2019
Add some Node configurations (10 & 12 on both mac & linux)
Use a workaround to have a working coverage command
yarnpkg/yarn#6746
CaptainAchab pushed a commit to TankerHQ/sdk-js that referenced this issue Oct 3, 2019
I have lost hope that yarnpkg/yarn#6746 will
ever be fixed
@dylanlan
Copy link

dylanlan commented Nov 4, 2019

Are there any known workarounds for this issue, besides using npm?
I seem to be running into this issue with yarn 1.19.1, node 8.11.4, and nyc 14.1.1
For me it seems to just be outputting 0% coverage (not Unknown%), but npm still outputs the expected amount.

@narwajea
Copy link

Same here with yarn 1.19.1, node 12.3.1 and nyc 14.1.1.

nyc yarn mocha ... leads to 0% coverage on all files.
nyc npm run mocha ... leads to fine coverage results.

@coreyfarrell
Copy link

I've seen what appears to be an incompatibility between yarn and spawn-wrap. To everyone having this issue please test nyc@next which by default uses a different method of wrapping child processes. Note that this updated version requires node.js 8 and is a semver-major release, so please check the release notes posted to istanbuljs/nyc#1104 (comment). If your project depends on babel-plugin-istanbul or other istanbul* modules it is important that you update all to the next version, I've seen issues when testers accidentally mixed latest and next libraries.

The hope is for nyc and related modules to be out of pre-release soon but this is a very complex module so I'm being cautious.

@narwajea
Copy link

@coreyfarrell it works with nyc@next (currently nyc@15.0.0-beta.1).

@Jack-Barry
Copy link

Was banging my head against the wall with this in Yarn 1.21.0, upgraded to nyc@next and it's working 👍🏼 Great work whoever fixed this!

@jeremad
Copy link
Author

jeremad commented Feb 20, 2020

fixed with nyc 15.0.0

@jeremad jeremad closed this as completed Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests