无法设置TEST_BROWSER_DRIVER环境变量Windows 10流星

时间:2018-07-30 14:25:05

标签: testing meteor mocha

我根本无法测试我的流星应用程序,以前是在v1.4上,我设法启动了测试,升级到1.6后,尽管付出了很多努力,但我仍然无法运行测试。希望任何人都能提供帮助。

操作系统:Windows 10。

当前的流星版本:1.6

在我的环境变量中,我设置了指向chromedriver的路径,但仍然没有成功。

 C:\Users\Username\Documents\Dev\Proj\infilerp>TEST_BROWSER_DRIVER=chrome meteor test --once --driver-package meteortesting:mocha
'TEST_BROWSER_DRIVER' is not recognized as an internal or external command,
operable program or batch file.  



C:\Users\Username\Documents\Dev\Proj\infilerp>meteor test --full-app --

driver-package meteortesting:mocha --port 8080
[[[[[ Tests ]]]]]

=> Started proxy.
=> A patch (Meteor 1.6.1.3) for your current release is available!
   Update this project now with 'meteor update --patch'.
=> Started MongoDB.
I20180730-17:58:52.807(8)? superadmin created
I20180730-17:58:53.166(8)?
I20180730-17:58:53.167(8)? --------------------------------
I20180730-17:58:53.167(8)? --- RUNNING APP SERVER TESTS ---
I20180730-17:58:53.168(8)? --------------------------------
I20180730-17:58:53.168(8)?
I20180730-17:58:53.168(8)?
I20180730-17:58:53.169(8)?
I20180730-17:58:53.169(8)?   0 passing (1ms)
I20180730-17:58:53.170(8)?
I20180730-17:58:53.171(8)?
I20180730-17:58:53.171(8)? --------------------------------
I20180730-17:58:53.172(8)? --- RUNNING APP CLIENT TESTS ---
I20180730-17:58:53.172(8)? --------------------------------
W20180730-17:58:53.281(8)? (STDERR) C:\Users\Username\AppData\Local\.meteor\packages\meteor-tool\1.6.1\mt-os.windows.x86_64\dev_bundle\server-lib\node_modules\fibers\future.js:280
W20180730-17:58:53.282(8)? (STDERR)                                             throw(ex);
W20180730-17:58:53.283(8)? (STDERR)                                             ^
W20180730-17:58:53.283(8)? (STDERR)
W20180730-17:58:53.283(8)? (STDERR) Error: Unknown driver "C:\Users\Username\Documents\Dev\Proj\infilerp\node_modules\chromedriver\lib\chromedriver\chromedriver.exe". browser-tests package requires that you set the TEST_BROWSER_DRIVER environment variable to one of the following: chrome, nightmare, phantomjs, puppeteer
W20180730-17:58:53.284(8)? (STDERR)     at startBrowser (packages/meteortesting:browser-tests/server.js:39:13)
W20180730-17:58:53.284(8)? (STDERR)     at clientTests (packages/meteortesting:mocha/server.js:138:3)
W20180730-17:58:53.284(8)? (STDERR)     at serverTests (packages/meteortesting:mocha/server.js:168:7)
W20180730-17:58:53.285(8)? (STDERR)     at mochaInstance.run.failureCount (packages/meteortesting:mocha/server.js:118:13)
W20180730-17:58:53.285(8)? (STDERR)     at done 

...    
=> Exited with code: 1

1 个答案:

答案 0 :(得分:2)

在Windows上使用NodeJS / Meteor时,我发现使用带有交叉环境或批处理脚本的npm脚本运行所有内容要容易得多

对于测试示例,我将在package.json中设置一个脚本,如下所示:

{
  "scripts": {
    "start": "meteor run",
    "test": "cross-env TEST_BROWSER_DRIVER=chrome meteor test --full-app --driver-package meteortesting:mocha --port 8080"
  },
  "devDependencies": {
    "cross-env": "^5.2.0",
    ...etc
  }
}

cross-env完成了跨不同操作系统正确设置环境变量的工作,因此您可以使用npm run test

在任何地方运行脚本

或者,作为批处理脚本(仅Windows):

set TEST_BROWSER_DRIVER=chrome
REM Optionally set other env vars you want
set TEST_WATCH=1
meteor test --full-app --driver-package meteortesting:mocha --port 8080

此外,现在meteortesting:mocha支持puppeteer,我强烈建议将其用作浏览器驱动程序。使用它使我头疼的方式减少了:

npm install --save-dev puppeteer

TEST_BROWSER_DRIVER=puppeteer

您可能需要将meteortesting:browser-tests更新到1.0.0版本以启用pupeteer支持。