@etohq/test-utils 1.3.0 → 1.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/LICENSE +21 -0
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +113 -39
- package/dist/database.js.map +1 -1
- package/dist/eto-test-runner-utils/bootstrap-app.d.ts.map +1 -1
- package/dist/eto-test-runner-utils/bootstrap-app.js +1 -0
- package/dist/eto-test-runner-utils/bootstrap-app.js.map +1 -1
- package/dist/eto-test-runner-utils/use-db.d.ts +1 -1
- package/dist/eto-test-runner-utils/use-db.d.ts.map +1 -1
- package/dist/eto-test-runner-utils/utils.d.ts +8 -0
- package/dist/eto-test-runner-utils/utils.d.ts.map +1 -1
- package/dist/eto-test-runner-utils/utils.js +15 -0
- package/dist/eto-test-runner-utils/utils.js.map +1 -1
- package/package.json +28 -28
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Etohq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/database.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAezF,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAStD;AAED,wBAAgB,iBAAiB,CAAC,EAChC,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,MAAM,GACP,EAAE;IACD,gBAAgB,EAAE,GAAG,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,OAAO,CAgBV;AAED,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,GAAG,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAA;IACpB,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAEhC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,UAAU,IAAI,gBAAgB,CAAA;IAC9B,WAAW,IAAI,gBAAgB,CAAA;IAC/B,MAAM,IAAI,QAAQ,CAAA;CACnB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,MAAM,GACP,EAAE;IACD,gBAAgB,EAAE,GAAG,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,YAAY,CAiHf;AAED,eAAO,MAAM,iBAAiB,QAAO,GA6FnC,CAAA"}
|
package/dist/database.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.getMikroOrmConfig = getMikroOrmConfig;
|
|
|
6
6
|
exports.getMikroOrmWrapper = getMikroOrmWrapper;
|
|
7
7
|
const postgresql_1 = require("@mikro-orm/postgresql");
|
|
8
8
|
const pg_god_1 = require("pg-god");
|
|
9
|
+
const eto_test_runner_utils_1 = require("./eto-test-runner-utils");
|
|
9
10
|
const DB_HOST = process.env.DB_HOST ?? "localhost";
|
|
10
11
|
const DB_USERNAME = process.env.DB_USERNAME ?? "";
|
|
11
12
|
const DB_PASSWORD = process.env.DB_PASSWORD ?? "";
|
|
@@ -16,15 +17,14 @@ const pgGodCredentials = {
|
|
|
16
17
|
};
|
|
17
18
|
function getDatabaseURL(dbName) {
|
|
18
19
|
const DB_HOST = process.env.DB_HOST ?? "localhost";
|
|
19
|
-
const DB_USERNAME = process.env.DB_USERNAME ?? "";
|
|
20
|
+
const DB_USERNAME = process.env.DB_USERNAME ?? "postgres";
|
|
20
21
|
const DB_PASSWORD = process.env.DB_PASSWORD;
|
|
21
22
|
const DB_NAME = dbName ?? process.env.DB_TEMP_NAME;
|
|
22
23
|
return `postgres://${DB_USERNAME}${DB_PASSWORD ? `:${DB_PASSWORD}` : ""}@${DB_HOST}/${DB_NAME}`;
|
|
23
24
|
}
|
|
24
25
|
function getMikroOrmConfig({ mikroOrmEntities, pathToMigrations, clientUrl, schema, }) {
|
|
25
26
|
const DB_URL = clientUrl ?? getDatabaseURL();
|
|
26
|
-
return {
|
|
27
|
-
type: "postgresql",
|
|
27
|
+
return (0, postgresql_1.defineConfig)({
|
|
28
28
|
clientUrl: DB_URL,
|
|
29
29
|
entities: Object.values(mikroOrmEntities),
|
|
30
30
|
schema: schema ?? process.env.ETO_DB_SCHEMA,
|
|
@@ -36,7 +36,7 @@ function getMikroOrmConfig({ mikroOrmEntities, pathToMigrations, clientUrl, sche
|
|
|
36
36
|
pathTs: pathToMigrations,
|
|
37
37
|
silent: true,
|
|
38
38
|
},
|
|
39
|
-
};
|
|
39
|
+
});
|
|
40
40
|
}
|
|
41
41
|
function getMikroOrmWrapper({ mikroOrmEntities, pathToMigrations, clientUrl, schema, }) {
|
|
42
42
|
return {
|
|
@@ -71,68 +71,142 @@ function getMikroOrmWrapper({ mikroOrmEntities, pathToMigrations, clientUrl, sch
|
|
|
71
71
|
clientUrl: this.clientUrl,
|
|
72
72
|
schema: this.schema,
|
|
73
73
|
});
|
|
74
|
-
// Initializing the ORM
|
|
75
|
-
this.orm = await postgresql_1.MikroORM.init(OrmConfig);
|
|
76
|
-
this.manager = this.orm.em;
|
|
77
74
|
try {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
await this.orm
|
|
75
|
+
this.orm = await postgresql_1.MikroORM.init(OrmConfig);
|
|
76
|
+
this.manager = this.orm.em;
|
|
77
|
+
try {
|
|
78
|
+
await this.orm.getSchemaGenerator().ensureDatabase();
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.error("Error ensuring database:", err);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
|
|
85
|
+
const pendingMigrations = await this.orm
|
|
89
86
|
.getMigrator()
|
|
90
|
-
.
|
|
87
|
+
.getPendingMigrations();
|
|
88
|
+
if (pendingMigrations && pendingMigrations.length > 0) {
|
|
89
|
+
await this.orm
|
|
90
|
+
.getMigrator()
|
|
91
|
+
.up({ migrations: pendingMigrations.map((m) => m.name) });
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
await this.orm.schema.refreshDatabase();
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (this.orm) {
|
|
99
|
+
try {
|
|
100
|
+
await this.orm.close();
|
|
101
|
+
}
|
|
102
|
+
catch (closeError) {
|
|
103
|
+
console.error("Error closing ORM:", closeError);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
this.orm = null;
|
|
107
|
+
this.manager = null;
|
|
108
|
+
throw error;
|
|
94
109
|
}
|
|
95
110
|
},
|
|
96
111
|
async clearDatabase() {
|
|
97
112
|
if (this.orm === null) {
|
|
98
113
|
throw new Error("ORM not configured");
|
|
99
114
|
}
|
|
100
|
-
await this.manager?.execute(`DROP SCHEMA IF EXISTS "${this.schema ?? "public"}" CASCADE;`);
|
|
101
|
-
await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
|
|
102
115
|
try {
|
|
103
|
-
await this.
|
|
116
|
+
await this.manager?.execute(`DROP SCHEMA IF EXISTS "${this.schema ?? "public"}" CASCADE;`);
|
|
117
|
+
await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
|
|
118
|
+
const closePromise = this.orm.close();
|
|
119
|
+
await (0, eto_test_runner_utils_1.execOrTimeout)(closePromise);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error("Error clearing database:", error);
|
|
123
|
+
try {
|
|
124
|
+
await this.orm?.close();
|
|
125
|
+
}
|
|
126
|
+
catch (closeError) {
|
|
127
|
+
console.error("Error during forced ORM close:", closeError);
|
|
128
|
+
}
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
this.orm = null;
|
|
133
|
+
this.manager = null;
|
|
104
134
|
}
|
|
105
|
-
catch { }
|
|
106
|
-
this.orm = null;
|
|
107
|
-
this.manager = null;
|
|
108
135
|
},
|
|
109
136
|
};
|
|
110
137
|
}
|
|
111
138
|
const dbTestUtilFactory = () => ({
|
|
112
139
|
pgConnection_: null,
|
|
113
140
|
create: async function (dbName) {
|
|
114
|
-
|
|
141
|
+
try {
|
|
142
|
+
await (0, pg_god_1.createDatabase)({ databaseName: dbName, errorIfExist: false }, pgGodCredentials);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.error("Error creating database:", error);
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
115
148
|
},
|
|
116
149
|
teardown: async function ({ schema } = {}) {
|
|
117
150
|
if (!this.pgConnection_) {
|
|
118
151
|
return;
|
|
119
152
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
153
|
+
try {
|
|
154
|
+
const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_);
|
|
155
|
+
schema ??= "public";
|
|
156
|
+
await runRawQuery(`SET session_replication_role = 'replica';`);
|
|
157
|
+
const { rows: tableNames } = await runRawQuery(`SELECT table_name
|
|
124
158
|
FROM information_schema.tables
|
|
125
159
|
WHERE table_schema = '${schema}';`);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
160
|
+
const skipIndexPartitionPrefix = "cat_";
|
|
161
|
+
const mainPartitionTables = ["index_data", "index_relation"];
|
|
162
|
+
let hasIndexTables = false;
|
|
163
|
+
for (const { table_name } of tableNames) {
|
|
164
|
+
if (mainPartitionTables.includes(table_name)) {
|
|
165
|
+
hasIndexTables = true;
|
|
166
|
+
}
|
|
167
|
+
if (table_name.startsWith(skipIndexPartitionPrefix) ||
|
|
168
|
+
mainPartitionTables.includes(table_name)) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
await runRawQuery(`DELETE FROM ${schema}."${table_name}";`);
|
|
172
|
+
}
|
|
173
|
+
if (hasIndexTables) {
|
|
174
|
+
await runRawQuery(`TRUNCATE TABLE ${schema}.index_data;`);
|
|
175
|
+
await runRawQuery(`TRUNCATE TABLE ${schema}.index_relation;`);
|
|
176
|
+
}
|
|
177
|
+
await runRawQuery(`SET session_replication_role = 'origin';`);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error("Error during database teardown:", error);
|
|
181
|
+
throw error;
|
|
129
182
|
}
|
|
130
|
-
await runRawQuery(`SET session_replication_role = 'origin';`);
|
|
131
183
|
},
|
|
132
184
|
shutdown: async function (dbName) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
185
|
+
try {
|
|
186
|
+
const cleanupPromises = [];
|
|
187
|
+
if (this.pgConnection_?.context) {
|
|
188
|
+
cleanupPromises.push((0, eto_test_runner_utils_1.execOrTimeout)(this.pgConnection_.context.destroy()));
|
|
189
|
+
}
|
|
190
|
+
if (this.pgConnection_) {
|
|
191
|
+
cleanupPromises.push((0, eto_test_runner_utils_1.execOrTimeout)(this.pgConnection_.destroy()));
|
|
192
|
+
}
|
|
193
|
+
await Promise.all(cleanupPromises);
|
|
194
|
+
return await (0, pg_god_1.dropDatabase)({ databaseName: dbName, errorIfNonExist: false }, pgGodCredentials);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
console.error("Error during database shutdown:", error);
|
|
198
|
+
try {
|
|
199
|
+
await this.pgConnection_?.context?.destroy();
|
|
200
|
+
await this.pgConnection_?.destroy();
|
|
201
|
+
}
|
|
202
|
+
catch (cleanupError) {
|
|
203
|
+
console.error("Error during forced cleanup:", cleanupError);
|
|
204
|
+
}
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
this.pgConnection_ = null;
|
|
209
|
+
}
|
|
136
210
|
},
|
|
137
211
|
});
|
|
138
212
|
exports.dbTestUtilFactory = dbTestUtilFactory;
|
package/dist/database.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;AAeA,wCASC;AAED,8CA0BC;AAkBD,gDA2HC;AAjMD,sDAAyF;AACzF,mCAAqD;AACrD,mEAAuD;AAGvD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW,CAAA;AAClD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAA;AACjD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAA;AAEjD,MAAM,gBAAgB,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,WAAW;IACrB,IAAI,EAAE,OAAO;CACd,CAAA;AAED,SAAgB,cAAc,CAAC,MAAe;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW,CAAA;IAClD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,UAAU,CAAA;IACzD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;IAC3C,MAAM,OAAO,GAAG,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAA;IAElD,OAAO,cAAc,WAAW,GAC9B,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,EACpC,IAAI,OAAO,IAAI,OAAO,EAAE,CAAA;AAC1B,CAAC;AAED,SAAgB,iBAAiB,CAAC,EAChC,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,MAAM,GAMP;IACC,MAAM,MAAM,GAAG,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AAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAA;YACvD,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;gBAC5C,MAAM,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,CAAA;YACrC,CAAC;YAAC,OAAO,YAAY,EAAE,CAAC;gBACtB,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,YAAY,CAAC,CAAA;YAC7D,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QAC3B,CAAC;IACH,CAAC;CACF,CAAC,CAAA;AA7FW,QAAA,iBAAiB,qBA6F5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-app.d.ts","sourceRoot":"","sources":["../../src/eto-test-runner-utils/bootstrap-app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bootstrap-app.d.ts","sourceRoot":"","sources":["../../src/eto-test-runner-utils/bootstrap-app.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AA0BrD,wBAAsB,QAAQ,CAAC,EAC7B,GAAG,EACH,GAAQ,GACT,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;CAAO,GAAG,OAAO,CAAC;IACzD,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B,SAAS,EAAE,YAAY,CAAA;CACxB,CAAC,CAuBD"}
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.startApp = startApp;
|
|
7
|
+
// @ts-ignore
|
|
7
8
|
const get_port_1 = __importDefault(require("get-port"));
|
|
8
9
|
const path_1 = require("path");
|
|
9
10
|
const utils_1 = require("./utils");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-app.js","sourceRoot":"","sources":["../../src/eto-test-runner-utils/bootstrap-app.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"bootstrap-app.js","sourceRoot":"","sources":["../../src/eto-test-runner-utils/bootstrap-app.ts"],"names":[],"mappings":";;;;;AA6BA,4BA6BC;AA1DD,aAAa;AACb,wDAA8B;AAC9B,+BAA8B;AAE9B,mCAA+C;AAC/C,kDAAmD;AAEnD,0CAA0C;AAC1C,KAAK,UAAU,YAAY,CAAC,EAC1B,GAAG,EACH,GAAG,GAAG,EAAE,MACoC,EAAE;IAC9C,IAAA,6BAAqB,EAAC,GAAG,CAAC,CAAA;IAE1B,MAAM,OAAO,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC,OAAO,CAAA;IAE3D,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,MAAM,OAAO,CAAC;QAC5C,SAAS,EAAE,IAAA,cAAO,EAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;KACzC,CAAC,CAAA;IAEF,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAA,kBAAO,GAAE,CAAA;IAE5E,OAAO;QACL,QAAQ;QACR,SAAS;QACT,IAAI,EAAE,IAAI;KACX,CAAA;AACH,CAAC;AAEM,KAAK,UAAU,QAAQ,CAAC,EAC7B,GAAG,EACH,GAAG,GAAG,EAAE,MACoC,EAAE;IAI9C,MAAM,EACJ,SAAS,EACT,QAAQ,EAAE,WAAW,GACtB,GAAG,MAAM,YAAY,CAAC;QACrB,GAAG;QACH,GAAG;KACJ,CAAC,CAAA;IAGF,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,MAAM,IAAA,kBAAU,EAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;QAEjC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,EAAE,EAAE,EAAE,CAAC;YAChD,MAAM,CAAC,EAAE,EAAE,CAAA;QACb,CAAC;IACH,CAAC,CAAA;IAED,OAAO;QACL,QAAQ;QACR,SAAS;KACV,CAAA;AAEH,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { EtoContainer } from "@etohq/framework/types";
|
|
|
3
3
|
/**
|
|
4
4
|
* Initiates the database connection
|
|
5
5
|
*/
|
|
6
|
-
export declare function initDb(): Promise<import("
|
|
6
|
+
export declare function initDb(): Promise<import("@mikro-orm/postgresql").Knex<any, any>>;
|
|
7
7
|
/**
|
|
8
8
|
* Migrates the database
|
|
9
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-db.d.ts","sourceRoot":"","sources":["../../src/eto-test-runner-utils/use-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAGrD;;GAEG;AACH,wBAAsB,MAAM,
|
|
1
|
+
{"version":3,"file":"use-db.d.ts","sourceRoot":"","sources":["../../src/eto-test-runner-utils/use-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAGrD;;GAEG;AACH,wBAAsB,MAAM,4DAS3B;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,SAAS,EAAE,YAAY,iBAO5D;AAED;;GAEG;AACH,wBAAsB,SAAS,CAC7B,SAAS,EAAE,YAAY,EACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,YAAY,iBAexB"}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export declare function applyEnvVarsToProcess(env?: Record<any, any>): void;
|
|
2
|
+
/**
|
|
3
|
+
* Execute a function and return a promise that resolves when the function
|
|
4
|
+
* resolves or rejects when the function rejects or the timeout is reached.
|
|
5
|
+
* @param fn - The function to execute.
|
|
6
|
+
* @param timeout - The timeout in milliseconds.
|
|
7
|
+
* @returns A promise that resolves when the function resolves or rejects when the function rejects or the timeout is reached.
|
|
8
|
+
*/
|
|
9
|
+
export declare function execOrTimeout(fn: Promise<any> | (() => Promise<void>), timeout?: number): Promise<any>;
|
|
2
10
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/eto-test-runner-utils/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,QAI3D"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/eto-test-runner-utils/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,QAI3D;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EACxC,OAAO,GAAE,MAAa,gBASvB"}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyEnvVarsToProcess = applyEnvVarsToProcess;
|
|
4
|
+
exports.execOrTimeout = execOrTimeout;
|
|
4
5
|
const utils_1 = require("@etohq/framework/utils");
|
|
5
6
|
function applyEnvVarsToProcess(env) {
|
|
6
7
|
if ((0, utils_1.isObject)(env)) {
|
|
7
8
|
Object.entries(env).forEach(([k, v]) => (process.env[k] = v));
|
|
8
9
|
}
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Execute a function and return a promise that resolves when the function
|
|
13
|
+
* resolves or rejects when the function rejects or the timeout is reached.
|
|
14
|
+
* @param fn - The function to execute.
|
|
15
|
+
* @param timeout - The timeout in milliseconds.
|
|
16
|
+
* @returns A promise that resolves when the function resolves or rejects when the function rejects or the timeout is reached.
|
|
17
|
+
*/
|
|
18
|
+
async function execOrTimeout(fn, timeout = 5000) {
|
|
19
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
20
|
+
setTimeout(() => reject(new Error("Timeout")), timeout).unref();
|
|
21
|
+
});
|
|
22
|
+
const fnPromise = typeof fn === "function" ? fn() : fn;
|
|
23
|
+
return Promise.race([fnPromise, timeoutPromise]);
|
|
24
|
+
}
|
|
10
25
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/eto-test-runner-utils/utils.ts"],"names":[],"mappings":";;AAEA,sDAIC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/eto-test-runner-utils/utils.ts"],"names":[],"mappings":";;AAEA,sDAIC;AASD,sCAWC;AA1BD,kDAAiD;AAEjD,SAAgB,qBAAqB,CAAC,GAAsB;IAC1D,IAAI,IAAA,gBAAQ,EAAC,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC/D,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,aAAa,CACjC,EAAwC,EACxC,UAAkB,IAAI;IAEtB,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC/C,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,CAAA;IACjE,CAAC,CAAC,CAAA;IAEF,MAAM,SAAS,GAAG,OAAO,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEtD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAA;AAClD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etohq/test-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Test utils for Eto",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -11,11 +11,6 @@
|
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=20"
|
|
13
13
|
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "rimraf dist && tsc --build",
|
|
16
|
-
"watch": "tsc --build --watch",
|
|
17
|
-
"test": "jest --passWithNoTests src"
|
|
18
|
-
},
|
|
19
14
|
"files": [
|
|
20
15
|
"dist",
|
|
21
16
|
"!dist/**/__tests__",
|
|
@@ -25,35 +20,40 @@
|
|
|
25
20
|
"author": "Eto",
|
|
26
21
|
"license": "MIT",
|
|
27
22
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@mikro-orm/
|
|
30
|
-
"@mikro-orm/
|
|
31
|
-
"@mikro-orm/
|
|
32
|
-
"@
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"pg": "
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
23
|
+
"@mikro-orm/core": "6.4.3",
|
|
24
|
+
"@mikro-orm/knex": "6.4.3",
|
|
25
|
+
"@mikro-orm/migrations": "6.4.3",
|
|
26
|
+
"@mikro-orm/postgresql": "6.4.3",
|
|
27
|
+
"@types/jest": "29.5.14",
|
|
28
|
+
"awilix": "8.0.1",
|
|
29
|
+
"jest": "29.7.0",
|
|
30
|
+
"pg": "8.13.0",
|
|
31
|
+
"pg-god": "1.0.12",
|
|
32
|
+
"rimraf": "5.0.2",
|
|
33
|
+
"typescript": "5.8.3",
|
|
34
|
+
"@etohq/framework": "1.5.0"
|
|
40
35
|
},
|
|
41
36
|
"dependencies": {
|
|
42
|
-
"@types/express": "
|
|
43
|
-
"axios": "
|
|
44
|
-
"get-port": "
|
|
45
|
-
"randomatic": "
|
|
37
|
+
"@types/express": "4.17.17",
|
|
38
|
+
"axios": "1.7.7",
|
|
39
|
+
"get-port": "7.1.0",
|
|
40
|
+
"randomatic": "3.1.1"
|
|
46
41
|
},
|
|
47
42
|
"peerDependencies": {
|
|
48
|
-
"@
|
|
49
|
-
"
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
43
|
+
"@mikro-orm/postgresql": "6.4.3",
|
|
44
|
+
"awilix": "8.0.1",
|
|
45
|
+
"@etohq/eto": "1.5.0",
|
|
46
|
+
"@etohq/framework": "1.5.0"
|
|
52
47
|
},
|
|
53
48
|
"peerDependenciesMeta": {
|
|
54
49
|
"@etohq/eto": {
|
|
55
50
|
"optional": true
|
|
56
51
|
}
|
|
57
52
|
},
|
|
58
|
-
"gitHead": "81a7ff73d012fda722f6e9ef0bd9ba0232d37808"
|
|
59
|
-
|
|
53
|
+
"gitHead": "81a7ff73d012fda722f6e9ef0bd9ba0232d37808",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "rimraf dist && tsc --build",
|
|
56
|
+
"watch": "tsc --build --watch",
|
|
57
|
+
"test": "jest --passWithNoTests src"
|
|
58
|
+
}
|
|
59
|
+
}
|