-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
coverage 0% with yarn v2 P'n'P #1204
Comments
I've seen reports of yarn apparently interfering with nyc, specifically it seems to break |
now it does throw an error internal/modules/cjs/loader.js:783 Error: Cannot find module '/Users/al/Projects/coverage-problem/.yarn/cache/node-preload-npm-0.1.3-55fd0dfa1d.zip/node_modules/node-preload/node-preload.js'
Required package: lcov (via "lcov")
(node:69196) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) |
This looks like yarn pnp is creating a broken install or otherwise changing the node.js runtime environment in a way nyc cannot deal with. The error at |
@coreyfarrell |
Failure to load As far as the other error where it fails to load
yarn has created a system which operates under slightly different (at least somewhat incompatible) rules. Many projects are very simple and can deal with changes to edge cases. Simple is not a valid description of nyc. |
The load fails in the 3.0.0-alpha.2 (but not in latest) because I'd suggest to add a check that
Which is actually correct: |
@arcanis thanks for looking at this and commenting, I'm moving forward with both of your suggestions in istanbul-reports. Any thoughts on the |
Hm ... I suspect that |
const result = require('child_process').execFileSync(
process.execPath,
[require.resolve('./fixtures/spawn.js')],
{
env: {NODE_OPTIONS: `--require "${require.resolve('../register.js')}"`}
}
); The child process will collect coverage for Edit: |
I see - in this case, I'm afraid NYC must have a special code to support PnP. It shouldn't be too long, the following would probably work: if (process.versions.pnp)
nodeOptionRequireSelf = `--require ${require.resolve('pnpapi')} ${nodeOptionRequireSelf}`; This way you'd bootstrap PnP before loading NYC. Does that sound right? |
Will If pnpapi only works in Node.js 12 then the path passed to require can be quoted with double-quotes and backslashes escaped. For node.js 8-11 it's more difficult as it's impossible to pass a path with a space to This difference before/after node.js 12 is a big part of why |
The
Yep I know, it's actually my PR which implemented the space support 😄 I think a reasonable approach might be to simply throw an exception on Node < 12 if the path to Fwiw Yarn currently injects the hook using the path, regardless of whether it contains spaces or not. I'll fix that to follow my own suggestion and throw instead on Node < 12, but since noone reported a problem so far I'd expect this use case to be somewhat fringe. |
Another option to deal with node < 12 could be to put your file into a subdirectory. If If I understand correctly spawning a subprocess with a cleared A specific example I can think of is if someone installed nyc 15 globally and ran Another edge case to consider, what happens if I've posted cfware/node-preload#3 for the yarn pnp changes. FWIW I testing locally using yarn v2 with a devDependency for nyc to install from |
Additional context, my local test using PnP with |
I would prefer not to move the file. Some tools might already assume PnP environments if this specific file exists, and better keep this assumption working (we could add an indirection, but I'm not sure it's worth it - it causes problems when watching the file etc).
It already kinda happens - when you run While I haven't wrote explicit code to handle that, it definitely seems to work - I think it's because the two hooks are loaded, but only the last one "wins".
Can you run:
And wait for it to run for at least one minute? What happens is that Yarn is cloning the repository and running Note that I'm going in 🌴🍹 for a week tomorrow. I'll make sure to check back as soon as I come back! |
I tried installing your branch:
I checked in /tmp/yarnpkg-sources, the remote URL for origin is https://github.com/yarnpkg/berry.git. Any suggestion? |
Oh right, cloning from PRs is pretty recent. Try this:
It should do the trick. |
Branch 539 allows it to install, unfortunately the test fails. I'm going to post my test repository in a minute.
|
I've posted a minimum demonstration of the issue at https://github.com/coreyfarrell/yarn-pnp. |
Perfect! I've just opened yarnpkg/berry#542 to fix the problem you've witnessed, it will be merged soonish. Running I think we'll also add an E2E test when I get some time, to track potential regressions 🙂 |
When I get a chance I'll add I do still have concerns about .pnp.js
packages/pkg1/.pnp.js Assume BTW you mentioned that you were planning on having node.js < 12 just throw if |
Yep, that's how I see things. When using workspaces, you'd only have a single That said the scenario you describe might cause problems when using a globally-installed To be fair, the NODE_OPTIONS preload is admittedly a bit clunky. There are some discussions in the Node Modules WG to instead be able to define loaders through the |
Would globally installed |
PnP is the default linking algorithm we're switching to in the v2, correct (although we have some plans to eventually support legacy node_modules installs, maybe even in time for the stable release). It's not so much about what features the individual projects use, but rather about the guarantees that the package manager can provide to the user. Given that PnP has the same runtime interface characteristics as traditional node_modules installs but with better speed and safety characteristics, that's definitely where we'll focus our efforts in the future. |
I think |
I have run my tests with |
it might be fixing your tests, but it does not fix the tests linked to in this issue |
@thealjey Pointing your package.json nyc version to |
@coreyfarrell I had to remove and reinstall everything, including Yarn v2 itself |
I think this issue can be closed, in fact |
https://github.com/thealjey/coverage-problem
git checkout master
yarn
yarn test
total: 1
passing: 1
duration: 2.1s
✨ Done in 2.78s.
git checkout yarnv2
yarn
yarn test
ERROR: Coverage for lines (0%) does not meet global threshold (100%)
ERROR: Coverage for functions (0%) does not meet global threshold (100%)
ERROR: Coverage for statements (0%) does not meet global threshold (100%)
total: 1
passing: 1
duration: 1.7s
The only difference between the branches is yarn version.
I was only forced for switch to v2 because Husky does not support v1 P'n'P (plug and play).
Also, yarn itself recommends using the v2 version of P'n'P, because it is "more stable".
And I find the prospect of "Zero-Installs" very appealing.
The only thing I was not able to make work thus far is nyc.
And I do not know how to even begin debugging this problem myself, as there are no errors thrown or anything obvious like that.
The text was updated successfully, but these errors were encountered: