Sembra che ciò che si preferisce sia eseguire un singolo test alla volta tramite karma/gelsomino usando il terminale. Se questo è corretto, questo è quello che faccio per eseguire test su singoli file.
Nota: Io uso il gulp per caricare il Karma, ma questo dovrebbe funzionare solo per usare il karma globale.
Ecco il mio metodo gulp se si sceglie di usarlo.
gulp.task('karma', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js'
}, done);
});
Nei miei karma.config.js
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
// Note the **setFilesUpForTesting** function below. Just change this.
files: setFilesUpForTesting(),
... the rest of file
} // end of module!!!!!
-> Ora sotto il modulo, negli stessi karma.config.js file di aggiungere il seguente
// ------------------------------------------------------------------ >
// Below code is for running either single or all test files.
// To run a single test, just pass in the test file name like so...
// If the test file name was rs-test-me-now_test.js
// To spool up Karma you would enter
// gulp karma --single-test=rs-test-me-now
// To just run all tests
// gulp karma
var fixedPath = [
'public/js/jquery.js',
'public/js/jquery-ui.min.js',
'public/js/foundation.min.js',
'public/js/angular.min.js',
'public/js/angular-mocks.js',
'public/js/angular-route.min.js',
'public/js/angular-sanitize.min.js',
'public/js/angular-cookies.js'
// all the files you want to include when tests run. I removed most of mine, but left some for reference.
];
var baseTestPath = 'public/test/'; // This is the path from root to your test/spec folder that contains all your tests.
function setFilesUpForTesting(){
fixedPath.push(testPath());
return fixedPath;
}
function testPath(){
return singleTestPath() || fullTestPath();
}
function fullTestPath(){
// If your root folder was butter, and all your tests were labeled
// like my_file_spec.js, and all your specs were in a folder under root
// called bread, then the path below would be
// 'butter/bread/**/*_spec.js' Got it?
return 'public/test/**/*_test.js'; // change this to suit your path.
}
function singleTestPath(){
var passedArgument = process.argv.filter(function(item){ if(/--single-test=/.test(item)){return item; }});
if(isEmpty(passedArgument)){ return false; }
return baseTestPath + '**/*' + fileName(passedArgument) + '_test.js';
// change above to fit your path.
}
function fileName(argument){
if(!argument){ return; }
return argument[0].replace('--single-test=', ''); // Change single-test if you want to.
}
function isEmpty(array){
return array.length === 0;
}
Quando voglio eseguire i test, eseguo quindi quanto segue
Per i test di file singoli sorso karma --single-test = test-me-now
// when test-me-now_test.js is the file name.
// and root/pulblic/test/ has all my test files and test folders.
// or root/bread/butter/ and file is called test-me-now_spec.js as in the other example I gave above.
Spero che questo aiuti qualcuno. Fai domande se non riesci a farlo funzionare.
UPDATE
ho appena usato il karma dalla riga di comando e questo funziona come detto sopra quando si utilizza sorso pure.
Se il karma è accessibile dalla riga di comando ora si può fare questo se si sceglie di implementare il file sopra le karma.config.js ...
Nota: devo usare il karma iniziare non corsa,
karma start (will run all tests)
// or for a single test file
karma start --single-test=my-test-file-name // but without the _test.js or _spec.js whatever you call your files. I had reasons for doing this, but you can change the functions above to accept the complete file name if needed.
Nota:
È possibile als o cambia la parola dopo "-" in --single-test = assicurati di aggiornare le informazioni karma.config.js che ho condiviso.
Questo non è nemmeno quasi una risposta, ma io' sono solo curioso Corro più di 600 test piuttosto pesanti che includono casualmente alcune operazioni angolari, DOM e attese asincrone in meno di 2 secondi su una macchina virtuale abbastanza lenta (1 core, 6 GB di RAM, Win7). Non hai pensato di controllare le prestazioni dei test? E potresti definire quanto tempo impiega per eseguire i tuoi test? –
Il codice di test prevede operazioni websocket; Ho uno schema di messaggistica personalizzato sviluppato su ws che sono le unità sotto test quindi non c'è modo di deriderle; i client parlano con un server che ha accumulato ritardi e ritardi incorporati nel client per simulare determinati comportamenti di rete; vale a dire condizioni di gara se si tenta di eseguire un'operazione da due client contemporaneamente ecc; sfortunatamente quei test devono anche essere eseguiti in serie per evitare gare con il server di backend di test. Ad ogni modo, questo non è correlato alla domanda. Trovo difficile credere che karma + gelsomino non fornisca un flusso di lavoro TDD – Dyna
FYI; Sono passato a mocha e sto usando il moka runner basato su nodeJS, che mi consente di eseguire un singolo test passando il flag '--grep' sul livello di cmdline. La storia Karma + gelsomino rimane triste :( – Dyna