Skip to content
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

jest-editor-support: Add support for Windows Subsystem for Linux in Runner #6941

Closed
wants to merge 3 commits into from

Conversation

mojadev
Copy link

@mojadev mojadev commented Sep 3, 2018

  • 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

Summary

See jest-community/vscode-jest#331 for motivation.
When running vscode in Windows but executing jest in WSL (WIndows Subsystem for Linux), additional steps have to be performed:

  • project_workspace now has a useWsl flag (like the built-in flag for vscode launch options) which can be set to true
  • The wsl command has to be prepended to the shell command if useWsl is true
  • The jest output path is a windows path, but wsl is running in a different filesystem with POSIX paths (usually C:/ is /mnt/c), this has to be translated.
  • The last step is done in a own package wsl-path, as this is also required in vscode-jest and I don't really see it in the scope of either jest or vscode jest (see https://github.com/mojadev/wsl-path)

Test plan

See the following command being executed on a Windows 10 Host - normally the path would be C:..
grafik

@codecov-io
Copy link

codecov-io commented Sep 3, 2018

Codecov Report

Merging #6941 into master will increase coverage by 0.03%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6941      +/-   ##
==========================================
+ Coverage   67.25%   67.28%   +0.03%     
==========================================
  Files         248      249       +1     
  Lines        9641     9614      -27     
  Branches        3        3              
==========================================
- Hits         6484     6469      -15     
+ Misses       3156     3144      -12     
  Partials        1        1
Impacted Files Coverage Δ
...kages/jest-editor-support/src/project_workspace.js 100% <100%> (ø) ⬆️
packages/jest-editor-support/src/Runner.js 88.09% <100%> (ø) ⬆️
packages/jest-editor-support/src/Process.js 88.88% <85.71%> (-4.45%) ⬇️
...ackages/jest-editor-support/src/readTestResults.js 90.47% <90.47%> (ø)
packages/jest-runtime/src/helpers.js 50% <0%> (-40.48%) ⬇️
packages/babel-jest/src/index.js 39.62% <0%> (-1.12%) ⬇️
packages/jest-runtime/src/index.js 76.64% <0%> (-0.53%) ⬇️
packages/jest-validate/src/index.js 0% <0%> (ø) ⬆️
packages/jest-message-util/src/index.js 80.91% <0%> (ø) ⬆️
packages/jest-jasmine2/src/index.js 0% <0%> (ø) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 814c929...9f62a27. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented Sep 3, 2018

@orta @seanpoulter @connectdotz mind reviewing this?

@seanpoulter
Copy link
Contributor

I'll have some time towards the end of the week to really get into it if the other two don't. Looks great at a glance though. Nicely done Jannis!

@SimenB
Copy link
Member

SimenB commented Sep 17, 2018

@orta @seanpoulter @connectdotz ping 🙂

@connectdotz
Copy link
Contributor

I don't have a window machine to verify this, if @seanpoulter didn't have time to review it, I suggest @stephtr who actually reviewed the original jest-community/vscode-jest#331


// If a path to configuration file was defined, push it to runtimeArgs
if (workspace.pathToConfig) {
runtimeArgs.push('--config');
runtimeArgs.push(workspace.pathToConfig);
}

