2013-06-07 19 views
5

Sto provando a creare un nodo boilerplate e sto provando a creare un'attività per eseguire il test Jasmine. Ho la seguente configurazione nei miei Gruntfile.js:Jasmine, Grunt, RequireJS Stalling sull'uscita di test

jasmine: { 
    src : ['static/test/spec/**/*.js'], 
    options: { 
    host: 'http://localhost:<%= connect.test.port %>/', 
    // specs : 'static/test/spec/**/*.js', 
    template: require('grunt-template-jasmine-requirejs'), 
    templateOptions: { 
     requireConfigFile: 'static/test/SpecRunner.js', 
     requireConfig: { 
     baseUrl: './' 
     } 
    } 
    } 
}, 
connect: { 
    test: { 
    port: 8082 
    } 
} 
.... 
grunt.registerTask('jasmine-test', ['connect', 'jasmine']); 

Quando eseguo il compito, non ottengo errori, ma non ho ricevuto oltre questo:

Running "connect:test" (connect) task 
Started connect web server on localhost:8000. 

Running "jasmine:src" (jasmine) task 
Testing jasmine specs via phantom 

Il _SpecRunner Il file .html viene creato e quando visualizzo il file nel browser, non solo non vedo errori, ma vedo anche che il mio test di gelsomino è stato eseguito correttamente. Cosa mi manca che fa appendere il problema?

Cheers,

Kianosh

risposta

1

sono stato in grado di ottenere il vostro esempio lavorando bene, e quello che hai qui funziona bene. Ho fatto alcune modifiche ma ottengo lo stesso risultato. Quello che stai usando è connect, che sta generando un server web locale, quindi i test vengono eseguiti nel browser. Quindi, il tuo compito non è sospeso, sta semplicemente eseguendo il sever.

Ma da come sembra, probabilmente vorrai eseguire i test nel terminale? Se è così, ho una soluzione abbastanza decente per voi:

package.json

{ 

"name": "Jasmine Tests", 
    "description": "Jasmine Testing", 
    "version": "0.0.1", 
    "devDependencies": { 
    "grunt": "0.4.x", 
    "grunt-contrib-watch": "~0.2.0", 
    "grunt-contrib-jshint": "~0.4.3", 
    "grunt-contrib-jasmine": "~0.4.2", 
    "phantomjs": "1.8.2-0", 
    } 
} 

Gruntfile.js

module.exports = function(grunt) { 
    grunt.initConfig({ 
    pkg: grunt.file.readJSON("package.json"), 
    watch: { 
     grunt: { 
     files: ["Gruntfile.js", "package.json"], 
     tasks: "default" 
     }, 
     javascript: { 
     files: ["src/client/**/*.js", "specs/**/*Spec.js"], 
     tasks: "test" 
     } 
    }, 
    jasmine: { 
     src: "src/client/js/*.js", 
     options: { 
     specs: "specs/client/*Spec.js" 
     } 
    }, 
    jshint: { 
     all: [ 
     "Gruntfile.js", 
     "src/**/*.js", 
     "spec/**/*.js" 
     ], 
     options: { 
     jshintrc: ".jshintrc" 
     } 
    } 
    }); 
    grunt.loadNpmTasks("grunt-contrib-watch"); 
    grunt.loadNpmTasks("grunt-contrib-jshint"); 
    grunt.loadNpmTasks("grunt-contrib-jasmine"); 
    grunt.registerTask("test", ["jshint", "jasmine"]); 
    grunt.registerTask("default", ["test"]); 
}; 

È possibile modificare il file stucture a tutto ciò che più vi si addice . Impostazione entrambi questi file eseguire i seguenti comandi:

npm install 

e

grunt test 

o

grunt watch 

Ora ho aggiunto un paio di cose, come jshint, e guardo ... watch è facoltativo, ma è davvero bello avere. jshint è un must nella mia opinione, ma sentitevi liberi di portarlo fuori dalla soluzione.

La chiave in realtà è phantomjs, che consente di eseguire questi test in un browser "fantasma", che viene inviato al terminale.

Sarà inoltre necessario personalizzare le directory in base alle proprie preferenze.

Ho postato un good blog post su questo (vado anche test lato server).

EDIT: Si effettua anche bisogno di un file .jshintrc se si sceglie di seguire questa strada.

.jshintrc

{ 
    "curly" : true, 
    "eqeqeq" : true, 
    "immed" : true, 
    "latedef" : true, 
    "newcap" : true, 
    "noarg" : true, 
    "sub"  : true, 
    "undef" : true, 
    "boss" : true, 
    "eqnull" : true, 
    "node" : true, 
    "es5"  : true, 
    "globals" : { 
    "it"   : false, 
    "xit"  : false, 
    "describe" : false, 
    "xdescribe" : false, 
    "beforeEach" : false, 
    "afterEach" : false, 
    "expect"  : false, 
    "spyOn"  : false 
    } 
} 

Spero che questo aiuti.

+0

Grazie !! quello ha funzionato per me. – Kianosh

Problemi correlati