我在项目和业力中使用了AngularJS进行测试。然后我像这样配置了业力:
config.set({
basePath: '../',
frameworks: ['jasmine'],
files: [
// bower:js
'bower_components/jquery/dist/jquery.js',
'bower_components/angular/angular.js',
'bower_components/bootstrap/dist/js/bootstrap.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-mocks/angular-mocks.js',
// endbower
'js/**/*.js',
'test/spec/**/*.js'
],
browsers: [
'PhantomJS'
],
plugins: [
'karma-phantomjs-launcher',
'karma-jasmine'
],
port: 8890
})
像这样咕:着:
grunt.initConfig({
connect: {
testserver: {
options: {
base: 'js/',
hostname: 'localhost',
port: '8889'
}
}
},
karma: {
unit: {
configFile: './test/karma-unit.conf.js',
singleRun: true
}
}
});
grunt.registerTask('test', ['connect', 'karma:unit']);
当我输入' grunt test'时,控制台显示phantomjs无法启动:
Running "connect:testserver" (connect) task
Started connect web server on http://localhost:8889
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.31 server started at http://localhost:8890/
INFO [launcher]: Starting browser PhantomJS
ERROR [launcher]: Cannot start PhantomJS
INFO [launcher]: Trying to start PhantomJS again (1/2).
ERROR [launcher]: Cannot start PhantomJS
INFO [launcher]: Trying to start PhantomJS again (2/2).
ERROR [launcher]: Cannot start PhantomJS
ERROR [launcher]: PhantomJS failed 2 times (cannot start). Giving up.
Warning: Task "karma:unit" failed. Use --force to continue.
Aborted due to warnings.
我该如何解决这个问题?有人能帮助我吗?
答案 0 :(得分:8)
我也碰到了这个问题,似乎是karma-phantomjs2-launcher寻找phantomjs可执行文件的问题。它使用PHANTOMJS_BIN来运行phantomjs,所以我解决了这个问题:
export PHANTOMJS_BIN=/usr/local/bin/phantomjs
只要您可以从命令行运行“phantomjs”并且它可以正常工作,那应该可以这样做。
答案 1 :(得分:6)
安装libfontconfig。假设你在ubuntu上:
sudo apt-get install libfontconfig
这解决了我。
答案 2 :(得分:2)
将package.json中的karma-phantomjs-launcher版本升级到1.0.2并重新安装该软件包。
答案 3 :(得分:0)
也许对某人有帮助。我没有任何正当理由突然得到相同的控制台消息,我只是停止了咕噜声并想重新启动它。
我npm卸载了业力并重新安装了业力。