我正在https://docs.angularjs.org/tutorial/step_02跟踪Angular Tutorial。
我想运行以下命令:
npm test
karma start karma.conf.js
收到以下错误:
> karma start karma.conf.js
WARN [watcher]: Pattern "/var/angularapp/angular-phonecat/app/**/*.module.js" does not match any file.
WARN [watcher]: Pattern "/var/angularapp/angular-phonecat/app/!(bower_components)/**/*!(.module|.spec).js" does not match any file.
WARN [karma]: No captured browser, open http://localhost:9876/
INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
INFO [launcher]: Starting browser Firefox
INFO [launcher]: Starting browser Chrome
ERROR [launcher]: Cannot start Firefox
INFO [launcher]: Trying to start Firefox again (1/2).
ERROR [launcher]: Cannot start Firefox
INFO [launcher]: Trying to start Firefox again (2/2).
17 08 2016 18:46:51.434:ERROR [launcher]: Cannot start Firefox
ERROR [launcher]: Firefox failed 2 times (cannot start). Giving up.
ERROR [launcher]: Cannot start Chrome
INFO [launcher]: Trying to start Chrome again (1/2).
ERROR [launcher]: Cannot start Chrome
[launcher]: Trying to start Chrome again (2/2).
[launcher]: Cannot start Chrome
ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.
karma.config.js:
browsers: ['Firefox', 'Chrome'],
我使用以下命令安装了Firefox和Chrome:
sudo apt-install chromium-browser
sudo apt-install firefox
并在〜/ .bachrc中设置env变量:
export FIREFOX_BIN=/usr/bin/firefox
export CHROME_BIN=/usr/bin/chromium-browser
我甚至输入了以下命令,但没有帮助:
source ~/.bashrc
我的节点版本是0.12.15,npm是2.15.1。请注意,这是我正在谈论的流浪盒。
请帮助:)
答案 0 :(得分:3)
有人建议我改用Phantomjs!所以我做到了,下面是我完全做了,并做了测试通过:
安装PhantomJS:
"/a/fancy/uri/which/is/invalid.js"
"/a/fancy/uri/which/is/invalid.js?ver=1"
通过在〜/ .bashrc中添加以下行来更新env变量:
sudo npm install -g phantomjs-prebuilt
将以下行添加到项目中package.json文件中的devdependencies:
export PHANTOMJS_BIN=/usr/bin/phantomjs
将以下行添加到karma.config.js文件中:
"karma-phantomjs-launcher": "^0.2.0",
最后将karma.config.js中的浏览器更改为:
plugins: [
...
'karma-phantomjs-launcher',
...
]
然而,我仍然不知道为什么Chrome和Firefox无法正常工作,而Phantomjs也做到了这一点。我查看它的方式是我的流浪盒只是一个Ubuntu机器,不应该与任何其他机器不同!如果有人向我解释原因,那就太好了。请考虑我是新手。
答案 1 :(得分:0)
我在相关主题中发布了一个答案: Karma - Chrome failed 2 times (cannot start). Giving up
基本上,对我来说,Chrome无法启动,因为缺少字体。
答案 2 :(得分:0)
测试也没有为我运行。我将karma.conf.js中的以下内容更改为,以便Karma仅尝试使用Chrome:
browsers: ['Chrome'],
plugins: [
'karma-chrome-launcher',
'karma-jasmine'
]
我假设计算机上未安装Firefox会导致Karma失败。