Ho un setup di progetto cordova apache e sto provando ad usare Karma per la prima volta. Ho iniziato il progetto come questo:Eseguito 0 di 0 ERRORE durante l'esecuzione di Karma sul progetto Cordova
karma start test/karma.conf.js --verbose
Ma tutto quello che sto ottenendo è:
INFO [karma]: Karma v0.12.36 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
WARN [web-server]: 404: /favicon.ico
INFO [Chrome 43.0.2357 (Windows 8.1 0.0.0)]: Connected on socket 0_IDnS6qvPg4OhGd7oq4 with id 66015767
Chrome 43.0.2357 (Windows 8.1 0.0.0): Executed 0 of 0 ERROR (0.002 secs/0 secs)
Ho ricontrollato quello che ho fatto contro the docs for configuring requirejs for karma.
karma.conf.js
module.exports = function(config) {
config.set({
basePath: '..',
frameworks: ['jasmine', 'requirejs'],
files: [
{pattern: 'www/lib/ionic/js/*.min.js', included: false},
{pattern: 'www/lib/ionic/js/angular/*.min.js', included: false},
{pattern: 'www/lib/ionic/js/angular-ui/*.min.js', included: false},
{pattern: 'www/js/**/*.js', included: false},
{pattern: 'test/specs/*Spec.js', included: false},
{pattern: 'test/test-app.js', included: true}
],
exclude: [
'www/js/app.js'
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
di test-app.js
var tests = [];
for(var file in window.__karma__.files) {
if(window.__karma__.files.hasOwnProperty(file)) {
if(/Spec\.js$/.test(file)) {
tests.push(file);
}
}
}
requirejs.config({
baseUrl: 'www',
paths: {
'angular': 'lib/ionic/js/angular'
,'angular-ui': 'lib/ionic/js/angular-ui'
},
shim: {
'angular': {exports: 'angular'},
'www/js/controllers': { deps: ['angular']}
},
deps: tests,
callback: window.__karma__.start
})
helloSpec.js
define('helloTests', ['angular'], function() {
describe('UnitTest: Hello', function() {
it('is defined', function() {
expect([1,2,3].length).toEqual(3);
});
});
});
Ed ecco esimo e conseguente debug.html:
<!doctype html>
<html>
<head>
<title>Karma DEBUG RUNNER</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<script type="text/javascript">
window.__karma__ = {
info: function(info) {
if (info.dump && window.console) window.console.log(info.dump);
},
complete: function() {
if (window.console) window.console.log('Skipped ' + this.skipped + ' tests');
},
store: function() {},
skipped: 0,
result: window.console ? function(result) {
if (result.skipped) {
this.skipped++;
return;
}
var msg = result.success ? 'SUCCESS ' : 'FAILED ';
window.console.log(msg + result.suite.join(' ') + ' ' + result.description);
for (var i = 0; i < result.log.length; i++) {
window.console.error(result.log[i]);
}
} : function() {},
loaded: function() {
this.start();
}
};
window.__karma__.config = {"args":[],"useIframe":true,"captureConsole":true};
// All served files with the latest timestamps
window.__karma__.files = {
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/requirejs/require.js': 'f9d7ac1ba78c53a51fd346e3901a5f406f060f44',
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-requirejs/lib/adapter.js': 'f2d8d5976c2bbe89ebe046ac51f393f5547bbc3b',
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/jasmine-core/lib/jasmine-core/jasmine.js': '578a1e5ff14db21b04e2d6db7fd0eda37042440c',
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-jasmine/lib/boot.js': '997181251903c5bcc9659d92edc872a2a4abfa7b',
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-jasmine/lib/adapter.js': '0a69ad1fa10cc8be0a12b241227d3b834f82db4f',
'/base/www/lib/ionic/js/ionic-angular.min.js': '44040e6eeb17077cc79b0985118b15bf1420217d',
'/base/www/lib/ionic/js/ionic.bundle.min.js': '4a4bfece5434ae5c4cebab055aaae274f82050d9',
'/base/www/lib/ionic/js/ionic.min.js': '3e42a6e6700ba9982583b6b5da48861d202d8cfe',
'/base/www/lib/ionic/js/angular/angular-animate.min.js': '6df7f913a45a779638fd60cce18eee17268460d2',
'/base/www/lib/ionic/js/angular/angular-resource.min.js': 'eca9d7e3b12d62b9da13216f1d3b39fcd411f860',
'/base/www/lib/ionic/js/angular/angular-sanitize.min.js': 'b8cf1b04b40df803c16edda80c431ec422b63ad8',
'/base/www/lib/ionic/js/angular/angular.min.js': '09028d3553206017f5ced7249be5641baaea2020',
'/base/www/lib/ionic/js/angular-ui/angular-ui-router.min.js': '0973f9c46d3be867276e941e2e6af9c662a92333',
'/base/www/js/controllers/game.js': '4b67bf783d76ae9f67ac5d569e78319be4a85321',
'/base/www/js/controllers/setup.js': 'b466bd52a326d35700517383a6ceb5b25b3ab44c',
'/base/www/js/directives.js': 'fbc832e4aa0c55a597a57cd4474aa9435bc17bf1',
'/base/www/js/services.js': 'df5339fa9aa37d92974fe59c392b8fb53a71497d',
'/base/test/specs/helloSpec.js': 'b8f2b498922be08d7ff36bafd094132b9c75d357',
'/base/test/test-app.js': '432128c0bcd0257679fb9f4f31ff75a1060f64db'
};
</script>
<!-- Dynamically replaced with <script> tags -->
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/requirejs/require.js"></script>
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-requirejs/lib/adapter.js"></script>
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-jasmine/lib/boot.js"></script>
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-jasmine/lib/adapter.js"></script>
<script type="text/javascript" src="/base/test/test-app.js"></script>
<script type="text/javascript">
window.__karma__.loaded();
</script>
</body>
</html>
sto supponendo che l'elenco dei documenti serviti è tutto richiamati dal requirejs e i tag di script sono ciò che è aggiunto dal karma.
L'uscita della console è:
Skipped 0 tests
così sembra semplicemente non vede le definizioni di prova. Ma quando faccio un passo attraverso il debug e impostare un punto di interruzione al requirejs.config posso vedere che la matrice "test" contiene il file di test:
/base/test/specs/helloSpec.js
posso anche vedere che è stato caricato, cercando in pannello di rete di Chrome . Che elenca:
debug.html
boot.js
jasmine.js
adapter.js
require.js
test-app.js
adapter.js
helloSpec.js