Skip to content

Commit

Permalink
mostly compatible with node-tap assertions, stubbed out assertion-to-…
Browse files Browse the repository at this point in the history
…TAP logic
  • Loading branch information
James Halliday committed Nov 25, 2012
1 parent da360eb commit 7948e2e
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 6 deletions.
35 changes: 35 additions & 0 deletions example/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var falafel = require('falafel');
var test = require('../');

test('array', function (t) {
t.plan(5);

var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';

var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});

var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
];

Function(['fn','g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
}
);
});
35 changes: 35 additions & 0 deletions example/fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var falafel = require('falafel');
var test = require('../');

test('array', function (t) {
t.plan(5);

var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';

var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});

var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
];

Function(['fn','g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]);
}
);
});
56 changes: 56 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var createDefaultStream = require('./lib/default_stream');
var Render = require('./lib/render');
var Test = require('./lib/test');

exports = module.exports = createHarness();
exports.createHarness = createHarness;
exports.Test = Test;

function createHarness () {
var pending = [];
var running = false;
var out = new Render();

return function (name, conf, cb) {
if (typeof conf === 'function') {
cb = conf;
conf = {};
}
var t = new Test;
out.push(t);

var piped = false;

t.pipe = function () {
piped = true;
};

t.once('pipe', function () {
piped = true;
});

process.nextTick(function () {
if (!piped) out.pipe(createDefaultStream());

var run = function () {
running = true;
cb(t);
};

if (running) {
pending.push(run);
}
else run();
});

t.on('end', function () {
running = false;
process.nextTick(function () {
if (pending.length) pending.shift()()
else out.close()
});
});
};

return out;
}
25 changes: 25 additions & 0 deletions lib/default_stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var Stream = require('stream');

module.exports = function () {
if (typeof process !== 'undefined' && process.stdout
&& typeof process.stdout.pipe === 'function') {
return process.stdout;
}

var out = new Stream;
out.writable = true;

out.write = function (buf) {
console.log(String(buf));
};

out.destroy = function () {
out.emit('close');
};

out.end = function () {
out.emit('close');
};

return out;
};
20 changes: 20 additions & 0 deletions lib/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var Stream = require('stream');

module.exports = Render;

function Render () {
Stream.call(this);
this.readable = true;
}

Render.prototype = new Stream;

Render.prototype.push = function (t) {
t.on('result', function (res) {
console.dir(res);
});
};

Render.prototype.close = function () {
console.log('__END__');
};
Loading

0 comments on commit 7948e2e

Please sign in to comment.