angular-phonecat 教程假定您在安装了 chrome 的服务器上运行 angular-phonecat。
进入 npm test
后,本地 chrome-browser 应该打开并连续运行测试。
当然这在我的 headless 服务器上不起作用:
/var/www/angular-phonecat$ npm test
> angular-phonecat@0.0.0 pretest /var/www/angular-phonecat
> npm install
> angular-phonecat@0.0.0 postinstall /var/www/angular-phonecat
> bower install
> angular-phonecat@0.0.0 test /var/www/angular-phonecat
> karma start test/karma.conf.js
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
ERROR [launcher]: Cannot start Chrome
Can not find the binary google-chrome
Please set env variable CHROME_BIN
我想在作为服务器且未安装 X 的 Linux 机器上执行此操作。
一种方法是通过隧道传输 X session ,但我宁愿通过 http 手动将 npm test
环境连接到我的本地 chrome。
我该怎么做?
我需要告诉 npm test
它不应该启动 chrome?我看到服务器正在 http://localhost:9876/
上运行,所以我会手动连接。
angular-phonecat 教程假定您在安装了 chrome 的服务器上运行 angular-phonecat。
进入 npm test
后,本地 chrome-browser 应该打开并连续运行测试。
当然这在我的 headless 服务器上不起作用:
/var/www/angular-phonecat$ npm test
> angular-phonecat@0.0.0 pretest /var/www/angular-phonecat
> npm install
> angular-phonecat@0.0.0 postinstall /var/www/angular-phonecat
> bower install
> angular-phonecat@0.0.0 test /var/www/angular-phonecat
> karma start test/karma.conf.js
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
ERROR [launcher]: Cannot start Chrome
Can not find the binary google-chrome
Please set env variable CHROME_BIN
我想在作为服务器且未安装 X 的 Linux 机器上执行此操作。
一种方法是通过隧道传输 X session ,但我宁愿通过 http 手动将 npm test
环境连接到我的本地 chrome。
我该怎么做?
我需要告诉 npm test
它不应该启动 chrome?我看到服务器正在 http://localhost:9876/
上运行,所以我会手动连接。
编辑 1:我尝试的是这个,创建一个虚拟二进制文件而不是不存在的 chrome:
/var/www/angular-phonecat$ cat dummy.sh
#!/bin/sh
read -p "Press enter to terminate ... " dummy_userinput
... 并将其传递给测试:
/var/www/angular-phonecat$ export CHROME_BIN="/var/www/angular-phonecat/dummy.sh" && npm test
它以某种方式工作,但虚拟 chrome 没有给出我怀疑的正确答案:
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 34.0.1847 (Windows 7)]: Connected on socket Ri4I_SRpM8UA1q_Kq6V6
WARN [launcher]: Chrome have not captured in 60000 ms, killing.
INFO [launcher]: Trying to start Chrome again.
WARN [launcher]: Chrome have not captured in 60000 ms, killing.
INFO [launcher]: Trying to start Chrome again.
WARN [launcher]: Chrome have not captured in 60000 ms, killing.
最佳答案
PhantomJS 就是为了这个目的。来自 PhantomJS 网站:
One major use case of PhantomJS is headless testing of web applications. It is suitable for general command-line based testing, within a precommit hook, and as part of a continuous integration system.
在您的 karma-conf.js 中,设置以下内容:
browsers: ['PhantomJS']
关于javascript - 在 headless 服务器上运行时如何运行 angular-phonecat 教程测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23643689/