firsttris / vscode-jest-runner

Simple way to run or debug one or more tests from context menu, codelens or command plalette
https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner
MIT License
265 stars 124 forks source link

regresion yarn2 not work any more #185

Closed stavalfi closed 3 years ago

stavalfi commented 3 years ago

bug with 0.4.39:

stavalfi@stavs-MacBook-Pro singer % node --require '/Users/stavalfi/projects/singer/.pnp.js' "" '/Users/stavalfi/projects/singer/packages/csm/__tests__/scheduld-all-research-calls-are-called.spec.ts' -t 'send pf message and then rb message to create a match for future game \(without molly messages\) and expect researchll 4 times and also after first-half is finished'
Welcome to Node.js v14.16.0.
Type ".help" for more information.
>

it seems that node interpeter is opened instead of running jest. I assume it is caused due to the fact the "jest" path is missing in the command.


bug with with version 0.4.34 (and 0.4.33): (when running "run" it's working, when running with debug - it's broken):

p/singer {stav/SIN-163} $ /usr/bin/env 'NODE_OPTIONS=--require "/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.js-debug/src/bootloader.bundle.js" --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/node-cdp.21569-1.sock","deferredMode"}:false,"waitForDebugger":"","execPath":"/var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/fnm-shell-9291080/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/node-debug-callback-11f29c16e8fe78a3"}' /var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/fnm-shell-9291080/bin/node --require /Users/stavalfi/projects/singer/.pnp.js "`yarn bin jest`" /Users/stavalfi/projects/singer/packages/csm/__tests__/schedulder/matching-after-game-started.spec.ts -t "send running-ball and punteam-fixture messages \\(which are related\\) but only after we should have called the first call to research - expect to skip the first call and expect we called the second time" --runInBand 
Debugger attached.
Waiting for the debugger to disconnect...
/Users/stavalfi/projects/singer/.pnp.js:19054
    throw firstError;
    ^

Error: Qualified path resolution failed - none of the candidates can be found on the disk.

Source path: /Users/stavalfi/projects/singer/`yarn bin jest`
Rejected candidate: /Users/stavalfi/projects/singer/`yarn bin jest`
Rejected candidate: /Users/stavalfi/projects/singer/`yarn bin jest`.js
Rejected candidate: /Users/stavalfi/projects/singer/`yarn bin jest`.json
Rejected candidate: /Users/stavalfi/projects/singer/`yarn bin jest`.node

    at internalTools_makeError (/Users/stavalfi/projects/singer/.pnp.js:18798:34)
    at resolveUnqualified (/Users/stavalfi/projects/singer/.pnp.js:19837:13)
    at resolveRequest (/Users/stavalfi/projects/singer/.pnp.js:19861:14)
    at Object.resolveRequest (/Users/stavalfi/projects/singer/.pnp.js:19933:26)
    at Function.external_module_.Module._resolveFilename (/Users/stavalfi/projects/singer/.pnp.js:19031:34)
    at Function.external_module_.Module._load (/Users/stavalfi/projects/singer/.pnp.js:18896:48)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

@alexkuc it will be very appriciated if you can take a quick look!

alexkuc commented 3 years ago

@stavalfi I'll try to find some time this week to resolve this

alexkuc commented 3 years ago

So I did some preliminary debugging and noticed a couple of things on my end as well as your end:

How are you running the latest version of vscode-jest-runner? Are you installing it via marketplace or installing it from the source?

image

I get empty jest path (like yours) when I am debugging the source code of the extension but if I install it via marketplace, the path is no longer empty (but still fails due to unescaped $ in the jest path)

stavalfi commented 3 years ago

@alexkuc Thanks for looking at it.

I'm installing the extensson from the market place.

Additional Info:

node version: v14.15.4 yarn 2 version: 2.4.1 os: macos catalina 10.15.1 (19B2093)

vscode version:

Version: 1.56.2
Commit: 054a9295330880ed74ceaedda236253b4f39a335
Date: 2021-05-12T17:44:30.902Z (3 wks ago)
Electron: 12.0.4
Chrome: 89.0.4389.114
Node.js: 14.16.0
V8: 8.9.255.24-electron.0
OS: Darwin x64 19.0.0

alexkuc commented 3 years ago

@stavalfi does your coworker use different shell? if yes, could you try with that shell to narrow down the bug?

stavalfi commented 3 years ago

@alexkuc Ho sorry, I forgot to mention that.

I tested this bug on sh,bash,zsh,fish and they all has the first bug. Two of my coworkers uses zsh and I ensured that my self. I saw he had the first bug.

What else can I help?

alexkuc commented 3 years ago

