@muritavo/testing-toolkit 0.4.1 → 0.5.0
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/dist/client/blockchain.d.ts +2 -1
- package/dist/client/blockchain.js +104 -68
- package/dist/client/blockchain.js.map +1 -1
- package/dist/client/emulator.js +0 -1
- package/dist/client/emulator.js.map +1 -1
- package/dist/native/blockchain.d.ts +13 -3
- package/dist/native/blockchain.js +366 -52
- package/dist/native/blockchain.js.map +1 -1
- package/dist/native/emulator.d.ts +13 -0
- package/dist/native/emulator.js +45 -12
- package/dist/native/emulator.js.map +1 -1
- package/dist/src/client/blockchain.d.ts +13 -0
- package/dist/src/client/blockchain.js +149 -0
- package/dist/src/client/blockchain.js.map +1 -0
- package/dist/src/client/emulator.d.ts +65 -0
- package/dist/src/client/emulator.js +250 -0
- package/dist/src/client/emulator.js.map +1 -0
- package/dist/src/client/utility.d.ts +7 -0
- package/dist/src/client/utility.js +39 -0
- package/dist/src/client/utility.js.map +1 -0
- package/dist/src/native/blockchain.d.ts +50 -0
- package/dist/src/native/blockchain.js +649 -0
- package/dist/src/native/blockchain.js.map +1 -0
- package/dist/src/native/consts.d.ts +5 -0
- package/dist/src/native/consts.js +9 -0
- package/dist/src/native/consts.js.map +1 -0
- package/dist/src/native/emulator.d.ts +49 -0
- package/dist/src/native/emulator.js +274 -0
- package/dist/src/native/emulator.js.map +1 -0
- package/dist/src/types/contract.d.ts +79 -0
- package/dist/src/types/contract.js +31 -0
- package/dist/src/types/contract.js.map +1 -0
- package/dist/src/utility/index.d.ts +1 -0
- package/dist/src/utility/index.js +12 -0
- package/dist/src/utility/index.js.map +1 -0
- package/dist/test/hardhat-configs/hardhat-with-graphql/hardhat.config.d.ts +42 -0
- package/dist/test/hardhat-configs/hardhat-with-graphql/hardhat.config.js +76 -0
- package/dist/test/hardhat-configs/hardhat-with-graphql/hardhat.config.js.map +1 -0
- package/package.json +5 -2
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ChildProcess } from "child_process";
|
|
1
3
|
/**
|
|
2
4
|
* Kills the emulator that was started by this module instance
|
|
3
5
|
*
|
|
4
6
|
* @returns A promise that resolves when the emulator is succesfully killed
|
|
5
7
|
*/
|
|
6
8
|
export declare function killEmulator(): Promise<any>;
|
|
9
|
+
export declare function registerEmulator({ databaseToImport, projectId, suiteId, process, tenantId, }: {
|
|
10
|
+
suiteId: string;
|
|
11
|
+
projectId: string;
|
|
12
|
+
databaseToImport: string;
|
|
13
|
+
tenantId?: string;
|
|
14
|
+
process?: ChildProcess;
|
|
15
|
+
}): Promise<void>;
|
|
7
16
|
/**
|
|
8
17
|
* With this you can start an firebase emulator
|
|
9
18
|
* @param args Check property typings for details
|
|
@@ -18,6 +27,10 @@ export declare function startEmulator(args: {
|
|
|
18
27
|
UIPort: number;
|
|
19
28
|
/** An optional flag to indicate when a new emulator instance should be created */
|
|
20
29
|
suiteId?: string;
|
|
30
|
+
/** Tenant aware auth */
|
|
31
|
+
tenantId?: string;
|
|
32
|
+
/** The starting directory */
|
|
33
|
+
startAtCwd?: string;
|
|
21
34
|
ports: number[];
|
|
22
35
|
shouldSaveData: boolean;
|
|
23
36
|
only: ("functions" | "hosting" | "firestore" | "storage" | "auth")[] | string[];
|
package/dist/native/emulator.js
CHANGED
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.invokeAuthAdmin = exports.startEmulator = exports.killEmulator = void 0;
|
|
42
|
+
exports.invokeAuthAdmin = exports.startEmulator = exports.registerEmulator = exports.killEmulator = void 0;
|
|
43
43
|
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
44
|
var child_process_1 = require("child_process");
|
|
45
45
|
var kill_port_1 = __importDefault(require("kill-port"));
|
|
@@ -85,6 +85,22 @@ function killEmulator() {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
exports.killEmulator = killEmulator;
|
|
88
|
+
function registerEmulator(_a) {
|
|
89
|
+
return __awaiter(this, arguments, void 0, function (_b) {
|
|
90
|
+
var databaseToImport = _b.databaseToImport, projectId = _b.projectId, suiteId = _b.suiteId, process = _b.process, tenantId = _b.tenantId;
|
|
91
|
+
return __generator(this, function (_c) {
|
|
92
|
+
spawnResult = {
|
|
93
|
+
id: suiteId,
|
|
94
|
+
project: projectId,
|
|
95
|
+
database: databaseToImport,
|
|
96
|
+
tenant: tenantId,
|
|
97
|
+
process: process,
|
|
98
|
+
};
|
|
99
|
+
return [2 /*return*/];
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
exports.registerEmulator = registerEmulator;
|
|
88
104
|
/**
|
|
89
105
|
* With this you can start an firebase emulator
|
|
90
106
|
* @param args Check property typings for details
|
|
@@ -99,7 +115,7 @@ function startEmulator(args_1) {
|
|
|
99
115
|
switch (_a.label) {
|
|
100
116
|
case 0:
|
|
101
117
|
suiteId = args.suiteId || args.databaseToImport || "default";
|
|
102
|
-
log("Spawning emulator process");
|
|
118
|
+
log("Spawning emulator process with args", args);
|
|
103
119
|
if (!(suiteId === (spawnResult === null || spawnResult === void 0 ? void 0 : spawnResult.id))) return [3 /*break*/, 1];
|
|
104
120
|
log("Emulator with suite id ".concat(suiteId, " already running"));
|
|
105
121
|
return [2 /*return*/, null];
|
|
@@ -108,16 +124,20 @@ function startEmulator(args_1) {
|
|
|
108
124
|
_a.sent();
|
|
109
125
|
_a.label = 3;
|
|
110
126
|
case 3:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
127
|
+
/** Clears node options so ts-loader is not ovewritten by cypress */
|
|
128
|
+
delete process.env.NODE_OPTIONS;
|
|
129
|
+
log("Spawning emulator with env", process.env);
|
|
130
|
+
registerEmulator({
|
|
131
|
+
suiteId: suiteId,
|
|
132
|
+
projectId: args.projectId,
|
|
133
|
+
databaseToImport: args.databaseToImport,
|
|
134
|
+
tenantId: args.tenantId,
|
|
115
135
|
process: (0, child_process_1.spawn)("firebase emulators:start -P ".concat(args.projectId, " ").concat(args.databaseToImport ? "--import ".concat(args.databaseToImport) : "", " ").concat(args.shouldSaveData ? "--export-on-exit" : "", " ").concat(args.only.length ? "--only=".concat(args.only.join(",")) : ""), {
|
|
116
|
-
cwd:
|
|
136
|
+
cwd: args.startAtCwd,
|
|
117
137
|
env: process.env,
|
|
118
138
|
shell: true,
|
|
119
139
|
}),
|
|
120
|
-
};
|
|
140
|
+
});
|
|
121
141
|
/**
|
|
122
142
|
* This script exists so we can start an emulator from inside cypress
|
|
123
143
|
*/
|
|
@@ -207,7 +227,7 @@ function startEmulator(args_1) {
|
|
|
207
227
|
exports.startEmulator = startEmulator;
|
|
208
228
|
function invokeAuthAdmin(_a) {
|
|
209
229
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
210
|
-
var app, func;
|
|
230
|
+
var app, func, result, e_2;
|
|
211
231
|
var projectId = _b.projectId, port = _b.port, functionName = _b.functionName, params = _b.params;
|
|
212
232
|
return __generator(this, function (_c) {
|
|
213
233
|
switch (_c.label) {
|
|
@@ -215,10 +235,17 @@ function invokeAuthAdmin(_a) {
|
|
|
215
235
|
case 1:
|
|
216
236
|
app = _c.sent();
|
|
217
237
|
func = app[functionName];
|
|
218
|
-
|
|
238
|
+
_c.label = 2;
|
|
219
239
|
case 2:
|
|
220
|
-
_c.
|
|
240
|
+
_c.trys.push([2, 4, , 5]);
|
|
241
|
+
return [4 /*yield*/, func.bind(app).apply(void 0, params)];
|
|
242
|
+
case 3:
|
|
243
|
+
result = _c.sent();
|
|
244
|
+
return [2 /*return*/, result || null];
|
|
245
|
+
case 4:
|
|
246
|
+
e_2 = _c.sent();
|
|
221
247
|
return [2 /*return*/, null];
|
|
248
|
+
case 5: return [2 /*return*/];
|
|
222
249
|
}
|
|
223
250
|
});
|
|
224
251
|
});
|
|
@@ -234,7 +261,13 @@ function _getAuthAdminInstance(projectId, authPort) {
|
|
|
234
261
|
process.env.FIREBASE_AUTH_EMULATOR_HOST = "".concat(consts_1.LOCALHOST_DOMAIN, ":").concat(authPort);
|
|
235
262
|
adminApp[projectId] =
|
|
236
263
|
adminApp[projectId] || initializeApp({ projectId: projectId }, projectId);
|
|
237
|
-
|
|
264
|
+
if (spawnResult.tenant)
|
|
265
|
+
return [2 /*return*/, getAuth(adminApp[projectId])
|
|
266
|
+
.tenantManager()
|
|
267
|
+
.authForTenant(spawnResult.tenant)];
|
|
268
|
+
else
|
|
269
|
+
return [2 /*return*/, getAuth(adminApp[projectId])];
|
|
270
|
+
return [2 /*return*/];
|
|
238
271
|
});
|
|
239
272
|
});
|
|
240
273
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emulator.js","sourceRoot":"","sources":["../../src/native/emulator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,+CAAoD;AACpD,wDAAiC;AACjC,mCAA4C;AAE5C,IAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oCAAoC,CAAC,CAAC;AACnE,IAAI,
|
|
1
|
+
{"version":3,"file":"emulator.js","sourceRoot":"","sources":["../../src/native/emulator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,+CAAoD;AACpD,wDAAiC;AACjC,mCAA4C;AAE5C,IAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oCAAoC,CAAC,CAAC;AACnE,IAAI,WAMH,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,CA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ACjB,QAAQ,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC,EAAE,SAAS,WAAA,EAAE,EAAE,SAAS,CAAC,CAAC;YACjE,IAAI,WAAW,CAAC,MAAM;gBACpB,sBAAO,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;yBAChC,aAAa,EAAE;yBACf,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,EAAC;;gBAClC,sBAAO,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAC;;;;CAC1C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import GenericContract, { MapTypeToJS } from "../types/contract";
|
|
2
|
+
/**
|
|
3
|
+
* For future me: This is needed because when using
|
|
4
|
+
* on cypress-toolkit "startblockchain" and "invokecontract"
|
|
5
|
+
* are run in different contexts, so the port variable cannot be
|
|
6
|
+
* shared.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setPort(_port: number): void;
|
|
9
|
+
export declare function invokeContract<C, M extends keyof C["methods"]>(wallet: string, _contract: C, contractMethodName: M, ...params: Parameters<C["methods"][M]>): Promise<C extends GenericContract<infer ABI> ? (ABI[number] & {
|
|
10
|
+
name: M;
|
|
11
|
+
})["stateMutability"] extends "view" ? MapTypeToJS<(ABI[number] & {
|
|
12
|
+
name: M;
|
|
13
|
+
})["outputs"][0]["type"], []> : never : never>;
|
|
@@ -0,0 +1,149 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.invokeContract = exports.setPort = void 0;
|
|
43
|
+
var web3_1 = __importDefault(require("web3"));
|
|
44
|
+
var port;
|
|
45
|
+
/**
|
|
46
|
+
* For future me: This is needed because when using
|
|
47
|
+
* on cypress-toolkit "startblockchain" and "invokecontract"
|
|
48
|
+
* are run in different contexts, so the port variable cannot be
|
|
49
|
+
* shared.
|
|
50
|
+
*/
|
|
51
|
+
function setPort(_port) {
|
|
52
|
+
port = _port;
|
|
53
|
+
}
|
|
54
|
+
exports.setPort = setPort;
|
|
55
|
+
function _getPort() {
|
|
56
|
+
if (!port)
|
|
57
|
+
throw new Error("Please, indicate the port that the blockchain node is running (by default it runs on 8545) \nusing the setPort from \"@muritavo/testing-toolkit/dist/client/blockchain\"");
|
|
58
|
+
return port;
|
|
59
|
+
}
|
|
60
|
+
/// @ts-expect-error
|
|
61
|
+
function invokeContract(wallet, _contract, contractMethodName) {
|
|
62
|
+
/// @ts-expect-error
|
|
63
|
+
var params = [];
|
|
64
|
+
for (
|
|
65
|
+
/// @ts-expect-error
|
|
66
|
+
var _i = 3;
|
|
67
|
+
/// @ts-expect-error
|
|
68
|
+
_i < arguments.length;
|
|
69
|
+
/// @ts-expect-error
|
|
70
|
+
_i++) {
|
|
71
|
+
/// @ts-expect-error
|
|
72
|
+
params[_i - 3] = arguments[_i];
|
|
73
|
+
}
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var contract, abiDefinition, state, call, web3;
|
|
76
|
+
var _a;
|
|
77
|
+
var _this = this;
|
|
78
|
+
return __generator(this, function (_b) {
|
|
79
|
+
contract = _contract;
|
|
80
|
+
abiDefinition = contract._jsonInterface.find(function (a) { return a.name === contractMethodName; });
|
|
81
|
+
state = abiDefinition.stateMutability;
|
|
82
|
+
if (state === "view")
|
|
83
|
+
return [2 /*return*/, new Promise(function (r, rej) {
|
|
84
|
+
var _a;
|
|
85
|
+
(_a = contract.methods)[contractMethodName].apply(_a, params).call()
|
|
86
|
+
.then(function (result) { return r(result); })
|
|
87
|
+
.catch(function (e) { return rej(e); });
|
|
88
|
+
})];
|
|
89
|
+
call = (_a = contract.methods)[contractMethodName].apply(_a, params).send({
|
|
90
|
+
from: wallet,
|
|
91
|
+
gas: 90000000,
|
|
92
|
+
gasPrice: "90000000000",
|
|
93
|
+
});
|
|
94
|
+
web3 = new web3_1.default(new web3_1.default.providers.HttpProvider("http://".concat("127.0.0.1", ":").concat(_getPort())));
|
|
95
|
+
return [2 /*return*/, new Promise(function (r, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
96
|
+
var txHash, transaction, isMined, e_1;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0:
|
|
100
|
+
_a.trys.push([0, 8, , 9]);
|
|
101
|
+
return [4 /*yield*/, new Promise(function (r, rej) {
|
|
102
|
+
call.on("transactionHash", function (tX) {
|
|
103
|
+
r(tX);
|
|
104
|
+
});
|
|
105
|
+
call.catch(function (e) {
|
|
106
|
+
rej(e);
|
|
107
|
+
});
|
|
108
|
+
})];
|
|
109
|
+
case 1:
|
|
110
|
+
txHash = _a.sent();
|
|
111
|
+
_a.label = 2;
|
|
112
|
+
case 2:
|
|
113
|
+
if (!true) return [3 /*break*/, 7];
|
|
114
|
+
return [4 /*yield*/, web3.eth.getTransactionReceipt(txHash)];
|
|
115
|
+
case 3:
|
|
116
|
+
transaction = _a.sent();
|
|
117
|
+
isMined = !transaction ||
|
|
118
|
+
!transaction.blockHash ||
|
|
119
|
+
transaction.status === undefined
|
|
120
|
+
? undefined // I still don't know if it's loaded
|
|
121
|
+
: !!transaction.status === true;
|
|
122
|
+
if (!(isMined === undefined)) return [3 /*break*/, 5];
|
|
123
|
+
return [4 /*yield*/, new Promise(function (r) { return setTimeout(function () { return r(); }, 1000); })];
|
|
124
|
+
case 4:
|
|
125
|
+
_a.sent();
|
|
126
|
+
return [3 /*break*/, 6];
|
|
127
|
+
case 5:
|
|
128
|
+
if (isMined) {
|
|
129
|
+
r();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
rej(new Error("Transaction failed, check the logs"));
|
|
133
|
+
}
|
|
134
|
+
return [3 /*break*/, 7];
|
|
135
|
+
case 6: return [3 /*break*/, 2];
|
|
136
|
+
case 7: return [3 /*break*/, 9];
|
|
137
|
+
case 8:
|
|
138
|
+
e_1 = _a.sent();
|
|
139
|
+
rej(e_1);
|
|
140
|
+
return [3 /*break*/, 9];
|
|
141
|
+
case 9: return [2 /*return*/];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}); })];
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
exports.invokeContract = invokeContract;
|
|
149
|
+
//# sourceMappingURL=blockchain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockchain.js","sourceRoot":"","sources":["../../../src/client/blockchain.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,8CAAwB;AAExB,IAAI,IAAY,CAAC;AACjB;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,KAAa;IACnC,IAAI,GAAG,KAAK,CAAC;AACf,CAAC;AAFD,0BAEC;AAED,SAAS,QAAQ;IACf,IAAI,CAAC,IAAI;QACP,MAAM,IAAI,KAAK,CACb,0KACoE,CACrE,CAAC;IACJ,OAAO,IAAI,CAAC;AACd,CAAC;AAED,oBAAoB;AACpB,SAAsB,cAAc,CAClC,MAAc,EACd,SAAY,EACZ,kBAAqB;IACrB,oBAAoB;IACpB,gBAAsC;;IADtC,oBAAoB;IACpB,U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EAAE,CAAC,CAAC;wCACR,CAAC,CAAC,CAAC;wCACH,IAAI,CAAC,KAAK,CAAC,UAAC,CAAC;4CACX,GAAG,CAAC,CAAC,CAAC,CAAC;wCACT,CAAC,CAAC,CAAC;oCACL,CAAC,CAAC,EAAA;;gCAPI,MAAM,GAAG,SAOb;;;qCACK,IAAI;gCACW,qBAAM,IAAI,CAAC,GAAG,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAA;;gCAA1D,WAAW,GAAG,SAA4C;gCAE1D,OAAO,GACX,CAAC,WAAW;oCACZ,CAAC,WAAW,CAAC,SAAS;oCACtB,WAAW,CAAC,MAAM,KAAK,SAAS;oCAC9B,CAAC,CAAC,SAAS,CAAC,oCAAoC;oCAChD,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,KAAK,IAAI,CAAC;qCAChC,CAAA,OAAO,KAAK,SAAS,CAAA,EAArB,wBAAqB;gCACvB,qBAAM,IAAI,OAAO,CAAO,UAAC,CAAC,IAAK,OAAA,UAAU,CAAC,cAAM,OAAA,CAAC,EAAE,EAAH,CAAG,EAAE,IAAI,CAAC,EAA3B,CAA2B,CAAC,EAAA;;gCAA3D,SAA2D,CAAC;;;gCAE5D,IAAI,OAAO,EAAE,CAAC;oCACZ,CAAC,EAAE,CAAC;gCACN,CAAC;qCAAM,CAAC;oCACN,GAAG,CAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC;gCACvD,CAAC;gCACD,wBAAM;;;;;gCAIV,GAAG,CAAC,GAAC,CAAC,CAAC;;;;;qBAEV,CAAQ,EAAC;;;CACX;AA5ED,wCA4EC"}
|
|
@@ -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, storage: firebase.storage.Storage) => Promise<void>, storageBucket?: string) => 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: boolean;
|
|
60
|
+
readonly port: number;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export type FirebaseConfigShape = typeof FirebaseConfigEmulatorsShapeExample;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,250 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.clearFirestore = exports.setEmulatorConfig = exports.clearAuth = exports.addAuthUser = exports.setupEmulator = exports.deleteCollection = void 0;
|
|
52
|
+
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
53
|
+
var rules_unit_testing_1 = require("@firebase/rules-unit-testing");
|
|
54
|
+
var consts_1 = require("../native/consts");
|
|
55
|
+
var emulatorConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Deletes a collection from firebase
|
|
58
|
+
* @param projectId The current project id of the emulator instance
|
|
59
|
+
* @param collectionPath The collection path **starting with "/"**
|
|
60
|
+
*/
|
|
61
|
+
var deleteCollection = function (projectId, collectionPath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0: return [4 /*yield*/, (0, node_fetch_1.default)("http://".concat(consts_1.LOCALHOST_DOMAIN, ":").concat(_getPort("firestore"), "/emulator/v1/projects/").concat(projectId, "/databases/(default)/documents").concat(collectionPath), {
|
|
65
|
+
method: "delete",
|
|
66
|
+
})];
|
|
67
|
+
case 1:
|
|
68
|
+
_a.sent();
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}); };
|
|
73
|
+
exports.deleteCollection = deleteCollection;
|
|
74
|
+
/**
|
|
75
|
+
* Gives the developer the possibility to interact with an admin firestore emulator instance
|
|
76
|
+
* @param projectId The current project id of the emulator instance
|
|
77
|
+
* @param cb The callback to be executed
|
|
78
|
+
*/
|
|
79
|
+
var setupEmulator = function (projectId, cb, storageBucket) { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
var testEnv;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0: return [4 /*yield*/, (0, rules_unit_testing_1.initializeTestEnvironment)({
|
|
84
|
+
projectId: projectId,
|
|
85
|
+
firestore: {
|
|
86
|
+
host: consts_1.LOCALHOST_DOMAIN,
|
|
87
|
+
port: _getPort("firestore"),
|
|
88
|
+
},
|
|
89
|
+
storage: {
|
|
90
|
+
host: consts_1.LOCALHOST_DOMAIN,
|
|
91
|
+
port: _getPort("storage"),
|
|
92
|
+
},
|
|
93
|
+
})];
|
|
94
|
+
case 1:
|
|
95
|
+
testEnv = _a.sent();
|
|
96
|
+
return [4 /*yield*/, testEnv.withSecurityRulesDisabled(function (ctx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0: return [4 /*yield*/, cb(ctx.firestore({
|
|
100
|
+
merge: true,
|
|
101
|
+
}), ctx.storage(storageBucket))];
|
|
102
|
+
case 1:
|
|
103
|
+
_a.sent();
|
|
104
|
+
return [2 /*return*/];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}); })];
|
|
108
|
+
case 2:
|
|
109
|
+
_a.sent();
|
|
110
|
+
return [2 /*return*/];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}); };
|
|
114
|
+
exports.setupEmulator = setupEmulator;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a user on the auth emulator allowing him to authenticate to the emulator
|
|
117
|
+
* @param projectId The current project id of the emulator instance
|
|
118
|
+
* @param email The email to authenticate the user with
|
|
119
|
+
* @param password The password to authenticate the user with
|
|
120
|
+
* @param localId A deterministic Id to be used for this user
|
|
121
|
+
*/
|
|
122
|
+
var addAuthUser = function (projectId_1, email_1, password_1) {
|
|
123
|
+
var args_1 = [];
|
|
124
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
|
125
|
+
args_1[_i - 3] = arguments[_i];
|
|
126
|
+
}
|
|
127
|
+
return __awaiter(void 0, __spreadArray([projectId_1, email_1, password_1], args_1, true), void 0, function (projectId, email, password, localId) {
|
|
128
|
+
var result;
|
|
129
|
+
if (localId === void 0) { localId = ""; }
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
switch (_a.label) {
|
|
132
|
+
case 0: return [4 /*yield*/, (0, node_fetch_1.default)("http://".concat(consts_1.LOCALHOST_DOMAIN, ":").concat(_getPort("auth"), "/identitytoolkit.googleapis.com/v1/projects/").concat(projectId, "/accounts"), {
|
|
133
|
+
body: JSON.stringify({
|
|
134
|
+
email: email,
|
|
135
|
+
password: password,
|
|
136
|
+
localId: localId,
|
|
137
|
+
}),
|
|
138
|
+
headers: {
|
|
139
|
+
"content-type": "application/json",
|
|
140
|
+
authorization: "Bearer owner",
|
|
141
|
+
},
|
|
142
|
+
method: "post",
|
|
143
|
+
})];
|
|
144
|
+
case 1:
|
|
145
|
+
result = _a.sent();
|
|
146
|
+
if (result.status > 300)
|
|
147
|
+
throw new Error("Creating account returned ".concat(result.status));
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
exports.addAuthUser = addAuthUser;
|
|
154
|
+
/**
|
|
155
|
+
* Clears all accounts from the auth emulator
|
|
156
|
+
*
|
|
157
|
+
* @param projectId The current project id of the emulator instance
|
|
158
|
+
*/
|
|
159
|
+
var clearAuth = function (projectId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
160
|
+
var result;
|
|
161
|
+
return __generator(this, function (_a) {
|
|
162
|
+
switch (_a.label) {
|
|
163
|
+
case 0: return [4 /*yield*/, (0, node_fetch_1.default)("http://".concat(consts_1.LOCALHOST_DOMAIN, ":").concat(_getPort("auth"), "/emulator/v1/projects/").concat(projectId, "/accounts"), {
|
|
164
|
+
method: "delete",
|
|
165
|
+
})];
|
|
166
|
+
case 1:
|
|
167
|
+
result = _a.sent();
|
|
168
|
+
if (result.status > 300)
|
|
169
|
+
throw new Error("Cleaning accounts returned ".concat(result.status));
|
|
170
|
+
return [2 /*return*/];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}); };
|
|
174
|
+
exports.clearAuth = clearAuth;
|
|
175
|
+
/**
|
|
176
|
+
* Sets the emulator ports config
|
|
177
|
+
* @param config Emulator ports config
|
|
178
|
+
*/
|
|
179
|
+
function setEmulatorConfig(config) {
|
|
180
|
+
emulatorConfig = config;
|
|
181
|
+
}
|
|
182
|
+
exports.setEmulatorConfig = setEmulatorConfig;
|
|
183
|
+
/**
|
|
184
|
+
* Clears all firestore documents from local emulator
|
|
185
|
+
* @param projectId The current project id of the emulator instance
|
|
186
|
+
*/
|
|
187
|
+
var clearFirestore = function (projectId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
188
|
+
var testEnv;
|
|
189
|
+
return __generator(this, function (_a) {
|
|
190
|
+
switch (_a.label) {
|
|
191
|
+
case 0: return [4 /*yield*/, (0, rules_unit_testing_1.initializeTestEnvironment)({
|
|
192
|
+
projectId: projectId,
|
|
193
|
+
firestore: {
|
|
194
|
+
host: consts_1.LOCALHOST_DOMAIN,
|
|
195
|
+
port: _getPort("firestore"),
|
|
196
|
+
},
|
|
197
|
+
})];
|
|
198
|
+
case 1:
|
|
199
|
+
testEnv = _a.sent();
|
|
200
|
+
return [4 /*yield*/, testEnv.clearFirestore()];
|
|
201
|
+
case 2:
|
|
202
|
+
_a.sent();
|
|
203
|
+
testEnv.cleanup();
|
|
204
|
+
return [2 /*return*/];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}); };
|
|
208
|
+
exports.clearFirestore = clearFirestore;
|
|
209
|
+
var FirebaseConfigEmulatorsShapeExample = {
|
|
210
|
+
emulators: {
|
|
211
|
+
auth: {
|
|
212
|
+
port: 9099,
|
|
213
|
+
},
|
|
214
|
+
functions: {
|
|
215
|
+
port: 5001,
|
|
216
|
+
},
|
|
217
|
+
firestore: {
|
|
218
|
+
port: 8080,
|
|
219
|
+
},
|
|
220
|
+
hosting: {
|
|
221
|
+
port: 5000,
|
|
222
|
+
},
|
|
223
|
+
storage: {
|
|
224
|
+
port: 9199,
|
|
225
|
+
},
|
|
226
|
+
pubsub: {
|
|
227
|
+
port: 8055,
|
|
228
|
+
},
|
|
229
|
+
ui: {
|
|
230
|
+
enabled: true,
|
|
231
|
+
port: 4000,
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Guarantees a firebase config has been provided before using the ports
|
|
237
|
+
* @param emulator The emulator type to get the port from
|
|
238
|
+
* @returns The port
|
|
239
|
+
*/
|
|
240
|
+
function _getPort(emulator) {
|
|
241
|
+
if (!emulatorConfig) {
|
|
242
|
+
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");
|
|
243
|
+
}
|
|
244
|
+
var emulatorConfigSet = emulatorConfig.emulators[emulator];
|
|
245
|
+
if (!emulatorConfigSet || !emulatorConfigSet.port) {
|
|
246
|
+
throw new Error("Emulator config not found");
|
|
247
|
+
}
|
|
248
|
+
return emulatorConfigSet.port;
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=emulator.js.map
|