@muritavo/testing-toolkit 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/client/emulator.d.ts +65 -0
- package/dist/client/emulator.js +230 -0
- package/dist/client/emulator.js.map +1 -0
- package/dist/native/emulator.d.ts +21 -0
- package/dist/native/emulator.js +181 -0
- package/dist/native/emulator.js.map +1 -0
- package/dist/types/contract.d.ts +78 -0
- package/dist/types/contract.js +32 -0
- package/dist/types/contract.js.map +1 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
This is a generalization of the functions used for @muritavo/cypress-toolkit so they can be used with other testing frameworks (like jest for example)
|
|
4
|
+
|
|
5
|
+
# Folder structure
|
|
6
|
+
|
|
7
|
+
There are 2 main folders where the source is located:
|
|
8
|
+
/native - These are pure nodejs based implementations, that require interfacing with nodejs native libraries (e.g. child_process)
|
|
9
|
+
/client - These are implementations that can be used on jsdom or nodejs and (usually) don't require env specific libraries
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import firebase from "firebase/compat";
|
|
2
|
+
/**
|
|
3
|
+
* Deletes a collection from firebase
|
|
4
|
+
* @param projectId The current project id of the emulator instance
|
|
5
|
+
* @param collectionPath The collection path **starting with "/"**
|
|
6
|
+
*/
|
|
7
|
+
export declare const deleteCollection: (projectId: string, collectionPath: string) => Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Gives the developer the possibility to interact with an admin firestore emulator instance
|
|
10
|
+
* @param projectId The current project id of the emulator instance
|
|
11
|
+
* @param cb The callback to be executed
|
|
12
|
+
*/
|
|
13
|
+
export declare const setupEmulator: (projectId: string, cb: (firestore: firebase.firestore.Firestore) => Promise<void>) => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a user on the auth emulator allowing him to authenticate to the emulator
|
|
16
|
+
* @param projectId The current project id of the emulator instance
|
|
17
|
+
* @param email The email to authenticate the user with
|
|
18
|
+
* @param password The password to authenticate the user with
|
|
19
|
+
* @param localId A deterministic Id to be used for this user
|
|
20
|
+
*/
|
|
21
|
+
export declare const addAuthUser: (projectId: string, email: string, password: string, localId?: string) => Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Clears all accounts from the auth emulator
|
|
24
|
+
*
|
|
25
|
+
* @param projectId The current project id of the emulator instance
|
|
26
|
+
*/
|
|
27
|
+
export declare const clearAuth: (projectId: string) => Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Sets the emulator ports config
|
|
30
|
+
* @param config Emulator ports config
|
|
31
|
+
*/
|
|
32
|
+
export declare function setEmulatorConfig(config: FirebaseConfigShape): void;
|
|
33
|
+
/**
|
|
34
|
+
* Clears all firestore documents from local emulator
|
|
35
|
+
* @param projectId The current project id of the emulator instance
|
|
36
|
+
*/
|
|
37
|
+
export declare const clearFirestore: (projectId: string) => Promise<void>;
|
|
38
|
+
declare const FirebaseConfigEmulatorsShapeExample: {
|
|
39
|
+
readonly emulators: {
|
|
40
|
+
readonly auth: {
|
|
41
|
+
readonly port: number;
|
|
42
|
+
};
|
|
43
|
+
readonly functions: {
|
|
44
|
+
readonly port: number;
|
|
45
|
+
};
|
|
46
|
+
readonly firestore: {
|
|
47
|
+
readonly port: number;
|
|
48
|
+
};
|
|
49
|
+
readonly hosting: {
|
|
50
|
+
readonly port: number;
|
|
51
|
+
};
|
|
52
|
+
readonly storage: {
|
|
53
|
+
readonly port: number;
|
|
54
|
+
};
|
|
55
|
+
readonly pubsub: {
|
|
56
|
+
readonly port: number;
|
|
57
|
+
};
|
|
58
|
+
readonly ui: {
|
|
59
|
+
readonly enabled: true;
|
|
60
|
+
readonly port: number;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export declare type FirebaseConfigShape = typeof FirebaseConfigEmulatorsShapeExample;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
exports.clearFirestore = exports.setEmulatorConfig = exports.clearAuth = exports.addAuthUser = exports.setupEmulator = exports.deleteCollection = void 0;
|
|
40
|
+
var node_fetch_1 = require("node-fetch");
|
|
41
|
+
var rules_unit_testing_1 = require("@firebase/rules-unit-testing");
|
|
42
|
+
var emulatorConfig;
|
|
43
|
+
/**
|
|
44
|
+
* Deletes a collection from firebase
|
|
45
|
+
* @param projectId The current project id of the emulator instance
|
|
46
|
+
* @param collectionPath The collection path **starting with "/"**
|
|
47
|
+
*/
|
|
48
|
+
var deleteCollection = function (projectId, collectionPath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0: return [4 /*yield*/, (0, node_fetch_1["default"])("http://localhost:".concat(_getPort("firestore"), "/emulator/v1/projects/").concat(projectId, "/databases/(default)/documents").concat(collectionPath), {
|
|
52
|
+
method: "delete"
|
|
53
|
+
})];
|
|
54
|
+
case 1:
|
|
55
|
+
_a.sent();
|
|
56
|
+
return [2 /*return*/];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}); };
|
|
60
|
+
exports.deleteCollection = deleteCollection;
|
|
61
|
+
/**
|
|
62
|
+
* Gives the developer the possibility to interact with an admin firestore emulator instance
|
|
63
|
+
* @param projectId The current project id of the emulator instance
|
|
64
|
+
* @param cb The callback to be executed
|
|
65
|
+
*/
|
|
66
|
+
var setupEmulator = function (projectId, cb) { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
+
var testEnv;
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0: return [4 /*yield*/, (0, rules_unit_testing_1.initializeTestEnvironment)({
|
|
71
|
+
projectId: projectId,
|
|
72
|
+
firestore: {
|
|
73
|
+
host: "localhost",
|
|
74
|
+
port: _getPort("firestore")
|
|
75
|
+
}
|
|
76
|
+
})];
|
|
77
|
+
case 1:
|
|
78
|
+
testEnv = _a.sent();
|
|
79
|
+
return [4 /*yield*/, testEnv.withSecurityRulesDisabled(function (ctx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
82
|
+
case 0: return [4 /*yield*/, cb(ctx.firestore({
|
|
83
|
+
experimentalForceLongPolling: true,
|
|
84
|
+
merge: true
|
|
85
|
+
}))];
|
|
86
|
+
case 1:
|
|
87
|
+
_a.sent();
|
|
88
|
+
return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}); })];
|
|
92
|
+
case 2:
|
|
93
|
+
_a.sent();
|
|
94
|
+
return [2 /*return*/];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}); };
|
|
98
|
+
exports.setupEmulator = setupEmulator;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a user on the auth emulator allowing him to authenticate to the emulator
|
|
101
|
+
* @param projectId The current project id of the emulator instance
|
|
102
|
+
* @param email The email to authenticate the user with
|
|
103
|
+
* @param password The password to authenticate the user with
|
|
104
|
+
* @param localId A deterministic Id to be used for this user
|
|
105
|
+
*/
|
|
106
|
+
var addAuthUser = function (projectId, email, password, localId) {
|
|
107
|
+
if (localId === void 0) { localId = ""; }
|
|
108
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
109
|
+
var result;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0: return [4 /*yield*/, (0, node_fetch_1["default"])("http://localhost:".concat(_getPort("auth"), "/identitytoolkit.googleapis.com/v1/projects/").concat(projectId, "/accounts"), {
|
|
113
|
+
body: JSON.stringify({
|
|
114
|
+
email: email,
|
|
115
|
+
password: password,
|
|
116
|
+
localId: localId
|
|
117
|
+
}),
|
|
118
|
+
headers: {
|
|
119
|
+
"content-type": "application/json",
|
|
120
|
+
authorization: "Bearer owner"
|
|
121
|
+
},
|
|
122
|
+
method: "post"
|
|
123
|
+
})];
|
|
124
|
+
case 1:
|
|
125
|
+
result = _a.sent();
|
|
126
|
+
if (result.status > 300)
|
|
127
|
+
throw new Error("Creating account returned ".concat(result.status));
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
exports.addAuthUser = addAuthUser;
|
|
134
|
+
/**
|
|
135
|
+
* Clears all accounts from the auth emulator
|
|
136
|
+
*
|
|
137
|
+
* @param projectId The current project id of the emulator instance
|
|
138
|
+
*/
|
|
139
|
+
var clearAuth = function (projectId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
140
|
+
var result;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
switch (_a.label) {
|
|
143
|
+
case 0: return [4 /*yield*/, (0, node_fetch_1["default"])("http://localhost:".concat(_getPort("auth"), "/emulator/v1/projects/").concat(projectId, "/accounts"), {
|
|
144
|
+
method: "delete"
|
|
145
|
+
})];
|
|
146
|
+
case 1:
|
|
147
|
+
result = _a.sent();
|
|
148
|
+
if (result.status > 300)
|
|
149
|
+
throw new Error("Cleaning accounts returned ".concat(result.status));
|
|
150
|
+
return [2 /*return*/];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}); };
|
|
154
|
+
exports.clearAuth = clearAuth;
|
|
155
|
+
/**
|
|
156
|
+
* Sets the emulator ports config
|
|
157
|
+
* @param config Emulator ports config
|
|
158
|
+
*/
|
|
159
|
+
function setEmulatorConfig(config) {
|
|
160
|
+
emulatorConfig = config;
|
|
161
|
+
}
|
|
162
|
+
exports.setEmulatorConfig = setEmulatorConfig;
|
|
163
|
+
/**
|
|
164
|
+
* Clears all firestore documents from local emulator
|
|
165
|
+
* @param projectId The current project id of the emulator instance
|
|
166
|
+
*/
|
|
167
|
+
var clearFirestore = function (projectId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
+
var testEnv;
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0: return [4 /*yield*/, (0, rules_unit_testing_1.initializeTestEnvironment)({
|
|
172
|
+
projectId: projectId,
|
|
173
|
+
firestore: {
|
|
174
|
+
host: "localhost",
|
|
175
|
+
port: _getPort("firestore")
|
|
176
|
+
}
|
|
177
|
+
})];
|
|
178
|
+
case 1:
|
|
179
|
+
testEnv = _a.sent();
|
|
180
|
+
return [4 /*yield*/, testEnv.clearFirestore()];
|
|
181
|
+
case 2:
|
|
182
|
+
_a.sent();
|
|
183
|
+
testEnv.cleanup();
|
|
184
|
+
return [2 /*return*/];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}); };
|
|
188
|
+
exports.clearFirestore = clearFirestore;
|
|
189
|
+
var FirebaseConfigEmulatorsShapeExample = {
|
|
190
|
+
emulators: {
|
|
191
|
+
auth: {
|
|
192
|
+
port: 9099
|
|
193
|
+
},
|
|
194
|
+
functions: {
|
|
195
|
+
port: 5001
|
|
196
|
+
},
|
|
197
|
+
firestore: {
|
|
198
|
+
port: 8080
|
|
199
|
+
},
|
|
200
|
+
hosting: {
|
|
201
|
+
port: 5000
|
|
202
|
+
},
|
|
203
|
+
storage: {
|
|
204
|
+
port: 9199
|
|
205
|
+
},
|
|
206
|
+
pubsub: {
|
|
207
|
+
port: 8055
|
|
208
|
+
},
|
|
209
|
+
ui: {
|
|
210
|
+
enabled: true,
|
|
211
|
+
port: 4000
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Guarantees a firebase config has been provided before using the ports
|
|
217
|
+
* @param emulator The emulator type to get the port from
|
|
218
|
+
* @returns The port
|
|
219
|
+
*/
|
|
220
|
+
function _getPort(emulator) {
|
|
221
|
+
if (!emulatorConfig) {
|
|
222
|
+
throw new Error("You didn't set the emulator config. Provide it by using the following at your cypress support file:\n\nimport { setEmulatorConfig } from '@muritavo/cypress-toolkit/dist/support/emulator'\n...\n...\n...\nbefore() {\n setEmulatorConfig(require(\"THE_PATH_TO_YOUR_FIREBASE_JSON\"))\n}\n");
|
|
223
|
+
}
|
|
224
|
+
var emulatorConfigSet = emulatorConfig.emulators[emulator];
|
|
225
|
+
if (!emulatorConfigSet || !emulatorConfigSet.port) {
|
|
226
|
+
throw new Error("Emulator config not found");
|
|
227
|
+
}
|
|
228
|
+
return emulatorConfigSet.port;
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=emulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emulator.js","sourceRoot":"","sources":["../../src/client/emulator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAmC;AACnC,mEAAyE;AAGzE,IAAI,cAAmC,CAAC;AAExC;;;;GAIG;AACI,IAAM,gBAAgB,GAAG,UAC9B,SAAiB,EACjB,cAAsB;;;oBAEtB,qBAAM,IAAA,uBAAS,EACb,2BAAoB,QAAQ,CAC1B,WAAW,CACZ,mCAAyB,SAAS,2CAAiC,cAAc,CAAE,EACpF;oBACE,MAAM,EAAE,QAAQ;iBACjB,CACF,EAAA;;gBAPD,SAOC,CAAC;;;;KACH,CAAC;AAZW,QAAA,gBAAgB,oBAY3B;AAEF;;;;GAIG;AACI,IAA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;AAIX;;;;GAIG;AACH,SAAS,QAAQ,CAAC,QAAgD;IAChE,IAAI,CAAC,cAAc,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,gSASnB,CAAC,CAAC;KACA;IACD,IAAM,iBAAiB,GAAG,cAAc,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC7D,IAAI,CAAC,iBAAiB,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE;QACjD,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;KAC9C;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kills the emulator that was started by this module instance
|
|
3
|
+
*
|
|
4
|
+
* @returns A promise that resolves when the emulator is succesfully killed
|
|
5
|
+
*/
|
|
6
|
+
export declare function killEmulator(): Promise<any>;
|
|
7
|
+
/**
|
|
8
|
+
* With this you can start an firebase emulator
|
|
9
|
+
* @param args Check property typings for details
|
|
10
|
+
* @returns A promise that resolves when the emulator is ready or fails if the emulator couldn't start or be reached
|
|
11
|
+
*/
|
|
12
|
+
export declare function startEmulator(args: {
|
|
13
|
+
/** The project id used by the emulator */
|
|
14
|
+
projectId: string;
|
|
15
|
+
/** Optionally indicates the database to import data from */
|
|
16
|
+
databaseToImport?: string;
|
|
17
|
+
/** The port where the firebase UI will be running to check if the emulator is up */
|
|
18
|
+
UIPort: number;
|
|
19
|
+
/** An optional flag to indicate when a new emulator instance should be created */
|
|
20
|
+
suiteId?: string;
|
|
21
|
+
}): Promise<null>;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
exports.startEmulator = exports.killEmulator = void 0;
|
|
40
|
+
var node_fetch_1 = require("node-fetch");
|
|
41
|
+
var child_process_1 = require("child_process");
|
|
42
|
+
var log = require("debug")("@muritavo/testing-toolkit/emulator");
|
|
43
|
+
var spawnResult;
|
|
44
|
+
function WaitTimeout(ml) {
|
|
45
|
+
if (ml === void 0) { ml = 200; }
|
|
46
|
+
return new Promise(function (r) {
|
|
47
|
+
setTimeout(function () {
|
|
48
|
+
r();
|
|
49
|
+
}, ml);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Kills the emulator that was started by this module instance
|
|
54
|
+
*
|
|
55
|
+
* @returns A promise that resolves when the emulator is succesfully killed
|
|
56
|
+
*/
|
|
57
|
+
function killEmulator() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
if (!spawnResult)
|
|
61
|
+
return [2 /*return*/, Promise.resolve(null)];
|
|
62
|
+
return [2 /*return*/, new Promise(function (r, rej) {
|
|
63
|
+
try {
|
|
64
|
+
var t_1 = setTimeout(function () {
|
|
65
|
+
spawnResult = undefined;
|
|
66
|
+
rej(new Error("Couldn't kill emulator"));
|
|
67
|
+
}, 10000);
|
|
68
|
+
spawnResult.process.on("close", function () {
|
|
69
|
+
clearTimeout(t_1);
|
|
70
|
+
r(null);
|
|
71
|
+
});
|
|
72
|
+
spawnResult.process.kill("SIGINT");
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.log("Unhandled exception", e);
|
|
76
|
+
r(null);
|
|
77
|
+
}
|
|
78
|
+
})];
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
exports.killEmulator = killEmulator;
|
|
83
|
+
/**
|
|
84
|
+
* With this you can start an firebase emulator
|
|
85
|
+
* @param args Check property typings for details
|
|
86
|
+
* @returns A promise that resolves when the emulator is ready or fails if the emulator couldn't start or be reached
|
|
87
|
+
*/
|
|
88
|
+
function startEmulator(args) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
var suiteId;
|
|
91
|
+
var _this = this;
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
switch (_a.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
suiteId = args.suiteId || args.databaseToImport || "default";
|
|
96
|
+
log("Spawning emulator process");
|
|
97
|
+
if (!(suiteId === (spawnResult === null || spawnResult === void 0 ? void 0 : spawnResult.id))) return [3 /*break*/, 1];
|
|
98
|
+
log("Emulator with suite id ".concat(suiteId, " already running"));
|
|
99
|
+
return [2 /*return*/, null];
|
|
100
|
+
case 1: return [4 /*yield*/, killEmulator()];
|
|
101
|
+
case 2:
|
|
102
|
+
_a.sent();
|
|
103
|
+
_a.label = 3;
|
|
104
|
+
case 3:
|
|
105
|
+
spawnResult = {
|
|
106
|
+
id: suiteId,
|
|
107
|
+
project: args.projectId,
|
|
108
|
+
database: args.databaseToImport,
|
|
109
|
+
process: (0, child_process_1.spawn)("firebase emulators:start -P ".concat(args.projectId, " ").concat(args.databaseToImport ? "--import ".concat(args.databaseToImport) : ""), {
|
|
110
|
+
cwd: undefined,
|
|
111
|
+
env: process.env,
|
|
112
|
+
shell: true
|
|
113
|
+
})
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* This script exists so we can start an emulator from inside cypress
|
|
117
|
+
*/
|
|
118
|
+
return [2 /*return*/, new Promise(function (r, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
119
|
+
var breakLoop, timeout, e_1;
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
switch (_a.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
breakLoop = false;
|
|
124
|
+
timeout = setTimeout(function () {
|
|
125
|
+
breakLoop = true;
|
|
126
|
+
console.error("Could not receive ok from firebase emulator");
|
|
127
|
+
clearTimeout(timeout);
|
|
128
|
+
rej(new Error("Timeout"));
|
|
129
|
+
spawnResult = undefined;
|
|
130
|
+
}, 30000);
|
|
131
|
+
log("Process is killed: ", spawnResult.process.killed);
|
|
132
|
+
log("Process exit code", spawnResult.process.exitCode);
|
|
133
|
+
spawnResult.process.on("error", function (e) {
|
|
134
|
+
clearTimeout(timeout);
|
|
135
|
+
log("Spawning emulator process failed with error", e.message);
|
|
136
|
+
rej(new Error("Spawning emulator process failed with error ".concat(e.message)));
|
|
137
|
+
spawnResult = undefined;
|
|
138
|
+
});
|
|
139
|
+
spawnResult.process.on("message", function (e) {
|
|
140
|
+
log("Emulator start sent message", e.toString());
|
|
141
|
+
});
|
|
142
|
+
spawnResult.process.on("close", function (e) {
|
|
143
|
+
clearTimeout(timeout);
|
|
144
|
+
log("Emulator closed with", e);
|
|
145
|
+
rej(new Error("Emulator closed with code ".concat(e, ". Check the firebse-debug.log for more details")));
|
|
146
|
+
spawnResult = undefined;
|
|
147
|
+
});
|
|
148
|
+
_a.label = 1;
|
|
149
|
+
case 1:
|
|
150
|
+
if (!!breakLoop) return [3 /*break*/, 7];
|
|
151
|
+
_a.label = 2;
|
|
152
|
+
case 2:
|
|
153
|
+
_a.trys.push([2, 4, , 5]);
|
|
154
|
+
log("Checking if emulator is up");
|
|
155
|
+
return [4 /*yield*/, (0, node_fetch_1["default"])("http://localhost:".concat(args.UIPort))];
|
|
156
|
+
case 3:
|
|
157
|
+
_a.sent();
|
|
158
|
+
log("Emulator is up and ready");
|
|
159
|
+
clearTimeout(timeout);
|
|
160
|
+
breakLoop = true;
|
|
161
|
+
r(null);
|
|
162
|
+
return [3 /*break*/, 5];
|
|
163
|
+
case 4:
|
|
164
|
+
e_1 = _a.sent();
|
|
165
|
+
log("Process is killed: ", spawnResult === null || spawnResult === void 0 ? void 0 : spawnResult.process.killed);
|
|
166
|
+
log("Emulator is not ready yet, retrying in 1 sec");
|
|
167
|
+
return [3 /*break*/, 5];
|
|
168
|
+
case 5: return [4 /*yield*/, WaitTimeout(1000)];
|
|
169
|
+
case 6:
|
|
170
|
+
_a.sent();
|
|
171
|
+
return [3 /*break*/, 1];
|
|
172
|
+
case 7: return [2 /*return*/];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}); })];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
exports.startEmulator = startEmulator;
|
|
181
|
+
//# sourceMappingURL=emulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emulator.js","sourceRoot":"","sources":["../../src/native/emulator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAmC;AACnC,+CAAoD;AAEpD,IAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oCAAoC,CAAC,CAAC;AACnE,IAAI,WAKH,CAAC;AACF,SAAS,WAAW,CAAC,EAAQ;IAAR,mBAAA,EAAA,QAAQ;IAC3B,OAAO,IAAI,OAAO,CAAO,UAAC,CAAC;QACzB,UAAU,CAAC;YACT,CAAC,EAAE,CAAC;QACN,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAsB,YAAY;;;YAChC,IAAI,CAAC,WAAW;gBAAE,sBAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAC;YAC/C,sBAAO,IAAI,OAAO,CAAC,UAAC,CAAC,EAAE,GAAG;oBACxB,IAAI;wBACF,IAAM,GAAC,GAAG,UAAU,CAAC;4BACnB,WAAW,GAAG,SAAgB,CAAC;4BAC/B,GAAG,CAAC,IAAI,KAAK,CAA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AC;4CAC/B,GAAG,CACD,IAAI,KAAK,CACP,oCAA6B,CAAC,mDAAgD,CAC/E,CACF,CAAC;4CACF,WAAW,GAAG,SAAgB,CAAC;wCACjC,CAAC,CAAC,CAAC;;;6CACI,CAAC,SAAS;;;;wCAEb,GAAG,CAAC,4BAA4B,CAAC,CAAC;wCAClC,qBAAM,IAAA,uBAAS,EAAC,2BAAoB,IAAI,CAAC,MAAM,CAAE,CAAC,EAAA;;wCAAlD,SAAkD,CAAC;wCACnD,GAAG,CAAC,0BAA0B,CAAC,CAAC;wCAChC,YAAY,CAAC,OAAO,CAAC,CAAC;wCACtB,SAAS,GAAG,IAAI,CAAC;wCACjB,CAAC,CAAC,IAAI,CAAC,CAAC;;;;wCAER,GAAG,CAAC,qBAAqB,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,MAAM,CAAC,CAAC;wCACxD,GAAG,CAAC,8CAA8C,CAAC,CAAC;;4CAEtD,qBAAM,WAAW,CAAC,IAAI,CAAC,EAAA;;wCAAvB,SAAuB,CAAC;;;;;6BAE3B,CAAC,EAAC;;;;CACJ;AAtFD,sCAsFC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Contract, ContractOptions, EventData, PastEventOptions } from "web3-eth-contract";
|
|
2
|
+
declare type ExtractMethods<A extends any[number]> = A extends {
|
|
3
|
+
type: "function";
|
|
4
|
+
} ? A["name"] : never;
|
|
5
|
+
declare type ExtractEvents<A extends any[number]> = A extends {
|
|
6
|
+
type: "event";
|
|
7
|
+
} ? A["name"] : never;
|
|
8
|
+
declare type TypeOrInternalType<T> = T["internalType"] extends unknown ? T["type"] : T["internalType"];
|
|
9
|
+
declare type MapTypeToJS<L, C> = L extends "address" | "uint256" | "uint128" | "uint8" | "string" | "bytes32" ? string : L extends "bool" ? boolean : L extends "tuple" ? TuplifyUnion<C[number], C[number]["name"]> : unknown;
|
|
10
|
+
declare type ExtractFromObj<R extends any[number] & {
|
|
11
|
+
type: "function";
|
|
12
|
+
}> = {
|
|
13
|
+
[K in R["outputs"][number]["name"]]: MapTypeToJS<TypeOrInternalType<R["outputs"][number] & {
|
|
14
|
+
name: K;
|
|
15
|
+
}>, (R["outputs"][number] & {
|
|
16
|
+
name: K;
|
|
17
|
+
})["components"]>;
|
|
18
|
+
};
|
|
19
|
+
export declare type ExtractMethodDefinition<A extends any, N extends (any[number] & {
|
|
20
|
+
type: "function";
|
|
21
|
+
})["name"], R = A[number] & {
|
|
22
|
+
type: "function";
|
|
23
|
+
name: N;
|
|
24
|
+
}> = (...args: TuplifyUnion<(A[number] & {
|
|
25
|
+
type: "function";
|
|
26
|
+
name: N;
|
|
27
|
+
})["inputs"][number], (A[number] & {
|
|
28
|
+
type: "function";
|
|
29
|
+
name: N;
|
|
30
|
+
})["inputs"][number]["name"]>) => {
|
|
31
|
+
call: () => Promise<R extends {
|
|
32
|
+
outputs: {
|
|
33
|
+
length: 1;
|
|
34
|
+
};
|
|
35
|
+
} ? MapTypeToJS<TypeOrInternalType<R["outputs"][0]>, R["outputs"][0]["components"]> : R extends {
|
|
36
|
+
outputs: any;
|
|
37
|
+
} ? ExtractFromObj<R> : void>;
|
|
38
|
+
send: (prop: {
|
|
39
|
+
from: string;
|
|
40
|
+
maxPriorityFeePerGas?: number;
|
|
41
|
+
gas?: number;
|
|
42
|
+
gasPrice?: string;
|
|
43
|
+
}) => Promise<void>;
|
|
44
|
+
};
|
|
45
|
+
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
46
|
+
declare type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
|
|
47
|
+
declare type Push<T extends any[], V> = [...T, V];
|
|
48
|
+
export declare type TuplifyUnion<FUNCS, T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<FUNCS, Exclude<T, L>>, MapTypeToJS<TypeOrInternalType<FUNCS & {
|
|
49
|
+
name: L;
|
|
50
|
+
}>, (FUNCS & {
|
|
51
|
+
name: L;
|
|
52
|
+
})["components"]>>;
|
|
53
|
+
export declare class GenericContract<A extends any = any, E extends string = ExtractEvents<A[number]> | "allEvents"> extends Contract {
|
|
54
|
+
events: Exclude<E, "allEvents">;
|
|
55
|
+
constructor(jsonInterface: A, address?: string, options?: ContractOptions);
|
|
56
|
+
methods: {
|
|
57
|
+
[k in ExtractMethods<A[number]>]: ExtractMethodDefinition<A, k>;
|
|
58
|
+
};
|
|
59
|
+
getPastEvents(event: E): Promise<GenericEventData<A>[]>;
|
|
60
|
+
getPastEvents(event: E, options: PastEventOptions, callback: (error: Error, event: EventData) => void): Promise<GenericEventData<A>[]>;
|
|
61
|
+
getPastEvents(event: E, options: PastEventOptions): Promise<GenericEventData<A>[]>;
|
|
62
|
+
getPastEvents(event: E, callback: (error: Error, event: EventData) => void): Promise<GenericEventData<A>[]>;
|
|
63
|
+
}
|
|
64
|
+
export declare type GenericEventData<E extends any> = EventData & GenericEvent<E>;
|
|
65
|
+
declare type ABIEvent = any[number] & {
|
|
66
|
+
type: "event";
|
|
67
|
+
};
|
|
68
|
+
declare type GenericEvent<ABI extends any, E extends string = ExtractEvents<ABI[number]>> = {
|
|
69
|
+
event: E;
|
|
70
|
+
returnValues: ExtractReturnValues<ABIEvent & {
|
|
71
|
+
name: E;
|
|
72
|
+
}>;
|
|
73
|
+
};
|
|
74
|
+
declare type ExtractReturnValues<E extends ABIEvent> = ExtractInputType<E["inputs"][number]>;
|
|
75
|
+
declare type ExtractInputType<I extends ABIEvent["inputs"][number]> = {
|
|
76
|
+
[k in I["name"]]: MapTypeToJS<TypeOrInternalType<I>, I["components"]>;
|
|
77
|
+
};
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
exports.__esModule = true;
|
|
18
|
+
exports.GenericContract = void 0;
|
|
19
|
+
// @ts-nocheck
|
|
20
|
+
var web3_eth_contract_1 = require("web3-eth-contract");
|
|
21
|
+
var GenericContract = /** @class */ (function (_super) {
|
|
22
|
+
__extends(GenericContract, _super);
|
|
23
|
+
function GenericContract(jsonInterface, address, options) {
|
|
24
|
+
return _super.call(this, jsonInterface, address, options) || this;
|
|
25
|
+
}
|
|
26
|
+
GenericContract.prototype.getPastEvents = function (event, options, callback) {
|
|
27
|
+
return _super.prototype.getPastEvents.call(this, event, options, callback);
|
|
28
|
+
};
|
|
29
|
+
return GenericContract;
|
|
30
|
+
}(web3_eth_contract_1.Contract));
|
|
31
|
+
exports.GenericContract = GenericContract;
|
|
32
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/types/contract.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,cAAc;AACd,uDAK2B;AAkH3B;IAGU,mCAAQ;IAEhB,yBAAY,aAAgB,EAAE,OAAgB,EAAE,OAAyB;eACvE,kBAAM,aAAqC,EAAE,OAAO,EAAE,OAAO,CAAC;IAChE,CAAC;IAkBQ,uCAAa,GAAtB,UACE,KAAU,EACV,OAAa,EACb,QAAc;QAEd,OAAO,iBAAM,aAAa,YAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAQ,CAAC;IAC9D,CAAC;IACH,sBAAC;AAAD,CAAC,AAhCD,CAGU,4BAAQ,GA6BjB;AAhCY,0CAAe"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@muritavo/testing-toolkit",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A series of functions to help with testing",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": ["./dist"],
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "tsc --watch",
|
|
9
|
+
"prepack": "tsc"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Muritavo/testing-toolkit.git"
|
|
14
|
+
},
|
|
15
|
+
"author": "Murilo Oliveira de Araujo",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/Muritavo/testing-toolkit/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/Muritavo/testing-toolkit#readme",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"firebase": "^9.10.0",
|
|
23
|
+
"web3": "^1.8.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@firebase/rules-unit-testing": "^2.0.4",
|
|
27
|
+
"@types/node-fetch": "^2.6.2",
|
|
28
|
+
"node-fetch": "^1",
|
|
29
|
+
"typescript": "^4.8.4"
|
|
30
|
+
}
|
|
31
|
+
}
|