-
Notifications
You must be signed in to change notification settings - Fork 1
/
stubbifier_es6.mjs
59 lines (53 loc) · 1.76 KB
/
stubbifier_es6.mjs
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
"use strict";
import * as fs from 'fs';
import * as tar from 'tar';
import * as path from 'path';
class Stubbifier {
constructor(filePath, testingMode = false) {
this.filePath = filePath;
this.stubMap = new Map();
this.testingMode = testingMode;
}
copyFunctionProperties (source, dest) {
// copy the associated properties
try {
if (!source || source === null) {
throw new Error('source is not defined for ' + dest);
}
for (var prop in source) {
dest[prop] = source[prop];
}
Object.keys(source).forEach(function (key) {
dest[key] = source[key];
});
dest.prototype = source.prototype;
}
catch (error) {
// console.error('[copyFunctionProperties] ' + error);
// console.error('Error in: ' + this.filePath);
}
return dest;
}
getStub(functionName) {
return this.stubMap.get(functionName);
}
setStub(functionName, evaledFunString) {
this.stubMap.set(functionName, evaledFunString);
}
getCode(searchName) {
if (!fs.existsSync(this.filePath + '.dir')) {
tar.x({
file: this.filePath + '.dir' + '.tgz',
sync: true,
cwd: path.dirname(this.filePath)
}); // , [this.filePath + '.dir' + '.tgz']);
}
if( this.testingMode) {
console.log("[STUBBIFIER METRICS] FUNCTION STUB HAS BEEN EXPANDED: " + searchName + " --- " + this.filePath);
}
var filename = this.filePath + ".dir/" + searchName + ".BIGG";
return fs.readFileSync(filename, 'utf-8');
}
}
export {Stubbifier};
export default Stubbifier;