RequireJS を使用してロードされた mocha 仕様を Karma ランナーに実行させようとしているところに問題があります。残念ながら、フレームワークがロードされているにもかかわらず、仕様が実行されない理由がわかりません。ここに私が望む関連ビットがあります:
// karma.conf.js
// Karma configuration
// Generated on Thu Jun 13 2013 13:38:06 GMT-0500 (CDT)
// base path, that will be used to resolve files and exclude
basePath = '';
// list of files / patterns to load in the browser
files = [
MOCHA,
MOCHA_ADAPTER,
REQUIRE,
REQUIRE_ADAPTER,
// !! libs required for test framework
{pattern: 'test/lib/chai.js', included: false},
// !! put what used to be in your requirejs 'shim' config here
'app/bower_components/angular/angular.js',
'app/bower_components/angular-cookies/angular-cookies.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/bower_components/angular-sanitize/angular-sanitize.js',
'app/bower_components/angular-scenario/angular-scenario.js',
'app/bower_components/jquery/jquery.js',
{pattern: 'app/scripts/**/*.js', included: false},
{pattern: 'test/**/*Spec.js', included: false},
'test/test-main.js'
];
// list of files to exclude
exclude = [
'app/scripts/main.js'
];
// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress'];
// web server port
port = 9876;
// cli runner port
runnerPort = 9100;
// enable / disable colors in the output (reporters and logs)
colors = true;
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_INFO;
// enable / disable watching file and executing tests whenever any file changes
autoWatch = true;
browsers = ['Chrome'];
// If browser does not capture in given timeout [ms], kill it
captureTimeout = 60000;
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = false;
次に、これはrequireJSの読み込みを処理する私のtest-main.jsファイルです
var tests = [];
for (var file in window.__karma__.files) {
if (/Spec\.js$/.test(file)) {
tests.push('../../' + file.replace(/^\/base\//, '').replace(/\.js$/, ''));
}
}
requirejs.config({
baseUrl: '/base/app/scripts/',
paths: {
chai: "../../test/lib/chai",
namespace: "vendor/namespace",
jquery: "../bower_components/jquery/jquery",
bootstrap: "vendor/bootstrap",
angular: "../bower_components/angular/angular",
angularCookies: "../bower_components/angular-cookies/angular-cookies",
angularResource: "../bower_components/angular-resource/angular-resource",
angularSanitize: "../bower_components/angular-sanitize/angular-sanitize",
applicationController: "controllers/application",
gameController: "controllers/game",
gamePresenter: "directives/game-presenter",
}
});
require(tests, function(){
window.__karma__.start();
});
これは私が実行している仕様の例です:
define(['chai', 'namespace','racecar'],
function(chai, namespace, racecar) {
var assert = chai.assert,
expect = chai.expect,
should = chai.should();
// This executes correctly!
var player = new com.angular.racecar.Player();
player.should.be.an('object');
// This never gets run!
describe('Player', function () {
it('should be an object', function () {
var player = new com.angular.racecar.Player();
player.should.be.an('object');
});
});
});
私がテストしているコードの例を次に示します。
(function() {
"use strict";
var Player;
namespace('com.angular.racecar', {
Player: Player = (function() {
function Player() {
this.car = new com.angular.racecar.Car();
return this;
}
return Player;
})()
});
}(this)
出力は単に次のように表示されます。
INFO [Chrome 27.0 (Mac)]: Connected on socket id fc4Kj9T0ppIzp9D0kmdH
Chrome 27.0 (Mac): Executed 0 of 0 SUCCESS (0.192 secs / 0 secs)