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

yarn 2 pnp fails in fish shell #144

Closed stavalfi closed 3 years ago

stavalfi commented 3 years ago

Using yarn 2.4.0 without node_modules, this plugin fails to start a debugger.

logs from vscode:

Welcome to fish, the friendly interactive shell
Type `help` for instructions on how to use fish
 p/era-ci {stav/move-to-yarn2} $  /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-ui=http' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/node-cdp.12103-1.sock","deferredMode":false,"waitForDebugger":"","execPath":"/var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/fnm-shell-9979566/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/node-debug-callback-e4d99c0653f081cb"}'  /var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/fnm-shell-9979566/bin/node ./node_modules/.bin/jest /Users/stavalfi/projects/era-ci/packages/tests/era-ci-tests/__tests__/print-exiting-flow-logs.spec.ts -c /Users/stavalfi/projects/era-ci/packages/tests/era-ci-tests/jest.config.js -t "@era-ci/core --print-flow <flow-id> fail when we try to print logs of flow-id that does not exists" --runInBand 
Debugger attached.
Waiting for the debugger to disconnect...
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '/Users/stavalfi/projects/era-ci/node_modules/.bin/jest'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
 p/era-ci {stav/move-to-yarn2} $ npx envinfo                                                                                                                                                                                                                               1s
npx: installed 1 in 1.533s

  System:
    OS: macOS 10.15.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.40 GB / 16.00 GB
    Shell: 3.1.2 - /usr/local/bin/fish
  Binaries:
    Node: 14.16.0 - /var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/fnm-shell-7875095/bin/node
    Yarn: 2.4.0 - /var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/fnm-shell-7875095/bin/yarn
    npm: 6.14.11 - /var/folders/fh/lk3kyv9n29v3w36bqyv_y7d00000gn/T/fnm-shell-7875095/bin/npm
  Managers:
    Homebrew: 3.0.1 - /usr/local/bin/brew
    pip3: 21.0.1 - /usr/local/bin/pip3
    RubyGems: 3.0.3 - /usr/bin/gem
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 4.2.1 - /usr/bin/gcc
    Git: 2.28.0 - /usr/local/bin/git
    Clang: 1103.0.32.62 - /usr/bin/clang
  Servers:
    Apache: 2.4.41 - /usr/sbin/apachectl
  Virtualization:
    Docker: 20.10.2 - /usr/local/bin/docker
  IDEs:
    Nano: 2.0.6 - /usr/bin/nano
    VSCode: 1.53.2 - /usr/local/bin/code
    Vim: 8.1 - /usr/bin/vim
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Go: 1.15.7 - /usr/local/bin/go
    Perl: 5.18.4 - /usr/bin/perl
    PHP: 7.3.9 - /usr/bin/php
    Python: 2.7.16 - /usr/bin/python
    Python3: 3.9.1 - /usr/local/bin/python3
    Ruby: 2.6.3 - /usr/bin/ruby
  Databases:
    SQLite: 3.28.0 - /usr/bin/sqlite3
  Browsers:
    Brave Browser: 88.1.20.108
    Chrome: 88.0.4324.192
    Safari: 13.0.3
  Monorepos:
    Yarn Workspaces: 2.4.0
firsttris commented 3 years ago

have you activated the following options for yarn 2 pnp in vscode settings ?

| jestrunner.enableYarnPnpSupport | Enable if you are using Yarn 2 with Plug'n'Play | | jestrunner.detectYarnPnpJestBin | Auto-detect path on Linux/Unix systems to Jest bin (Yarn 2 Pnp) |

stavalfi commented 3 years ago

after settings them:

it seems broken:

 p/another-nodejs-test-runner (main) $ node --require '/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js' "`yarn bin jest`" '/Users/stavalfi/projects/another-ndejs-test-runner/packages/another-nodejs-test-runner/__tests__/test1.spec.ts' -t 'test1'
/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js:15100
    throw firstError;
    ^

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

