-
Notifications
You must be signed in to change notification settings - Fork 291
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
No way to use jest installed within Windows Subsystem for Linux #331
Comments
Is your whole project residing within WSL or did you just run npm install within WSL? |
Sorry, not sure what you mean - I ran |
That answers my question. You could set |
That doesn't work, and I would've been surprised if it did, because the command still runs within the windows context, which does not have
Note how it refers to Same error, referring to I believe I've found the correct command that should be used by the extension: |
If you want to get yours hands dirty it's simple to debug the extension and see if
When you get vscode-jest open in VS Code, run the Debug: Select and Start Debugging command and start the Launch Extension configuration. That'll open up a new workspace where you can load your own project. Jump back into the extension and set set a breakpoint at Alternatively, I'd suggest creating a minimal JS file from Windows that spawns a process that can access the WSL. They're likely going to be the same amount of work. |
Since the whole node_modules folder is already present, what speaks against installing just Node? I think that would be the only tool needed. |
vscode-jest 2.9.0 has shipped, which could help addressing this issue. Please give it a try and let us know if it works for you. |
@connectdotz please see the screenshots above - it still doesn't work, with the same error. What I find bizarre is that the following user setting should work, as I explained with a little more info above {
"jest.pathToJest": "wsl jest"
} But instead, it says
The same Which means that whatever context this extension is running with, it's missing something, possibly the correct PATH |
If you follow the README docs to setup this report and the Jest repo, you'll be able to debug the process launch and see how we're calling |
Hey, I'm also having issues getting the extension running with a wsl only setup. The issue is that the workspace path (which is provided by jest-editor-support afaik) is used from the windows environment, not from the WSL environment - leading to errors like this: `
Therefore |
any update on this issue? |
I set up the extension for development/debugging and will see if I find a fix or workaround tomorrow
From: Yehonathan Sharvit
Sent: Tuesday, August 14, 2018 7:45 PM
To: jest-community/vscode-jest
Cc: Jannis Moßhammer; Comment
Subject: Re: [jest-community/vscode-jest] No way to use jest installed withinWindows Subsystem for Linux (#331)
any update on this issue?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Thanks @mojadev |
See #361 - although I would also be ok with this PR to be rejected and updating jest-editor-support where necessary. Opinions/Suggestions on how to improve path detection and mapping are welcome. |
@viebel & @mojadev please can you help me with this problem. I've read the thread twice and it's like the solution is hidden. I had a look at the PR but that sort of stuff seems to be beyond my level. I've got jest running in the console but not properly integrated into vscode.
The following runs in the debug console but it does throw up an error.
I also had a linked at the PR but that didn't help me much. Please could someone explain to me how to get the jest integrated with vscode properly. |
…unner * Add useWsl configuration flag to project worksapce * Translate windows paths in call args to POSIX paths valid in WSL see jest-community/vscode-jest#331
…unner * Add useWsl configuration flag to project worksapce * Translate windows paths in call args to POSIX paths valid in WSL see jest-community/vscode-jest#331
@mojadev Any update on this issue ? I'm looking forward having this extension working with WSL 😄 |
Yes, support is currently in work (at them moment in facebook/jest). |
@stephtr Thanks, gonna wait for this PR merge then :) |
…unner * Add useWsl configuration flag to project worksapce * Translate windows paths in call args to POSIX paths valid in WSL see jest-community/vscode-jest#331
…unner * Add useWsl configuration flag to project worksapce * Translate windows paths in call args to POSIX paths valid in WSL see jest-community/vscode-jest#331
Any updates on this ? It seems that jest has added support in this issue (If I'm not mistaken, this is the PR that was talked about in previous comments) |
Hi I'm deeply sorry it takes so long - functionality wise it is there, and the PR worked, but due to a unfortunate mixture of either me or reviewers not being available (either me not having time or the reviewer) and a bigger restructuring in the jest repository this got heavily delayed. For me the next weeks are less crowded and I just need to take the code and move it to the new repository that has been introduced by jest. I'll try to binge-watch a couple of 'just-do-it' motivational speeches and finish it this week. |
Don't be sorry for our bottleneck reviewing @mojadev. 😥 Can you help test the PR @bogdan-calapod? I reviewed it last night. |
Sure, I'll check it out tomorrow |
I overlooked that we'll need a change to jest-community/jest-editor-support as well. Check for a PR there first. https://github.com/jest-community/jest-editor-support/pulls |
@seanpoulter : Did you find time to look over the issues in the PR? |
No, sorry. I got as far as confirming the tests are failing in the jest-editor-support repo. |
I receive the following error when trying to run it in WSL
It looks like it's trying to run tests with the node/jest in WSL, but some path stuff is getting messed up. Workspace Settings:
User settings:
|
I was able to trick jest into working by telling vscode-jest to run the following script: "use strict";
const cp = require("child_process");
const args = [];
for (const arg of process.argv.slice(2)) {
if (arg.startsWith("C:\\")) {
args.push(`/mnt/c/${arg.slice(3).replace(/\\/g, "/")}`);
} else args.push(arg);
}
cp.spawnSync("wsl", ["node", "node_modules/.bin/jest", ...args], {
cwd: process.cwd(),
stdio: "inherit"
}); However vscode-jest doesn't seem to apply the failures -- most likely because it doesn't understand the file paths in the test results JSON (which use WSL I think I can adjust the script to intercept the JSON file though. Telling vscode-jest to use wsl directly didn't work because it used Windows paths. The output indicated the backslashes are being swallowed at some point but either way jest wouldn't know what to do with the EDIT: Adjusted the script to intercept the file and do a naive search & replace to fix paths: "use strict";
const fs = require("fs");
const cp = require("child_process");
const args = ["--json", "--no-color"];
const i = process.argv.indexOf("--outputFile");
if (i === -1) {
console.error("Unexpected args", process.argv.slice(2));
process.exit(1);
}
if (process.argv.includes("--watch")) {
args.push("--watch");
}
const winOutputFilePath = process.argv[i + 1];
const proc = cp.spawn("wsl", ["node", "node_modules/.bin/jest", ...args], {
cwd: process.cwd(),
stdio: "pipe"
});
proc.stdout.on("data", buf => {
const str = buf.toString("utf-8");
fs.writeFileSync(
winOutputFilePath,
str
.replace(/\/mnt\/[a-z]/g, str => `${str.charAt(5).toUpperCase()}:`)
.replace(/\//g, "\\\\")
.replace(/\n/g, "\r\n")
);
});
proc.stderr.on("data", buf => {
const str = buf.toString("utf-8");
process.stdout.write(
str
.replace(/\/mnt\/[a-z]/g, str => `${str.charAt(5).toUpperCase()}:`)
.replace(/\//g, "\\")
.replace(/\n/g, "\r\n")
);
});
proc.on("error", err => {
console.error(err);
}); However it looks like this isn't sufficient to get watch mode working. The plugin gets stuck on "starting watch mode" and still doesn't apply the output. I'm guessing it expects some kind of signal or something. EDIT2: Looks like this is a dead end. I've looked into |
I already created a fix for this half a year ago that got stuck after reworks in the base repo and breaking tests (that weren't really affected by the changes)- see https://github.com/mojadev/jest-editor-support/tree/WSL_Support . Technically it's easy, but getting it into the master seems to be the actual issue :) I'll try to pull the current master of the editor support once and see if the base repo is more stable now. |
Any updates on this? I'm having the same issue. Thanks! 🙏 |
@connectdotz just informed me that the jest-editor-support changes are about to be finished, afterwards I'll check my PR again for conflicts and we should be able to close this issue. |
Any updates on this? I'm having the same issue. Thanks! 🙏 |
Note that the extension currently only works with the Insiders version. But now that VS Code is getting native support for WSL via the Remote WSL extension I think this ticket can be closed. |
I agree. I could update my fix now that the 3.0.0. release is out but given that the Remote WSL extension is out (soon) I think using that one is the better solution. I used my wsl-support branch for development in WSL until now and will also switch to the remote extension, as this is the better solution imho. |
Even Microsoft is now deprecating the use of Finally thank you all, especially @mojadev, for the effort put into trying to solve this issue! |
Thanks @stephtr this Works. Since we are mostly developing and deploying Docker, this also exposed some assumptions we've made about handling dates too. |
Environment
node -v
: no version installednpm -v
: no version installednpm ls react-scripts
(if you haven’t ejected): N/AOperating system: Windows 10 + WSL
Steps to Reproduce
Use Windows 10 + Windows subsystem for linux. Install node/npm/jest within the subsystem only, not in windows.
Expected Behavior
There should be a way to use the version of jest installed within WSL rather than duplicating the installation of all the tools required, once within linux and once in windows
Actual Behavior
(Quite rightly, as there's absolutely no node/jest/npm installed outside WSL)
I've tried to look through docs and other open bugs but cannot find anything similar, apologies if I've missed it!
Note that I'm not sure if there are any guidelines for extension authors around using WSL, but it's e.g. possible to debug files using node installed within WSL, so assuming it's doable for extensions as well.
The text was updated successfully, but these errors were encountered: