2015-03-05 27 views
6

Ho utilizzato AngularJS nel mio progetto e il karma da testare. Poi ho configurato il karma in questo modo:phantomjs non può essere avviato

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 

}) 

E grugnito in questo modo:

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']); 

Quando digito 'test grugnito', la console mostra che phantomjs non può iniziare:

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. 

Come posso risolvere questo? Qualcuno può aiutarmi?

+0

Il tuo PhantomJS è installato a livello globale? Che cosa dice la tua variabile env PHANTOMJS_BIN? –

+0

Ho lo stesso problema, il mio output è: ERRORE [launcher]: impossibile avviare PhantomJS \t Errore: spawn EACCES –

+0

correlati: http://stackoverflow.com/questions/31966434/karma-chrome-failed-2-times- can not-start-giving-up/42700178 # 42700178 –

risposta

5

Installare libfontconfig. Dando per scontato che su Ubuntu:

sudo apt-get install libfontconfig

Questo risolto per me.

-1

Se hai installato il browser Chrome sul tuo computer, passa ad esso.

Nell'array di browser annota Chrome invece di PhantomJS e nell'array plugins utilizzare karma-chrome-launcher.

karma-chrome-launcher è disponibile come un altro pacchetto di nodi, deve essere installato.

browsers: [ 
     'Chrome' 
    ], 
    plugins: 
     'karma-chrome-launcher', 
     'karma-jasmine' 
    ], 
7

mi sono imbattuto in questo troppo, sembrava essere un problema con cui il karma-phantomjs2-launcher cerca l'eseguibile phantomjs. Esso utilizza PHANTOMJS_BIN per eseguire phantomjs, così ho risolto in questo modo:

export PHANTOMJS_BIN=/usr/local/bin/phantomjs 

Finché è possibile eseguire "phantomjs" dalla riga di comando troppo e funziona, che dovrebbe probabilmente farlo.

+1

Mi ha salvato MOLTO tempo. Grazie! –

+0

Questo ha funzionato per me su macOS sierra (v10.2). Grazie! – accraze

2

Aggiornamento di karma-phantomjs-launcher versione 1.0.2 in package.json e reinstallare il pacchetto.

+1

Ha lavorato per me nel 2017 – mles

0

Forse aiuta qualcuno. Ho ricevuto gli stessi messaggi della console all'improvviso senza motivi validi, ho appena smesso di grugnire e volevo riavviarlo.

I npm ha disinstallato il karma e ha reinstallato il karma.

Problemi correlati