if (workspace.useWsl) {
runtimeArgs = [command, ...runtimeArgs.map(convertWslPath)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for consistency I would also convert command such that we also support absolute commands.

@stephtr
Copy link
Contributor

stephtr commented Sep 22, 2018

At first thank you for your work!
One thing I noticed is that if you have several Linux distros installed in parallel (which is perfectly supported by Microsoft), you have no chance of specifying in which one the command should be executed. One way of solving it would be to not automatically prepend wsl as a command but have the user to explicitly set for example bash npm test --.
Beside that, is it intended that we transform windows -> linux paths in jest-editor-support but do the backtransformation in vscode-jest instead of within Runner.js?

@mojadev
Copy link
Author

mojadev commented Sep 24, 2018

Hey,
very good points - I'll rework the PR this week.

  • Regarding multiple wsl environments -> I basically mirrored the behaviour of the launch.json configuration, which always uses the default distro. Originally I also didn't have the prepend command magic in there, but I didn't like having to set two settings (one useWsl + an updated path) - detecting the environment from the path is not really an option, I think. How about useWsl: string | boolean, e.g.
    useWsl: true // default wsl env
    useWsl: 'ubuntu' // use ubuntu
    useWsl: 'bash;  // use bash

as possible config options?

  • Having the backtransformation in vscode-jest would be definetly best (also because I don't need two PRs :) ), but where would you see that happening right? When I get it right, editor-support is only providing the output as is, reading the actual results is done in vscode-jest. I could see two options to support mapping only in one place:
  • Move reading the json file to editor-support and make an implicit mapping when in wsl
  • Move wsl support deeper into jest, so the file is already mapped, which I would not really consider an option
    I didn't want to change too much in the existing code for this PR, but I'm willing to :)

@stephtr
Copy link
Contributor

stephtr commented Sep 24, 2018

How about useWsl: string | boolean

In my opinion that would be perfect!

When I get it right, editor-support is only providing the output as is, reading the actual results is done in vscode-jest.

You initially added the translateWslPathsToWindowsPaths to updateWithData, which itself is called within jestProcess.onJestEditorSupportEvent('executableJSON', (data: JestTotalResults) => {this.updateWithData(data)}), which in turn gets triggered by _parseOutput within jest-editor-support/Runner.js.

@mojadev
Copy link
Author

mojadev commented Sep 24, 2018

You're right, I somehow had in mind vscode-jest reads the file by itself. Thanks!

Then I'll

  • update wsl-path to support multiple environments
  • update useWsl to (string | boolean)
  • move the translate logic out of vscode-jest and into _parseOuptut
  • also translate the command, as noted in your code review

I hope that I manage to do it in the next few days

@stephtr
Copy link
Contributor

stephtr commented Sep 24, 2018

Sounds good to me.
@connectdotz or @seanpoulter: is that ok for you?

@seanpoulter
Copy link
Contributor

I'm unable to comment for a few weeks, sorry.

@mojadev
Copy link
Author

mojadev commented Oct 7, 2018

@stephtr : Sorry for the delay here (I didn't find too much time for reworking it, and my main system is Fedora again). One question regarding file naming: I will add a result_reader module which contains a readTestResults. Now I'm a bit confused because some modules are uppercase (Process.js) and others are lower / snakecase (test_reconciler). Is there some kind of pattern behind this? Should I use result_reader.js or ResultReader.js?

@SimenB
Copy link
Member

SimenB commented Oct 7, 2018

See #4969

…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 mojadev force-pushed the wsl-support-in-runner branch 2 times, most recently from 2361f16 to 83573c0 Compare October 14, 2018 18:19
…upport, support multiple wsl environments

- The useWsl config in ProjectWorkspace can now be
  either 'true' or the actual wsl command (e.g. 'ubuntu run')
- Resolving the path is done after resolving the json file,
  so for projects using jest-editor-support no extra effort is required
  to support useWsl
@mojadev
Copy link
Author

mojadev commented Oct 14, 2018

@stephtr I updated the PR as discussed, maybe you find some time to look over it

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's up? lf vs crlf?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange - in my local dev environment it's LF (and I disabled autoCLRF), I'll verify that

Copy link
Author

@mojadev mojadev Oct 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the master this file is CLRF while all other files are LF - is that intended?

file index.d.ts
index.d.ts: ASCII text, with CRLF line terminators

if so, I switch back to CLRF for this file only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite sure that this wasn't intended, but it's probably better to change line endings in a separate PR.

@@ -40,7 +42,7 @@ export default class Runner extends EventEmitter {
this._createProcess = (options && options.createProcess) || createProcess;
this.options = options || {};
this.workspace = workspace;
this.outputPath = tmpdir() + '/jest_runner.json';
this.outputPath = tmpdir() + sep + 'jest_runner.json';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.join instead

@SimenB
Copy link
Member

SimenB commented Oct 22, 2018

@mojadev could you open this up against https://github.com/jest-community/jest-editor-support (See #7232).

Thanks, and sorry for the inconvenience!

@SimenB SimenB closed this Oct 22, 2018
@mojadev
Copy link
Author

mojadev commented Oct 22, 2018 via email

Copy link
Contributor

@stephtr stephtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay.
In principle it looks good to me, once we have the PR in the new repository, we will test it and hopefully ship it soon.

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite sure that this wasn't intended, but it's probably better to change line endings in a separate PR.

*
* @param coverageMap The coverage map to rewrite
*/
const translateWslPathCoverateToWindowsPaths = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Coverate" is probably a spelling mistake?

if (workspace.useWsl) {
// useWsl can be either true for the default ('wsl' or the explicit
// wsl call to use, e.g. 'ubuntu run')
const wslCommand = workspace.useWsl === true ? 'wsl' : workspace.useWsl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to not duplicate your code, I would use your getWslCommand function from readTestResults.js (even though I would then place the function in another file, maybe we need a helper.js file or similar).

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants