Permalink
Browse files

node harness with t.log() and stubbed out t.createWindow()

  • Loading branch information...
1 parent dbec17a commit 0307525a8716f15e07c80376d7866d77b2162e9f @substack committed Jul 1, 2012
Showing with 70 additions and 3 deletions.
  1. +1 −2 index.js
  2. +44 −0 lib/harness/index.js
  3. +24 −0 lib/harness/test.js
  4. +1 −1 package.json
View
@@ -1,2 +1 @@
-var tap = require('tap');
-module.exports = tap.test;
+module.exports = require('./lib/harness')().test;
View
@@ -0,0 +1,44 @@
+var Harness = require('tap/lib/tap-harness');
+var Test = require('./test');
+var TapProducer = require('tap/lib/tap-producer');
+
+module.exports = function () {
+ var harness = new Harness(Test);
+ harness.test = harness.test.bind(harness);
+ harness.plan = harness.plan.bind(harness);
+
+ var output = this.output = new TapProducer;
+ output.pipe(process.stdout);
+
+ harness.on('childEnd', function (child) {
+ output.write(child.conf.name || '(unnamed test)')
+ harness.results.list.forEach(function (res) {
+ output.write(res);
+ });
+ harness.results.list.length = 0
+ });
+
+ var streamEnded = false
+ harness.on('end', function () {
+ if (!streamEnded) {
+ harness.results.list.forEach(function (res) {
+ output.write(res);
+ });
+ harness.results.list.length = 0;
+ output.end();
+ streamEnded = true;
+ }
+ });
+
+ harness.on('log', function (msg) {
+ process.stdout.write(String(msg).split('\n')
+ .map(function (x) { return '>> ' + x })
+ .join('\n') + '\n'
+ );
+ });
+
+ process.on('unhandledException', function (e) {
+ harness.bailout('unhandled exception: ' + e.message)
+ });
+ return harness
+};
View
@@ -0,0 +1,24 @@
+var Test = require('tap/lib/tap-test');
+var inherits = require('util').inherits;
+
+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 () {
+ throw new Error('createWindow not yet implemented for node');
+};
+
+Testling.prototype.log = function (msg) {
+ this.harness.emit('log', msg);
+};
View
@@ -1,7 +1,7 @@
{
"name" : "testling",
"description" : "write tests for browser code",
- "version" : "0.2.3",
+ "version" : "0.2.4",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/testling.git"

1 comment on commit 0307525

@Raynos
Raynos commented on 0307525 Jul 1, 2012

bad ass.

Please sign in to comment.