1
0
mirror of https://github.com/lrsjng/h5ai.git synced 2025-08-08 23:06:46 +02:00

Clean code.

This commit is contained in:
Lars Jung
2015-04-23 00:08:43 +02:00
parent c732fbb363
commit 60b366a7f4
2 changed files with 88 additions and 76 deletions

View File

@@ -2,89 +2,33 @@
// @include "util/*.js" // @include "util/*.js"
(function () { (function () {
'use strict'; 'use strict';
modulejs.define('config', util.uniqObj()); modulejs.define('config', util.uniqObj());
modulejs._private.instances = {}; modulejs._private.instances = {};
window.assert = chai.assert; $(function () {
mocha.setup('bdd'); $('html').removeClass();
mocha.checkLeaks(); util.pinHtml();
util.runMocha();
});
function update() { util.setupMocha();
$('#mocha-overlay .suite').each(function () { describe('unit tests', function () {
var $suite = $(this); // @include "tests/unit/premisses.js"
// @include "tests/unit/modulejs.js"
// @include "tests/unit/libs.js"
// @include "tests/unit/config.js"
// @include "tests/unit/boot.js"
// @include "tests/unit/*/*.js"
});
var tests = $suite.find('.test').length; describe('integration tests', function () {
var passed = $suite.find('.test.pass').length;
var failed = tests - passed;
var $header = $suite.find('> h1 a'); // @include "tests/integration/**/*.js"
var $count = $('<span class="count"><span class="passed">' + passed + '</span><span class="failed">' + failed + '</span></span>'); });
if (!failed) {
$count.find('.failed').remove();
}
$suite.addClass(tests === passed ? 'pass' : 'fail');
$header.find('.count').remove();
$header.append($count);
});
}
var count = 0;
function onTest() {
if (count % 25 === 0) {
update();
}
count += 1;
}
function onEnd() {
$('#mocha-overlay').addClass($('.test.fail').length ? 'fail' : 'pass');
$('#mocha-overlay code').each(function () {
var $code = $(this);
$code.text($code.text().trim().replace(/;\n\s*/g, ';\n'));
});
update();
}
function init() {
$('html').removeClass();
util.pinHtml();
mocha
.run()
.on('test', onTest)
.on('end', onEnd);
}
$(init);
}());
(function () {
'use strict';
describe('unit tests', function () {
// @include "tests/unit/premisses.js"
// @include "tests/unit/modulejs.js"
// @include "tests/unit/libs.js"
// @include "tests/unit/config.js"
// @include "tests/unit/boot.js"
// @include "tests/unit/*/*.js"
});
describe('integration tests', function () {
// @include "tests/integration/**/*.js"
});
}()); }());

68
test/util/mocha.js Normal file
View File

@@ -0,0 +1,68 @@
(function () {
'use strict';
function update() {
$('#mocha-overlay .suite').each(function () {
var $suite = $(this);
var tests = $suite.find('.test').length;
var passed = $suite.find('.test.pass').length;
var failed = tests - passed;
var $header = $suite.find('> h1 a');
var $count = $('<span class="count"><span class="passed">' + passed + '</span><span class="failed">' + failed + '</span></span>');
if (!failed) {
$count.find('.failed').remove();
}
$suite.addClass(tests === passed ? 'pass' : 'fail');
$header.find('.count').remove();
$header.append($count);
});
}
function onEnd() {
$('#mocha-overlay').addClass($('.test.fail').length ? 'fail' : 'pass');
$('#mocha-overlay code').each(function () {
var $code = $(this);
$code.text($code.text().trim().replace(/;\n\s*/g, ';\n'));
});
update();
}
var count = 0;
function onTest() {
if (count % 25 === 0) {
update();
}
count += 1;
}
function setupMocha() {
window.assert = chai.assert;
mocha.setup('bdd');
mocha.checkLeaks();
}
function runMocha() {
mocha.run()
.on('test', onTest)
.on('end', onEnd);
}
window.util = window.util || {};
window.util.setupMocha = setupMocha;
window.util.runMocha = runMocha;
}());