Permalink
Browse files

async test for new feature

  • Loading branch information...
1 parent d9e8489 commit e6eaa1ca2fa64e5d8ac4c69a55c3b690eb84c729 @substack committed Jun 12, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 test/async.js
View
@@ -0,0 +1,43 @@
+var falafel = require('../');
+var test = require('tap').test;
+var vm = require('vm');
+
+test('array', function (t) {
+ t.plan(5);
+
+ var src = '(' + function () {
+ var xs = [ 1, 2, [ 3, 4 ] ];
+ var ys = [ 5, 6 ];
+ g([ xs, ys ]);
+ } + ')()';
+
+ var pending = 0;
+ var output = falafel.map(src, function (node) {
+ if (node.type === 'ArrayExpression') {
+ pending ++;
+ setTimeout(function () {
+ node.update('fn(' + node.source() + ')');
+ if (--pending === 0) check();
+ }, Math.random() * 50);
+ }
+ });
+
+ var arrays = [
+ [ 3, 4 ],
+ [ 1, 2, [ 3, 4 ] ],
+ [ 5, 6 ],
+ [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
+ ];
+
+ function check () {
+ vm.runInNewContext(output.source, {
+ fn : function (xs) {
+ t.same(arrays.shift(), xs);
+ return xs;
+ },
+ g : function (xs) {
+ t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
+ },
+ });
+ }
+});

0 comments on commit e6eaa1c

Please sign in to comment.