question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auto-detect project path?

See original GitHub issue

I’m new to vscode and this extension, so I’m not sure if I’m missing something.

My workspace contains a Java backend and a TypeScript/JavaScript frontend. The frontend is in folder scroll-documents-ui/src/main/frontend. Getting this extension to work wasn’t easy, as it was not clear from the documentation which config option I would have to set:

  • Without any config, it wouldn’t work as it would look for jest in node_modules/.bin/jest based on my workspace directory, rather than the frontend directory.
  • Specifying jestrunner.jestPath didn’t work, because it was running the tests from the workspace directory, rather than the frontend directory. For some reason this caused jest not to be able to parse the test files. Also, a relative path worked for jestrunner.jestPath despite the documentation specifying that it needs to be an absolute path.
  • Specifying jestrunner.projectPath worked, although only as an absolute path, not as a relative path.

The main pain points that I see here are:

  • The documentation is not very explicit on how exactly to configure a multi-module workspace, even though I think that scenario is very common when developing an application that has a frontend and a backend?
  • The requirement of specifying jestrunner.projectPath as an absolute path makes it impossible to share my workspace config with other developers.
  • What if I want to use jest in multiple modules, for example in the frontend and in the backend?

I’m wondering why this extension is not detecting the project path automatically? My guess would be that it should be the closest ancestor directory to the test for which a node_modules/.bin/jest sub-path exists.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
berndartmuellercommented, Feb 20, 2021

For anyone who’s interested, here’s a simple shell script which I use for a Yarn workspaces project:

# Extract working directory based on jest config file

# Path to Jest config file supplied by VSCode Jest Runner
jest_config=$3

# Remove part after last slash
cwd=$(echo "$jest_config" | sed 's|\(.*\)/.*|\1|')

cd "$cwd"

command="node '$cwd/node_modules/.bin/jest' '$1' -c $jest_config -t '$5' $6"

eval "$command"

cd ../..

How to use

  1. Put script into ./bin/jest.sh in the root folder of your project
  2. Add "jestrunner.jestCommand": ". bin/jest.sh" to your VSCode settings.json
  3. Use VSCode Jest runner as usual end enjoy your working tests 😃

This script is my opinionated way to auto-detect the working directory of the test file. It can be improved to be more “smart” about how to find the CWD (e.g. traverse the file tree looking for a package.json,…)

1reaction
firsttriscommented, Feb 24, 2021

Hey guys, for me and many others the extension already works well with yarn workspaces.

the only thing which is not currently supported is if your jest binrary / config is not in the root folder.

i think the smartest way to solve this would be a todo a reverse lookup for the jest binrary. To find the hierarchy level where the jest binrary is in the node_modules. This should be the correct folder to start Jest.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi-root Workspaces in Visual Studio Code
You can open and work on multiple project folders in Visual Studio Code with multi-root ... a "workspace" is just your project's single...
Read more >
virtualenvwrapper: how to update project path? - Stack Overflow
According to the docs you can use setvirtualenvproject . This will automatically move you to the project folder if you use the workon...
Read more >
Unable to autodetect 'javac' path, using 'javac' from the ...
Hello, I'm experiencing this error when trying to build a specific maven project: "Unable to autodetect 'javac' path, using 'javac'...
Read more >
Toolchains for JVM projects - Gradle User Manual
Additionally, you may want to build a project using a Java version that is not ... Any tasks that can be configured with...
Read more >
build_ios_app - fastlane docs
Sensible defaults: Automatically detect the project, its schemes and more ... build") # store the ipa in this folder output_name("MyApp") # the name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found