forked from nbqx/estktap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (35 loc) · 1.2 KB
/
index.js
File metadata and controls
39 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var tape = require('tape-catch'),
fakestk = require('fakestk');
module.exports = estktap;
function estktap(mes,script,is_a,targets){
// param target is optional and can be undefined
var targetArr = ( Array.isArray(targets) )? targets.slice(0) : ["undefined"];
// Shift params
if( Array.isArray(is_a) ) targetArr = is_a.slice(0), is_a = undefined;
var tLen = targetArr.length;
// Index array for asynchronous pooping
var targetIndex = Array.apply(null, {length: tLen}).map(Number.call, Number);
if(typeof is_a !== 'function'){
tape(mes,function(t){
for (var i = 0; i < tLen; i++) {
fakestk.run(script,targetArr.pop(),function(err,res){
if(err) return t.fail(err);
var jsobj = (new Function('return '+res))();
t.equal(jsobj,is_a,mes);
if(targetIndex.pop() === 0) t.end();
});
};
});
}else{
tape(mes,function(t){
for (var i = 0; i < tLen; i++) {
fakestk.run(script,targetArr.pop(),function(err,res){
if(err) return t.fail(err);
var jsobj = (new Function('return '+res))();
is_a(jsobj, t);
if(targetIndex.pop() === 0) t.end();
});
};
});
};
};