Source path: /Users/stavalfi/projects/another-nodejs-test-runner/`yarn bin jest`
Rejected candidate: /Users/stavalfi/projects/another-nodejs-test-runner/`yarn bin jest`
Rejected candidate: /Users/stavalfi/projects/another-nodejs-test-runner/`yarn bin jest`.js
Rejected candidate: /Users/stavalfi/projects/another-nodejs-test-runner/`yarn bin jest`.json
Rejected candidate: /Users/stavalfi/projects/another-nodejs-test-runner/`yarn bin jest`.node

    at internalTools_makeError (/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js:14844:34)
    at resolveUnqualified (/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js:15883:13)
    at resolveRequest (/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js:15907:14)
    at Object.resolveRequest (/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js:15979:26)
    at Function.external_module_.Module._resolveFilename (/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js:15077:34)
    at Function.external_module_.Module._load (/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js:14942:48)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

when I try to run: "echo /Users/stavalfi/projects/another-nodejs-test-runner/yarn bin jest":

/Users/stavalfi/projects/another-nodejs-test-runner//Users/stavalfi/projects/era-ci/node_modules/.bin/jest

stavalfi commented 3 years ago

it took me some time to find the actual bug:

for some reason, this extension changes the folder names:

look:

node --require '/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js' "`yarn bin jest`" '/Users/stavalfi/projects/another-ndejs-test-runner/packages/another-nodejs-test-runner/__tests__/test1.spec.ts' -t 'test1'

look closer:

/Users/stavalfi/projects/another-nodejs-test-runner/.pnp.js
/Users/stavalfi/projects/another-ndejs-test-runner/packages/another-nodejs-test-runner/__tests__/test1.spec.ts

the change:

another-nodejs-test-runner/
another-ndejs-test-runner

weird...

When changing the project name to something else ("another-test-runner"), this bug was reproduced on the "packages" word: "packages" -> "pacages"

stavalfi commented 3 years ago

more info:

I'm using fish as the default terminal in Vscode.

--

When changing to zsh, it's working. you should add it to the docs as the supported terminals.

firsttris commented 3 years ago

also using fish btw :+1:

we are changing directory to workspace root.

means

vscode.workspace.getConfiguration().get('jestrunner.projectPath') || vscode.workspace.getWorkspaceFolder(editor.document.uri).uri.fsPath;

why does it do that?

https://github.com/firsttris/vscode-jest-runner/blob/master/src/jestRunner.ts#L49

stavalfi commented 3 years ago

you can try to reproduce it: https://github.com/stavalfi/another-nodejs-test-runner

install your extention and: (with nodejs v14.16.0 (yarn2 is having hard time with node15))

yarn
yarn dlx @yarnpkg/pnpify --sdk
yarn

try to run a test with fish as a default terminal in vscode.

firsttris commented 3 years ago

image

image

image

works like a charm ;)

firsttris commented 3 years ago

in version 34 is now also an option to disable changing directory to workspace root

firsttris commented 3 years ago

a wait on this computer i have not installed fish... will test tomorrow on my main computer

firsttris commented 3 years ago

with fish shell: image

with bash: image

some other tests: image

firsttris commented 3 years ago

do you know whats the problem with the command for fish shell? i don't see any path problems on my side.

stavalfi commented 3 years ago

not sure. but at least something is reproducable at your machine.

firsttris commented 3 years ago

i think the way we concat the command together is not compatibel for fish.

stavalfi commented 3 years ago

@alexkuc

alexkuc commented 3 years ago

The issue here is the use of backticks. Fish does not support backticks (docs). This needs to use subshell instead of backticks:

https://github.com/firsttris/vscode-jest-runner/blob/b0ee1d36b443884d69d32813e8e0bdbf5e079aba/src/jestRunnerConfig.ts#L146

Unfortunately, when writing the PR I wasn't too familiar with VSCode and couldn't get it to stop escaping the dollar sign, e.g. $(subshell).

alexkuc commented 3 years ago

@stavalfi @firsttris https://github.com/firsttris/vscode-jest-runner/pull/158

stavalfi commented 3 years ago

Thanks @alexkuc !