maty21 / mocha-sidebar

Mocha side bar viewer that allows you to run Mocha tests from side bar menu and view results can run each level hierarchy from all tests to a single test(and each describer of course)
MIT License
193 stars 61 forks source link

Is it possible to run mocha sidebar with WSL #65

Open Steinblock opened 6 years ago

Steinblock commented 6 years ago

I am using Visual Studio Code on windows.

However, the app I am developing runs on linux only.

Generally this is not a problem. I configured "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe" in my user settings.

user@host:/mnt/c/Users/user/Source/app$ which node
/usr/bin/node
user@host:/mnt/c/Users/user/Source/app$ which npm
/usr/bin/npm

However, tests from the moacha sidebar are detected and run with windows.

import { expect } from 'chai';

describe('when running with wsl', () => {

    it("process.platform should be linux", () => {

        expect(process.platform).to.be.equal("linux");

    });

}); 
Finding tests with Mocha on Node.js at "C:\Program Files\nodejs\node.EXE"

Running Mocha with Node.js at "C:\Program Files\nodejs\node.EXE"

Applying Mocha options:
  {
    "bail": false,
    "timeout": 20000
  }

Test file(s):
  c:\Users\user\Source\app\test\test1.ts

Grep pattern:
  ^when running with wsl process\.platform should be linux$

  when running with wsl
    1) process.platform should be linux

  0 passing (17ms)
  1 failing

  1) when running with wsl process.platform should be linux:

      AssertionError: expected 'win32' to equal 'linux'
      + expected - actual

      -win32
      +linux

Not a surprise, because it uses Node from windows

Running Mocha with Node.js at "C:\Program Files\nodejs\node.EXE"

If I understand your docs correctly, there is no way to configure which node will be used, because it takes the one it finds on path: https://github.com/maty21/mocha-sidebar

Because your tests may requires a newer version of Node.js than the one powering Visual Studio Code, thus, this extension will attempt to find your installed Node.js and use it for your tests. It will search for the installed Node.js as indicated by environmental variable PATH.

It would be really helpful, having some control on which command will be executed. So I could just set

C:\WINDOWS\System32\bash.exe -ic 'node node_modules/mocha/bin/_mocha'

to run my test with WSL

This should solve https://github.com/maty21/mocha-sidebar/issues/57 too.

pieterwillaert commented 6 years ago

I was able to get this working by following this guide: https://stackoverflow.com/a/44450219

edit your ~/.profile (nano) and update your path to:

PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"

reload vscode and it should work

maty21 commented 6 years ago

Nice I will add this to the FAQ section

maty21 commented 6 years ago

Can you write exactly the steps should be done / create a PR with this addition to the README file Tks

pieterwillaert commented 6 years ago

@Steinblock could you let me know if this fixed your problem?

Other things you can try

imeyals commented 6 years ago

@pieterwillaert Hey! Could you elaborate on what you mean when saying

make sure your nodejs folder is in your windows path

I don't even have nodejs installed on my windows, only for the WSL subsystem.... Unfortunately it is not working for me so far...

pieterwillaert commented 6 years ago

@aykesubir see: https://stackoverflow.com/a/27864253/1782659, I think node should be installed on your windows in order to run mocha-sidebar

imeyals commented 6 years ago

@pieterwillaert I'll reinstall it and check. And it doesn't matter if it's not the same node instance I use to run my project (which is the node installed on the WSL machine)