-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocha-start.js
153 lines (140 loc) · 3.77 KB
/
mocha-start.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
global.fetch = function () {}; // remotestorage.js requires a polyfill for global.fetch on node.js 17 and under
(function KVCMochaStubs() {
Object.entries({
uStubSchema(inputData = {}) {
return Object.assign({
ZDRSchemaKey: Math.random().toString(),
ZDRSchemaPath: (function () {
return Math.random().toString();
}),
ZDRSchemaStub: (function () {
return {};
}),
}, inputData);
},
uStubScope(inputData = {}) {
return Object.assign({
ZDRScopeKey: Math.random().toString(),
ZDRScopeDirectory: Math.random().toString(),
}, inputData);
},
uStubCustomClient(inputData = {}) {
const tree = {};
return Object.assign({
ZDRClientWriteFile: (function (param1, param2, param3) {
tree[param1] = param2;
}),
ZDRClientReadFile: (function (inputData) {
return tree[inputData];
}),
ZDRClientListObjects: (function () {
return tree;
}),
ZDRClientDelete: (function (inputData) {}),
}, inputData);
},
uStubRemoteStorage(inputData = {}) {
const RemoteStorage = function (params = {}) {
return (params.modules || []).reduce(function (coll, item) {
const scope = (function () {
const tree = {};
return Object.assign({
storeFile: (function (param1, param2, param3) {
tree[param2] = {
data: param3,
};
}),
getFile: (function (inputData) {
return tree[inputData];
}),
getAll: (function () {
return tree;
}),
getListing: (function () {
return {};
}),
getItemURL: (function () {}),
remove: (function () {}),
}, inputData);
});
return Object.assign(coll, {
[item.name]: {
privateClient: Object.assign(scope(), inputData.FakePublicClient ? {} : inputData),
publicClient: Object.assign(scope(), inputData.FakePublicClient ? inputData : {}),
},
});
}, Object.assign({
access: Object.assign({
claim: (function () {}),
}, inputData),
caching: Object.assign({
enable: (function () {}),
}, inputData),
connect: (function () {}),
reconnect: (function () {}),
disconnect: (function () {}),
on: (function (param1, param2) {
if (param1 !== 'ready') {
return;
}
return param2();
}),
remote: {},
}, inputData));
};
RemoteStorage.Authorize = Math.random().toString();
return RemoteStorage;
},
uStubFission(inputData = {}) {
const tree = {};
return Object.assign({
initialize: (function () {}),
leave: (function () {}),
_fs: Object.assign({
root: Object.assign({
put: (function () {}),
}, inputData),
write: (async function (param1, param2) {
tree[param1] = param2;
}),
cat: (function (inputData) {
const search = '/private';
if (inputData.match(search)) {
inputData = [search, inputData.split(search).pop()].join('');
}
return tree[inputData];
}),
ls: (function () {
return Object.fromEntries(Object.entries(tree).map(function ([key, value]) {
return [key, {
isFile: true,
}];
}));
}),
rm: (async function () {}),
publish: (async function () {}),
exists: (function () {
return true;
}),
}, inputData),
Scenario: {
AuthCancelled: 'AuthCancelled',
NotAuthorised: 'NotAuthorised',
AuthSucceeded: 'AuthSucceeded',
Continuation: 'Continuation',
},
}, inputData);
},
uStubLocalStorage(inputData = {}) {
return Object.assign({
getItem: (function () {}),
setItem: (function () {}),
}, inputData);
},
uStubFilePath () {
return Date.now().toString() + '/' + Date.now().toString();
},
}).map(function (e) {
return global[e.shift()] = e.pop();
});
})();