Skip to content
Browse files

a bit more working on refreshes but not quite

  • Loading branch information...
1 parent 3cccc07 commit 55e9532f4f1f7c17046b8ee7a334267eacb00274 @substack committed
Showing with 95 additions and 80 deletions.
  1. +87 −73 browser/main.js
  2. +7 −1 browser/test.js
  3. +0 −3 server.js
  4. +1 −3 test/a.js
View
160 browser/main.js
@@ -17,60 +17,70 @@ function createTestElement (name, refreshFn) {
progress : jadeify('progress.jade')[0].outerHTML,
ok : 0,
fail : 0,
- }).appendTo($('#tests'));
-
- box.find('.title .refresh')
- .mouseover(function () {
- $(this).attr('src', 'images/refresh_hover.png');
- })
- .mouseout(function () {
- $(this).attr('src', 'images/refresh.png');
- })
- .click(function (ev) {
- ev.stopPropagation();
- refreshFn();
- })
- ;
-
- var progress = box.find('.progress');
- var pWidth = progress.width();
- var pHeight = progress.height();
-
- progress.ready(function () {
- progress.find('.finished img').width(pWidth).height(pHeight);
- progress.find('.remaining img').width(pWidth).height(pHeight);
- progress.find('.percent').width(pWidth);
});
+ box.render = function () {
+ box.find('.title .refresh')
+ .mouseover(function () {
+ $(this).attr('src', 'images/refresh_hover.png');
+ })
+ .mouseout(function () {
+ $(this).attr('src', 'images/refresh.png');
+ })
+ .click(function (ev) {
+ ev.stopPropagation();
+ refreshFn();
+ })
+ ;
+
+ var progress = box.find('.progress');
+ var pWidth = progress.width();
+ var pHeight = progress.height();
+
+ progress.ready(function () {
+ progress.find('.finished img').width(pWidth).height(pHeight);
+ progress.find('.remaining img').width(pWidth).height(pHeight);
+ progress.find('.percent').width(pWidth);
+ });
+
+ box.find('.title').toggle(box.expand, box.collapse);
+ };
+
box.complete = function (p) {
- if (box !== total) {
- var ran = 0, planned = 0;
- total.tests.forEach(function (t) {
- ran += t.count;
- if (!t.running) {
- planned += t.count;
- }
- else if (t.planned) {
- planned += t.planned;
- }
- else {
- planned = undefined;
- }
- });
+ box.ready(function () {
+ var progress = box.find('.progress');
+ var pWidth = progress.width();
+ var pHeight = progress.height();
- if (planned) total.complete(ran / planned);
- }
-
- progress.find('.finished').width(
- Math.min(pWidth, Math.floor(p * pWidth))
- );
- progress.find('.percent').text(
- Math.min(100, Math.floor(p * 100)) + ' %'
- );
+ if (box !== total) {
+ var ran = 0, planned = 0;
+ total.tests.forEach(function (t) {
+ ran += t.count;
+ if (!t.running) {
+ planned += t.count;
+ }
+ else if (t.planned) {
+ planned += t.planned;
+ }
+ else {
+ planned = undefined;
+ }
+ });
+
+ if (planned) total.complete(ran / planned);
+ }
+
+ progress.find('.finished').width(
+ Math.min(pWidth, Math.floor(p * pWidth))
+ );
+ progress.find('.percent').text(
+ Math.min(100, Math.floor(p * 100)) + ' %'
+ );
- if (p >= 1 && !box.find('.title').hasClass('fail')) {
- box.find('.title').removeClass('ok').addClass('all-ok');
- }
+ if (p >= 1 && !box.find('.title').hasClass('fail')) {
+ box.find('.title').removeClass('ok').addClass('all-ok');
+ }
+ });
};
function toggleImage () {
@@ -101,8 +111,6 @@ function createTestElement (name, refreshFn) {
}
};
- box.find('.title').toggle(box.expand, box.collapse);
-
return box;
}
@@ -122,6 +130,8 @@ $(window).ready(function reload () {
// somehow stop all the tests first...
reload();
});
+ total.appendTo('#tests');
+ total.render();
total.tests = [];
Object.keys(require.modules)
@@ -146,27 +156,31 @@ var boxes = [];
function runTest (file, key, test) {
running[key] = Object.keys(test);
- Object.keys(test).forEach(function loadTest (name) {
- var box = createTestElement(file + ' : ' + name, function () {
- // first somehow stop the test if it's running
-
- if (!running[key]) running[key] = [];
-
- var b = loadTest(name);
- //var shouldExpand = false;
-
- if (box.find('.more').is(':visible')) {
- //shouldExpand = true;
- b.expand(0);
- }
-
- box.replaceWith(b);
- //b.expand();
-
- //runTest(file, key, test);
- });
- boxes.push(box);
+ Object.keys(test).map(function (name) {
+ var b = loadTest(file, key, name, test);
+ b.appendTo('#tests');
+ b.render();
+ });
+}
+
+function loadTest (file, key, name, test) {
+ var box = createTestElement(file + ' : ' + name, function () {
+ // first somehow stop the test if it's running
+
+ if (!running[key]) running[key] = [];
+
+ var b = loadTest(file, key, name, test);
+
+ if (box.find('.more').is(':visible')) {
+ b.expand(0);
+ }
+ box.replaceWith(b);
+ b.render();
+ });
+ boxes.push(box);
+
+ box.ready(function () {
var t = new Test(name, box.find('div .frames'));
total.tests.push(t);
@@ -317,7 +331,7 @@ function runTest (file, key, test) {
catch (err) {
t.emit('fail', 'throw', null, null, err);
}
-
- return box;
});
+
+ return box;
}
View
8 browser/test.js
@@ -1,5 +1,6 @@
var EventEmitter = require('events').EventEmitter;
var traverse = require('traverse');
+var jquery = require('jquery');
var Test = module.exports = function (name, frameTarget) {
this.name = name;
@@ -28,7 +29,12 @@ Test.prototype.createWindow = function (href, cb) {
if (cb) {
var fn = function () {
process.nextTick(function () {
- cb(win)
+ cb(win, function (x) {
+ return arguments.length === 1
+ ? jquery(x, win.document)
+ : jquery.apply(null, arguments)
+ ;
+ })
});
};
View
3 server.js
@@ -30,9 +30,6 @@ var bundle = browserify({
mount : argv.mount + '/browserify.js',
})
.require({ jquery : 'jquery-browserify' })
- .require(__dirname + '/browser/jquery.js', {
- target : '_tests/node_modules/jquery/index.js'
- })
.use(jadeify(__dirname + '/views'))
.addEntry(__dirname + '/browser/main.js')
;
View
4 test/a.js
@@ -1,9 +1,7 @@
exports['sign in'] = function (t) {
t.plan(10);
- t.createWindow('/', function (window) {
- var $ = require('jquery')(window);
-
+ t.createWindow('/', function (window, $) {
var form = $('#sign-in-form');
t.ok(form[0], 'form element exists');
var email = $(form[0].elements['sign-in.email']);

0 comments on commit 55e9532

Please sign in to comment.
Something went wrong with that request. Please try again.