Making Yeti Work With RequireJS
A proposal to change Yeti so that it can work with tests loaded via AMD.
HTML
<div id="mocha"></div>
<p>(You might also want to look at <a href="https://gist.github.com/wrumsby/5095822">this gist</a>)</p>
CSS
body {
font-family: Open Sans, sans-serif;
}
#mocha.passed:after {
content:'passed';
font-weight: bold;
color: green;
}
p {
margin-top: 3em;
font-size: smaller;
}
JavaScript
/*global window, console, YUI, mocha */
// a very artificial require mock
window.require = function (modules, callback) {
window.setTimeout(function () {
// assume ES5 for this example
modules.forEach(function (value) {
console.log('loading module ' + value);
});
callback();
}, 300);
};
// a very artificial mocha mock
window.mocha = {
run: function () {
console.log('mocha run');
YUI().use('node-base', 'node-core', function (Y) {
Y.one('#mocha').addClass('passed');
});
return this;
}
};
// inject.js mock
(function (global) {
'use strict';
var yui;
global.$yetify = function (options) {
console.log('$yetify called');
yui = YUI({
// The test for require being defined would be more robust in reality
delayUntil: global.require ? 'yeti:start' : 'domready'
}).use(function (Y) {
var runner = mocha.run();
});
};
global.$yetify.run = function () {
if (yui) {
yui.fire('yeti:start');
}
};
}(window));
require(['chai'], function () {
// we would have to do this
$yetify.run();
});
// yeti does this
$yetify();