在Windows中导出节点变量,如在mac上

时间:2017-12-08 09:51:48

标签: node.js windows macos export mocha

我想将变量传递给mocha测试,这不像预期的那么简单。传递这样的变量:

npm run test --scope=28

是不可能的,因为mocha会捕获输入。我还尝试使用npm minimist包,并且使用用户提示也失败了。

无论如何,我的同事正在使用mac并且能够使用此命令传递env变量

export testscope="18" && npm run test

但不幸的是,这在Windows中不起作用。所以我的问题是,Windows是否有类似的导出命令?

1 个答案:

答案 0 :(得分:0)

您可以使用CMD.EXE set命令,就像* {NIX上的export一样。

set testscope=18 && npm run test

你没有说明你正在使用哪个shell,在PowerShell中,你可能想要这样做:

$env:testscope= 18; npm run test

OP最终决定安装Windows的Linux子系统,为此,您在Powershell中发出以下命令(“以管理员身份打开”):

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux