-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.js
98 lines (85 loc) · 2.89 KB
/
widget.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***/
var fs = require("fs");
var deleteFolderRecursive = function(path) {
if( fs.existsSync(path) ) {
fs.readdirSync(path).forEach(function(file){
var curPath = path + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
deleteFolderRecursive("DUMP");
var oldit = it;
it = function() { // eslint-disable-line no-global-assign
var oldF = arguments[1];
arguments[1] = function() {
var path = [];
for(var x = this.test; x.parent; x = x.parent) {
path.push(x.title);
}
global._p_a_t_h_ = ["DUMP"].concat(path.reverse());
return oldF.apply(this, arguments);
};
return oldit.apply(this, arguments);
};
var oldjsonata = jsonata;
jsonata = function(expr) {
// Build test output directories
var x = "";
global._p_a_t_h_.forEach(function(element) {
x += element
.replace(/:/g, "%3A")
.replace(/"/g, "%22")
.replace(/\*/g, "%2A")
.replace(/</g, "%3C")
.replace(/>/g, "%3E")
.replace(/\n/g, "%0A")
.replace(/\?/g, "%3F")
.replace(/\t/g, "%09")
.replace(/\\/g, "%5C")
.replace(/\//g, "%2F")
.replace(/\|/g, "%7C") + "/";
if(!fs.existsSync(x)) {
fs.mkdirSync(x);
}
});
fs.writeFileSync(x + "expression.jsonata", expr);
var expression = oldjsonata.apply(this, arguments);
var boop = {};
var oldassign = expression.assign;
expression.assign = function(name, value) {
// Several tests attempt to bind functions. We can't handle that :-/
boop[name] = value;
return oldassign.apply(this, arguments);
};
var oldevaluate = expression.evaluate;
expression.evaluate = function(input, bindings, callback) {
fs.writeFileSync(x + "input.json", JSON.stringify(input, null, 4));
// Only ONE test case uses this!
boop = Object.assign(boop, bindings);
if(Object.keys(boop).length > 0) {
fs.writeFileSync(x + "bindings.json", JSON.stringify(boop, null, 4));
}
if(typeof callback === 'function') {
var oldcallback = callback;
callback = function(err, value) {
if(arguments.length >= 2) {
fs.writeFileSync(x + "output.json", JSON.stringify(value, null, 4));
}
oldcallback.apply(this, arguments);
};
oldevaluate.apply(this, arguments);
} else {
var value = oldevaluate.apply(this, arguments);
fs.writeFileSync(x + "output.json", JSON.stringify(value, null, 4));
return value;
}
};
return expression;
};
/***/