1

I would like to pass variables to a mocha test, which is not as simple as expected. Passing a variable like this:

npm run test --scope=28

is not possible, because mocha will catch the input. I also tried to use the npm minimist package and using a user prompt failed also.

Anyway my colleagues are using a mac and are able to pass an env variable by using this command

export testscope="18" && npm run test

But unfortunately this will not work in Windows. So my question is, is there a similar export command for Windows?

1 Answer 1

2

You can use the CMD.EXE set command for this, acts like export on *NIX.

set testscope=18 && npm run test

You did not say which shell you are using, in PowerShell, you might want to do this:

$env:testscope= 18; npm run test

The OP finally decided on installing the Linux subsystem of Windows, to do this, you issue the following in Powershell ("opened as Administrator"):

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
3
  • Thank you! I would like to use the PowerShell but set testscope=18 && npm run test did not worked. Because of the "&&". So I tried using the first command and then the second, which did not worked out. I'm installing the Linux bash (subsystem) now in Windows.
    – KiSa87
    Commented Dec 8, 2017 at 10:25
  • I ended up installing the linux bash as a subsystem on windows and used the command there, which are working great.
    – KiSa87
    Commented Dec 8, 2017 at 11:02
  • If somebody find this post and will need more information about Linux as a subsystem: blogs.msdn.microsoft.com/wsl/2016/04/22/…
    – KiSa87
    Commented Dec 8, 2017 at 12:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.