@stavalfi so far to me, unfortunately, it is not clear what has changed or why it broke so I am still looking into this but due to my limited availability, the progress is slowly. Possibly on the weekends, I'll have more time.

stavalfi commented 3 years ago

@alexkuc Please update! Thank you!

drwlrsn commented 3 years ago

Heyo! Just found this issue and I hope I can add some more information to help. The environment the code is running is Yarn 2 with PnP in a monorepo.

When I have 0.4.39 installed I am experiencing the following when running a test via the Run code lens

Screen Shot 2021-06-10 at 2 48 11 PM

I went and tried installing different versions of the extensions and 0.4.34 is latest version that works, so it might be the regression was introduced in 0.4.35.

I verified that both the Run and Debug code lens actions work in 0.4.34.

PS Thanks for this great extension!

drwlrsn commented 3 years ago

If I had to guess it feels like it might be this

https://github.com/firsttris/vscode-jest-runner/blob/39e8fd3b99ee29d04f4108ceb92bca1356311397/src/jestRunner.ts#L53

https://github.com/firsttris/vscode-jest-runner/commit/39e8fd3b99ee29d04f4108ceb92bca1356311397#diff-47c4d698a74f57959729af063e997e343a4c5973453e40bf927b0276d43d8687L53

firsttris commented 3 years ago

i changed something about the escaping of the filepath and also updated jest-editor-support to version 29.

can you re-check if that fixed your issue in 0.4.40

firsttris commented 3 years ago

ah no it didn't.

but i have a yarn pnp project now and can check whats the issue.

firsttris commented 3 years ago

hello i simplified the yarn pnp implementation by simply letting yarn always start jest: https://github.com/firsttris/vscode-jest-runner/commit/ff9a0270a480081319eb20196a7f862ce070be11

only downside its starts 2 debug processes, but apart of that it worked fine for me.

check version 0.4.43

alexkuc commented 3 years ago

This solution will break if you don't use latest Yarn version:

config.program = '.yarn/releases/yarn-berry.cjs';

If your Yarn points to another version, you will get fatal error file not found

firsttris commented 3 years ago

okay, im will research for some more clever vscode debug configuration to do a "yarn jest".

alexkuc commented 3 years ago

To initialize yarn 2 pnp environment, you need to call .pnp.js instead of anything else. If you want to avoid having to deal with bootstrap the yarn environment yourself, just do yarn <cmd> as the documentation says:

use yarn node as interpreter instead of node. This will be enough to register the .pnp.cjs file as runtime dependency.

You can all yarn jest as a simple shell command i.e. via process.exec()

stavalfi commented 3 years ago

hello i simplified the yarn pnp implementation by simply letting yarn always start jest: ff9a027

only downside its starts 2 debug processes, but apart of that it worked fine for me.

check version 0.4.43

Thanks @firsttris!

I can confirm that it's working with bash as a default shell, latest yarn stable version: 2.4.2, node v14.15.4 and jest-runner 0.4.44.

Also, as you saw, there are 2 debug processes.

firsttris commented 3 years ago

thats because 1.) node is starting yarn and 2.) yarn is starting jest

also found other options for the debug config.

type = 'node-terminal' command = 'yarn jest'

but this opens 3 prozesses

1.) user/bin/yarn 2.) starts yarn2 3) starts jest

if you find a better vscode debug config (for yarn pnp with jest) let me know and we change it asap.

best regards tristan

firsttris commented 3 years ago

the best solution would be if i could directly start yarn from vscode debug config, not node.

stavalfi commented 3 years ago

is there any way to add e2e test for yarn2? I never developed any plugin to vscode so im clueless about the possibilities for tests.

maybe yarn2 test case is completely not doable or not worth it. wdyt?

firsttris commented 3 years ago

i have no clue what "e2e test for yarn2" means.

i use jest for compenent testing and unit testing, and cypress for FE-integration and e2e testing.

drwlrsn commented 3 years ago

@firsttris I checked in 0.4.44 and the tests run. Love it! Thanks

stavalfi commented 3 years ago

@firsttris first of all, thank you for fixing this bug! my team productivity is much higher!!

on other topic, I was thinking if there is a way to create a test case such that it involves yarn2 project (because of 2 regressions in the last 2 months). if it's too hard or not worth it, let's leave it.

drwlrsn commented 3 years ago

@stavalfi I just want to make it clear... I did not fix the bug. I just poked around and made a guess. @firsttris is the one responsible.

stavalfi commented 3 years ago

That was a big typo mistake! I meanted to mention @firsttris in the first place. Thanks for notifing me!

@firsttris Sorry!