Permalink
Browse files

t.log and t.createWindow work

  • Loading branch information...
1 parent 1583149 commit 9f938e039192e04cf11b06ec648012e0ef362880 @substack committed Jun 23, 2012
Showing with 61 additions and 31 deletions.
  1. +14 −11 browser/harness.js
  2. +27 −0 browser/test.js
  3. +16 −19 example/form.js
  4. +3 −1 example/test.js
  5. +1 −0 package.json
View
@@ -1,7 +1,7 @@
var Results = require('tap/lib/tap-results');
var Harness = require('tap/lib/tap-harness');
-var Test = require('tap/lib/tap-test');
+var Test = require('./test');
var output = require('./output');
module.exports = function () {
@@ -15,20 +15,23 @@ module.exports = function () {
output.write(res)
});
harness.results.list.length = 0
- })
-
- var streamEnded = false
+ });
+
+ var streamEnded = false;
harness.on('end', function () {
- //console.error('global ending the stream')
if (!streamEnded) {
harness.results.list.forEach(function (res) {
- output.write(res)
- })
- harness.results.list.length = 0
- output.end()
- streamEnded = true
+ output.write(res);
+ });
+ harness.results.list.length = 0;
+ output.end();
+ streamEnded = true;
}
- })
+ });
+
+ harness.on('log', function (msg) {
+ output.write({ 'log' : msg });
+ });
/*
process.on('unhandledException', function (e) {
View
@@ -0,0 +1,27 @@
+var Test = require('tap/lib/tap-test');
+var inherits = require('util').inherits;
+var schoolbus = require('schoolbus');
+
+inherits(Testling, Test);
+module.exports = Testling;
+
+function Testling (harness, name, conf) {
+ Test.apply(this, arguments);
+ for (var key in Test.prototype) {
+ this[key] = Test.prototype[key].bind(this);
+ }
+
+ for (var key in Testling.prototype) {
+ this[key] = Testling.prototype[key].bind(this);
+ }
+}
+
+Testling.prototype.createWindow = function () {
+ var bus = schoolbus.apply(null, arguments);
+ bus.appendTo(document.body);
+ return bus;
+};
+
+Testling.prototype.log = function (msg) {
+ this.harness.emit('log', msg);
+};
View
@@ -1,25 +1,22 @@
var test = require('../');
-test('login', function (t) {
- var w = t.createWindow('http://localhost:8081');
+test('submit a form', function (t) {
+ t.plan(1);
+
+ var uri = 'http://localhost:7272/test-form/';
+ var w = t.createWindow(uri, { t : t });
w.next(function (win, $) {
- function finish () {
- if (--pending === 0) t.end();
- }
+ t.log('page[0]: ' + win.location.href);
- var form = win.document.getElementsByTagName('form')[0];
-
- t.submitForm(form, function (w) {
- t.equal(w.document.body.innerHTML, 'ACCESS DENIED');
- finish();
- });
-
- $('input[name=user]', form).val('abc');
- $('input[name=pass]', form).val('def');
-
- t.submitForm(form, function (w) {
- t.equal(w.document.body.innerHTML, 'welcome!');
- finish();
- });
+ var form = $('#form')[0];
+ $('input[name=login]').val('beep');
+ $('input[name=passw]').val('boop');
+ $('form').submit();
+ });
+
+ w.next(function (win, $) {
+ t.log('page[1]: ' + win.location.href);
+ t.equal($('#welcome p:first').text(), 'Login successful.');
+ t.end();
});
});
View
@@ -1,6 +1,8 @@
var test = require('../');
test('json parse', function (t) {
- t.deepEqual(JSON.parse('[1,2]'), [1,2]);
+ t.same(JSON.parse('[1,2]'), [1,2]);
+ t.ok(false);
+ t.log('beep boop');
t.end();
});
View
@@ -23,6 +23,7 @@
},
"dependencies" : {
"jsonify" : "~0.0.0",
+ "schoolbus" : "~0.0.1",
"domready" : "~0.2.11",
"optimist" : "~0.3.4",
"tap" : "~0.2.5",

0 comments on commit 9f938e0

Please sign in to comment.