@deenruv/testing 1.0.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 +23 -0
- package/README.md +5 -0
- package/lib/config/test-config.d.ts +26 -0
- package/lib/config/test-config.js +70 -0
- package/lib/config/test-config.js.map +1 -0
- package/lib/config/testing-asset-preview-strategy.d.ts +13 -0
- package/lib/config/testing-asset-preview-strategy.js +21 -0
- package/lib/config/testing-asset-preview-strategy.js.map +1 -0
- package/lib/config/testing-asset-storage-strategy.d.ts +18 -0
- package/lib/config/testing-asset-storage-strategy.js +47 -0
- package/lib/config/testing-asset-storage-strategy.js.map +1 -0
- package/lib/config/testing-entity-id-strategy.d.ts +11 -0
- package/lib/config/testing-entity-id-strategy.js +22 -0
- package/lib/config/testing-entity-id-strategy.js.map +1 -0
- package/lib/create-test-environment.d.ts +57 -0
- package/lib/create-test-environment.js +47 -0
- package/lib/create-test-environment.js.map +1 -0
- package/lib/data-population/clear-all-tables.d.ts +5 -0
- package/lib/data-population/clear-all-tables.js +32 -0
- package/lib/data-population/clear-all-tables.js.map +1 -0
- package/lib/data-population/mock-data.service.d.ts +21 -0
- package/lib/data-population/mock-data.service.js +108 -0
- package/lib/data-population/mock-data.service.js.map +1 -0
- package/lib/data-population/populate-customers.d.ts +5 -0
- package/lib/data-population/populate-customers.js +30 -0
- package/lib/data-population/populate-customers.js.map +1 -0
- package/lib/data-population/populate-for-testing.d.ts +7 -0
- package/lib/data-population/populate-for-testing.js +42 -0
- package/lib/data-population/populate-for-testing.js.map +1 -0
- package/lib/error-result-guard.d.ts +65 -0
- package/lib/error-result-guard.js +85 -0
- package/lib/error-result-guard.js.map +1 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +31 -0
- package/lib/index.js.map +1 -0
- package/lib/initializers/initializers.d.ts +14 -0
- package/lib/initializers/initializers.js +24 -0
- package/lib/initializers/initializers.js.map +1 -0
- package/lib/initializers/mysql-initializer.d.ts +10 -0
- package/lib/initializers/mysql-initializer.js +43 -0
- package/lib/initializers/mysql-initializer.js.map +1 -0
- package/lib/initializers/postgres-initializer.d.ts +10 -0
- package/lib/initializers/postgres-initializer.js +41 -0
- package/lib/initializers/postgres-initializer.js.map +1 -0
- package/lib/initializers/sqljs-initializer.d.ts +19 -0
- package/lib/initializers/sqljs-initializer.js +55 -0
- package/lib/initializers/sqljs-initializer.js.map +1 -0
- package/lib/initializers/test-db-initializer.d.ts +42 -0
- package/lib/initializers/test-db-initializer.js +3 -0
- package/lib/initializers/test-db-initializer.js.map +1 -0
- package/lib/simple-graphql-client.d.ts +86 -0
- package/lib/simple-graphql-client.js +229 -0
- package/lib/simple-graphql-client.js.map +1 -0
- package/lib/test-server.d.ts +45 -0
- package/lib/test-server.js +123 -0
- package/lib/test-server.js.map +1 -0
- package/lib/testing-logger.d.ts +67 -0
- package/lib/testing-logger.js +82 -0
- package/lib/testing-logger.js.map +1 -0
- package/lib/types.d.ts +42 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/create-upload-post-data.d.ts +23 -0
- package/lib/utils/create-upload-post-data.js +55 -0
- package/lib/utils/create-upload-post-data.js.map +1 -0
- package/lib/utils/get-superadmin-context.d.ts +10 -0
- package/lib/utils/get-superadmin-context.js +40 -0
- package/lib/utils/get-superadmin-context.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.populateForTesting = void 0;
|
|
4
|
+
const generated_types_1 = require("@deenruv/common/lib/generated-types");
|
|
5
|
+
const cli_1 = require("@deenruv/core/cli");
|
|
6
|
+
const populate_customers_1 = require("./populate-customers");
|
|
7
|
+
/**
|
|
8
|
+
* Clears all tables from the database and populates with (deterministic) random data.
|
|
9
|
+
*/
|
|
10
|
+
async function populateForTesting(config, bootstrapFn, options) {
|
|
11
|
+
var _a;
|
|
12
|
+
config.dbConnectionOptions.logging = false;
|
|
13
|
+
const logging = options.logging === undefined ? true : options.logging;
|
|
14
|
+
const originalRequireVerification = config.authOptions.requireVerification;
|
|
15
|
+
config.authOptions.requireVerification = false;
|
|
16
|
+
const app = await bootstrapFn(config);
|
|
17
|
+
const logFn = (message) => (logging ? console.log(message) : null);
|
|
18
|
+
await (0, cli_1.populateInitialData)(app, options.initialData);
|
|
19
|
+
await populateProducts(app, options.productsCsvPath, logging);
|
|
20
|
+
await (0, cli_1.populateCollections)(app, options.initialData);
|
|
21
|
+
await (0, populate_customers_1.populateCustomers)(app, (_a = options.customerCount) !== null && _a !== void 0 ? _a : 10, logFn);
|
|
22
|
+
config.authOptions.requireVerification = originalRequireVerification;
|
|
23
|
+
return app;
|
|
24
|
+
}
|
|
25
|
+
exports.populateForTesting = populateForTesting;
|
|
26
|
+
async function populateProducts(app, productsCsvPath, logging) {
|
|
27
|
+
if (!productsCsvPath) {
|
|
28
|
+
if (logging) {
|
|
29
|
+
console.log("\nNo product data provided, skipping product import");
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const importResult = await (0, cli_1.importProductsFromCsv)(app, productsCsvPath, generated_types_1.LanguageCode.en);
|
|
34
|
+
if (importResult.errors && importResult.errors.length) {
|
|
35
|
+
console.log(`${importResult.errors.length} errors encountered when importing product data:`);
|
|
36
|
+
console.log(importResult.errors.join("\n"));
|
|
37
|
+
}
|
|
38
|
+
if (logging) {
|
|
39
|
+
console.log(`\nImported ${importResult.imported} products`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=populate-for-testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"populate-for-testing.js","sourceRoot":"","sources":["../../src/data-population/populate-for-testing.ts"],"names":[],"mappings":";;;AACA,yEAAmE;AAEnE,2CAI2B;AAI3B,6DAAyD;AAEzD;;GAEG;AACI,KAAK,UAAU,kBAAkB,CACtC,MAA+B,EAC/B,WAAkD,EAClD,OAA0B;;IAEzB,MAAM,CAAC,mBAA2B,CAAC,OAAO,GAAG,KAAK,CAAC;IACpD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACvE,MAAM,2BAA2B,GAAG,MAAM,CAAC,WAAW,CAAC,mBAAmB,CAAC;IAC3E,MAAM,CAAC,WAAW,CAAC,mBAAmB,GAAG,KAAK,CAAC;IAE/C,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;IAEtC,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE3E,MAAM,IAAA,yBAAmB,EAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IACpD,MAAM,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAC9D,MAAM,IAAA,yBAAmB,EAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IACpD,MAAM,IAAA,sCAAiB,EAAC,GAAG,EAAE,MAAA,OAAO,CAAC,aAAa,mCAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IAEjE,MAAM,CAAC,WAAW,CAAC,mBAAmB,GAAG,2BAA2B,CAAC;IACrE,OAAO,GAAG,CAAC;AACb,CAAC;AArBD,gDAqBC;AAED,KAAK,UAAU,gBAAgB,CAC7B,GAA4B,EAC5B,eAAmC,EACnC,OAAgB;IAEhB,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;QACrE,CAAC;QACD,OAAO;IACT,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAqB,EAC9C,GAAG,EACH,eAAe,EACf,8BAAY,CAAC,EAAE,CAChB,CAAC;IACF,IAAI,YAAY,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACtD,OAAO,CAAC,GAAG,CACT,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,kDAAkD,CAChF,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,cAAc,YAAY,CAAC,QAAQ,WAAW,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* Convenience method for creating an {@link ErrorResultGuard}. Takes a predicate function which
|
|
4
|
+
* tests whether the input is considered successful (true) or an error result (false).
|
|
5
|
+
*
|
|
6
|
+
* Note that the resulting variable must _still_ be type annotated in order for the TypeScript
|
|
7
|
+
* type inference to work as expected:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const orderResultGuard: ErrorResultGuard<AddItemToOrderResult>
|
|
12
|
+
* = createErrorResultGuard(order => !!order.lines);
|
|
13
|
+
* ```
|
|
14
|
+
* @docsCategory testing
|
|
15
|
+
*/
|
|
16
|
+
export declare function createErrorResultGuard<T>(testFn: (input: T) => boolean): ErrorResultGuard<T>;
|
|
17
|
+
/**
|
|
18
|
+
* @description
|
|
19
|
+
* A utility class which is used to assert the success of an operation
|
|
20
|
+
* which returns a union type of `SuccessType | ErrorResponse [ | ErrorResponse ]`.
|
|
21
|
+
* The methods of this class are used to:
|
|
22
|
+
* 1. assert that the result is a success or error case
|
|
23
|
+
* 2. narrow the type so that TypeScript can correctly infer the properties of the result.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const orderResultGuard: ErrorResultGuard<AddItemToOrderResult>
|
|
28
|
+
* = createErrorResultGuard(order => !!order.lines);
|
|
29
|
+
*
|
|
30
|
+
* it('errors when quantity is negative', async () => {
|
|
31
|
+
* const { addItemToOrder } = await shopClient.query<AddItemToOrder.Query, AddItemToOrder.Mutation>(ADD_ITEM_TO_ORDER, {
|
|
32
|
+
* productVariantId: 42, quantity: -1,
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // The test will fail
|
|
36
|
+
* orderResultGuard.assertErrorResult(addItemToOrder);
|
|
37
|
+
*
|
|
38
|
+
* // the type of `addItemToOrder` has now been
|
|
39
|
+
* // narrowed to only include the ErrorResult types.
|
|
40
|
+
* expect(addItemToOrder.errorCode).toBe(ErrorCode.NegativeQuantityError);
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
* @docsCategory testing
|
|
44
|
+
*/
|
|
45
|
+
export declare class ErrorResultGuard<T> {
|
|
46
|
+
private testFn;
|
|
47
|
+
constructor(testFn: (input: T) => boolean);
|
|
48
|
+
/**
|
|
49
|
+
* @description
|
|
50
|
+
* A type guard which returns `true` if the input passes the `testFn` predicate.
|
|
51
|
+
*/
|
|
52
|
+
isSuccess(input: T | any): input is T;
|
|
53
|
+
/**
|
|
54
|
+
* @description
|
|
55
|
+
* Asserts (using the testing library's `fail()` function) that the input is
|
|
56
|
+
* successful, i.e. it passes the `testFn`.
|
|
57
|
+
*/
|
|
58
|
+
assertSuccess<R>(input: T | R): asserts input is T;
|
|
59
|
+
/**
|
|
60
|
+
* @description
|
|
61
|
+
* Asserts (using the testing library's `fail()` function) that the input is
|
|
62
|
+
* not successful, i.e. it does not pass the `testFn`.
|
|
63
|
+
*/
|
|
64
|
+
assertErrorResult<R>(input: T | R): asserts input is R;
|
|
65
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorResultGuard = exports.createErrorResultGuard = void 0;
|
|
4
|
+
const assert_1 = require("assert");
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* Convenience method for creating an {@link ErrorResultGuard}. Takes a predicate function which
|
|
8
|
+
* tests whether the input is considered successful (true) or an error result (false).
|
|
9
|
+
*
|
|
10
|
+
* Note that the resulting variable must _still_ be type annotated in order for the TypeScript
|
|
11
|
+
* type inference to work as expected:
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const orderResultGuard: ErrorResultGuard<AddItemToOrderResult>
|
|
16
|
+
* = createErrorResultGuard(order => !!order.lines);
|
|
17
|
+
* ```
|
|
18
|
+
* @docsCategory testing
|
|
19
|
+
*/
|
|
20
|
+
function createErrorResultGuard(testFn) {
|
|
21
|
+
return new ErrorResultGuard(testFn);
|
|
22
|
+
}
|
|
23
|
+
exports.createErrorResultGuard = createErrorResultGuard;
|
|
24
|
+
/**
|
|
25
|
+
* @description
|
|
26
|
+
* A utility class which is used to assert the success of an operation
|
|
27
|
+
* which returns a union type of `SuccessType | ErrorResponse [ | ErrorResponse ]`.
|
|
28
|
+
* The methods of this class are used to:
|
|
29
|
+
* 1. assert that the result is a success or error case
|
|
30
|
+
* 2. narrow the type so that TypeScript can correctly infer the properties of the result.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const orderResultGuard: ErrorResultGuard<AddItemToOrderResult>
|
|
35
|
+
* = createErrorResultGuard(order => !!order.lines);
|
|
36
|
+
*
|
|
37
|
+
* it('errors when quantity is negative', async () => {
|
|
38
|
+
* const { addItemToOrder } = await shopClient.query<AddItemToOrder.Query, AddItemToOrder.Mutation>(ADD_ITEM_TO_ORDER, {
|
|
39
|
+
* productVariantId: 42, quantity: -1,
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // The test will fail
|
|
43
|
+
* orderResultGuard.assertErrorResult(addItemToOrder);
|
|
44
|
+
*
|
|
45
|
+
* // the type of `addItemToOrder` has now been
|
|
46
|
+
* // narrowed to only include the ErrorResult types.
|
|
47
|
+
* expect(addItemToOrder.errorCode).toBe(ErrorCode.NegativeQuantityError);
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
* @docsCategory testing
|
|
51
|
+
*/
|
|
52
|
+
class ErrorResultGuard {
|
|
53
|
+
constructor(testFn) {
|
|
54
|
+
this.testFn = testFn;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @description
|
|
58
|
+
* A type guard which returns `true` if the input passes the `testFn` predicate.
|
|
59
|
+
*/
|
|
60
|
+
isSuccess(input) {
|
|
61
|
+
return this.testFn(input);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @description
|
|
65
|
+
* Asserts (using the testing library's `fail()` function) that the input is
|
|
66
|
+
* successful, i.e. it passes the `testFn`.
|
|
67
|
+
*/
|
|
68
|
+
assertSuccess(input) {
|
|
69
|
+
if (!this.isSuccess(input)) {
|
|
70
|
+
(0, assert_1.fail)(`Unexpected error: ${JSON.stringify(input)}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @description
|
|
75
|
+
* Asserts (using the testing library's `fail()` function) that the input is
|
|
76
|
+
* not successful, i.e. it does not pass the `testFn`.
|
|
77
|
+
*/
|
|
78
|
+
assertErrorResult(input) {
|
|
79
|
+
if (this.isSuccess(input)) {
|
|
80
|
+
(0, assert_1.fail)("Should have errored");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.ErrorResultGuard = ErrorResultGuard;
|
|
85
|
+
//# sourceMappingURL=error-result-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-result-guard.js","sourceRoot":"","sources":["../src/error-result-guard.ts"],"names":[],"mappings":";;;AAAA,mCAA8B;AAE9B;;;;;;;;;;;;;;GAcG;AACH,SAAgB,sBAAsB,CACpC,MAA6B;IAE7B,OAAO,IAAI,gBAAgB,CAAI,MAAM,CAAC,CAAC;AACzC,CAAC;AAJD,wDAIC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,gBAAgB;IAC3B,YAAoB,MAA6B;QAA7B,WAAM,GAAN,MAAM,CAAuB;IAAG,CAAC;IAErD;;;OAGG;IACH,SAAS,CAAC,KAAc;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAU,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAI,KAAY;QAC3B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,IAAA,aAAI,EAAC,qBAAqB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAI,KAAY;QAC/B,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,IAAA,aAAI,EAAC,qBAAqB,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;CACF;AAhCD,4CAgCC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./simple-graphql-client";
|
|
2
|
+
export * from "./test-server";
|
|
3
|
+
export * from "./config/test-config";
|
|
4
|
+
export * from "./create-test-environment";
|
|
5
|
+
export * from "./data-population/clear-all-tables";
|
|
6
|
+
export * from "./data-population/populate-customers";
|
|
7
|
+
export * from "./error-result-guard";
|
|
8
|
+
export * from "./initializers/initializers";
|
|
9
|
+
export * from "./initializers/test-db-initializer";
|
|
10
|
+
export * from "./initializers/mysql-initializer";
|
|
11
|
+
export * from "./initializers/postgres-initializer";
|
|
12
|
+
export * from "./initializers/sqljs-initializer";
|
|
13
|
+
export * from "./testing-logger";
|
|
14
|
+
export * from "./types";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./simple-graphql-client"), exports);
|
|
18
|
+
__exportStar(require("./test-server"), exports);
|
|
19
|
+
__exportStar(require("./config/test-config"), exports);
|
|
20
|
+
__exportStar(require("./create-test-environment"), exports);
|
|
21
|
+
__exportStar(require("./data-population/clear-all-tables"), exports);
|
|
22
|
+
__exportStar(require("./data-population/populate-customers"), exports);
|
|
23
|
+
__exportStar(require("./error-result-guard"), exports);
|
|
24
|
+
__exportStar(require("./initializers/initializers"), exports);
|
|
25
|
+
__exportStar(require("./initializers/test-db-initializer"), exports);
|
|
26
|
+
__exportStar(require("./initializers/mysql-initializer"), exports);
|
|
27
|
+
__exportStar(require("./initializers/postgres-initializer"), exports);
|
|
28
|
+
__exportStar(require("./initializers/sqljs-initializer"), exports);
|
|
29
|
+
__exportStar(require("./testing-logger"), exports);
|
|
30
|
+
__exportStar(require("./types"), exports);
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,gDAA8B;AAC9B,uDAAqC;AACrC,4DAA0C;AAC1C,qEAAmD;AACnD,uEAAqD;AACrD,uDAAqC;AACrC,8DAA4C;AAC5C,qEAAmD;AACnD,mEAAiD;AACjD,sEAAoD;AACpD,mEAAiD;AACjD,mDAAiC;AACjC,0CAAwB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DataSourceOptions } from "typeorm";
|
|
2
|
+
import { TestDbInitializer } from "./test-db-initializer";
|
|
3
|
+
export type InitializerRegistry = {
|
|
4
|
+
[type in DataSourceOptions["type"]]?: TestDbInitializer<any>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* Registers a {@link TestDbInitializer} for the given database type. Should be called before invoking
|
|
9
|
+
* {@link createTestEnvironment}.
|
|
10
|
+
*
|
|
11
|
+
* @docsCategory testing
|
|
12
|
+
*/
|
|
13
|
+
export declare function registerInitializer(type: DataSourceOptions["type"], initializer: TestDbInitializer<any>): void;
|
|
14
|
+
export declare function getInitializerFor(type: DataSourceOptions["type"]): TestDbInitializer<any>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInitializerFor = exports.registerInitializer = void 0;
|
|
4
|
+
const initializerRegistry = {};
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* Registers a {@link TestDbInitializer} for the given database type. Should be called before invoking
|
|
8
|
+
* {@link createTestEnvironment}.
|
|
9
|
+
*
|
|
10
|
+
* @docsCategory testing
|
|
11
|
+
*/
|
|
12
|
+
function registerInitializer(type, initializer) {
|
|
13
|
+
initializerRegistry[type] = initializer;
|
|
14
|
+
}
|
|
15
|
+
exports.registerInitializer = registerInitializer;
|
|
16
|
+
function getInitializerFor(type) {
|
|
17
|
+
const initializer = initializerRegistry[type];
|
|
18
|
+
if (!initializer) {
|
|
19
|
+
throw new Error(`No initializer has been registered for the database type "${type}"`);
|
|
20
|
+
}
|
|
21
|
+
return initializer;
|
|
22
|
+
}
|
|
23
|
+
exports.getInitializerFor = getInitializerFor;
|
|
24
|
+
//# sourceMappingURL=initializers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializers.js","sourceRoot":"","sources":["../../src/initializers/initializers.ts"],"names":[],"mappings":";;;AAQA,MAAM,mBAAmB,GAAwB,EAAE,CAAC;AAEpD;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC,IAA+B,EAC/B,WAAmC;IAEnC,mBAAmB,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;AAC1C,CAAC;AALD,kDAKC;AAED,SAAgB,iBAAiB,CAC/B,IAA+B;IAE/B,MAAM,WAAW,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,6DAA6D,IAAI,GAAG,CACrE,CAAC;IACJ,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAVD,8CAUC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MysqlConnectionOptions } from "typeorm/driver/mysql/MysqlConnectionOptions";
|
|
2
|
+
import { TestDbInitializer } from "./test-db-initializer";
|
|
3
|
+
export declare class MysqlInitializer implements TestDbInitializer<MysqlConnectionOptions> {
|
|
4
|
+
private conn;
|
|
5
|
+
init(testFileName: string, connectionOptions: MysqlConnectionOptions): Promise<MysqlConnectionOptions>;
|
|
6
|
+
populate(populateFn: () => Promise<void>): Promise<void>;
|
|
7
|
+
destroy(): Promise<void>;
|
|
8
|
+
private getMysqlConnection;
|
|
9
|
+
private getDbNameFromFilename;
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MysqlInitializer = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
class MysqlInitializer {
|
|
10
|
+
async init(testFileName, connectionOptions) {
|
|
11
|
+
const dbName = this.getDbNameFromFilename(testFileName);
|
|
12
|
+
this.conn = await this.getMysqlConnection(connectionOptions);
|
|
13
|
+
connectionOptions.database = dbName;
|
|
14
|
+
connectionOptions.synchronize = true;
|
|
15
|
+
const query = (0, util_1.promisify)(this.conn.query).bind(this.conn);
|
|
16
|
+
await query(`DROP DATABASE IF EXISTS ${dbName}`);
|
|
17
|
+
await query(`CREATE DATABASE IF NOT EXISTS ${dbName}`);
|
|
18
|
+
return connectionOptions;
|
|
19
|
+
}
|
|
20
|
+
async populate(populateFn) {
|
|
21
|
+
await populateFn();
|
|
22
|
+
}
|
|
23
|
+
async destroy() {
|
|
24
|
+
await (0, util_1.promisify)(this.conn.end).bind(this.conn)();
|
|
25
|
+
}
|
|
26
|
+
async getMysqlConnection(connectionOptions) {
|
|
27
|
+
const { createConnection } = await import("mysql");
|
|
28
|
+
const conn = createConnection({
|
|
29
|
+
host: connectionOptions.host,
|
|
30
|
+
port: connectionOptions.port,
|
|
31
|
+
user: connectionOptions.username,
|
|
32
|
+
password: connectionOptions.password,
|
|
33
|
+
});
|
|
34
|
+
const connect = (0, util_1.promisify)(conn.connect).bind(conn);
|
|
35
|
+
await connect();
|
|
36
|
+
return conn;
|
|
37
|
+
}
|
|
38
|
+
getDbNameFromFilename(filename) {
|
|
39
|
+
return "e2e_" + path_1.default.basename(filename).replace(/[^a-z0-9_]/gi, "_");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.MysqlInitializer = MysqlInitializer;
|
|
43
|
+
//# sourceMappingURL=mysql-initializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql-initializer.js","sourceRoot":"","sources":["../../src/initializers/mysql-initializer.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAGxB,+BAAiC;AAIjC,MAAa,gBAAgB;IAG3B,KAAK,CAAC,IAAI,CACR,YAAoB,EACpB,iBAAyC;QAEzC,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;QAC5D,iBAAyB,CAAC,QAAQ,GAAG,MAAM,CAAC;QAC5C,iBAAyB,CAAC,WAAW,GAAG,IAAI,CAAC;QAC9C,MAAM,KAAK,GAAG,IAAA,gBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,MAAM,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC,iCAAiC,MAAM,EAAE,CAAC,CAAC;QACvD,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,UAA+B;QAC5C,MAAM,UAAU,EAAE,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAA,gBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IACnD,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAC9B,iBAAyC;QAEzC,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;QACnD,MAAM,IAAI,GAAG,gBAAgB,CAAC;YAC5B,IAAI,EAAE,iBAAiB,CAAC,IAAI;YAC5B,IAAI,EAAE,iBAAiB,CAAC,IAAI;YAC5B,IAAI,EAAE,iBAAiB,CAAC,QAAQ;YAChC,QAAQ,EAAE,iBAAiB,CAAC,QAAQ;SACrC,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,IAAA,gBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,MAAM,OAAO,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,qBAAqB,CAAC,QAAgB;QAC5C,OAAO,MAAM,GAAG,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IACvE,CAAC;CACF;AA5CD,4CA4CC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PostgresConnectionOptions } from "typeorm/driver/postgres/PostgresConnectionOptions";
|
|
2
|
+
import { TestDbInitializer } from "./test-db-initializer";
|
|
3
|
+
export declare class PostgresInitializer implements TestDbInitializer<PostgresConnectionOptions> {
|
|
4
|
+
private client;
|
|
5
|
+
init(testFileName: string, connectionOptions: PostgresConnectionOptions): Promise<PostgresConnectionOptions>;
|
|
6
|
+
populate(populateFn: () => Promise<void>): Promise<void>;
|
|
7
|
+
destroy(): void | Promise<void>;
|
|
8
|
+
private getPostgresConnection;
|
|
9
|
+
private getDbNameFromFilename;
|
|
10
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PostgresInitializer = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
class PostgresInitializer {
|
|
9
|
+
async init(testFileName, connectionOptions) {
|
|
10
|
+
const dbName = this.getDbNameFromFilename(testFileName);
|
|
11
|
+
connectionOptions.database = dbName;
|
|
12
|
+
connectionOptions.synchronize = true;
|
|
13
|
+
this.client = await this.getPostgresConnection(connectionOptions);
|
|
14
|
+
await this.client.query(`DROP DATABASE IF EXISTS ${dbName}`);
|
|
15
|
+
await this.client.query(`CREATE DATABASE ${dbName}`);
|
|
16
|
+
return connectionOptions;
|
|
17
|
+
}
|
|
18
|
+
async populate(populateFn) {
|
|
19
|
+
await populateFn();
|
|
20
|
+
}
|
|
21
|
+
destroy() {
|
|
22
|
+
return this.client.end();
|
|
23
|
+
}
|
|
24
|
+
async getPostgresConnection(connectionOptions) {
|
|
25
|
+
const { Client } = require("pg");
|
|
26
|
+
const client = new Client({
|
|
27
|
+
host: connectionOptions.host,
|
|
28
|
+
port: connectionOptions.port,
|
|
29
|
+
user: connectionOptions.username,
|
|
30
|
+
password: connectionOptions.password,
|
|
31
|
+
database: "postgres",
|
|
32
|
+
});
|
|
33
|
+
await client.connect();
|
|
34
|
+
return client;
|
|
35
|
+
}
|
|
36
|
+
getDbNameFromFilename(filename) {
|
|
37
|
+
return "e2e_" + path_1.default.basename(filename).replace(/[^a-z0-9_]/gi, "_");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.PostgresInitializer = PostgresInitializer;
|
|
41
|
+
//# sourceMappingURL=postgres-initializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-initializer.js","sourceRoot":"","sources":["../../src/initializers/postgres-initializer.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAKxB,MAAa,mBAAmB;IAG9B,KAAK,CAAC,IAAI,CACR,YAAoB,EACpB,iBAA4C;QAE5C,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QACvD,iBAAyB,CAAC,QAAQ,GAAG,MAAM,CAAC;QAC5C,iBAAyB,CAAC,WAAW,GAAG,IAAI,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;QAClE,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;QAC7D,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;QACrD,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,UAA+B;QAC5C,MAAM,UAAU,EAAE,CAAC;IACrB,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,qBAAqB,CACjC,iBAA4C;QAE5C,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACjC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;YACxB,IAAI,EAAE,iBAAiB,CAAC,IAAI;YAC5B,IAAI,EAAE,iBAAiB,CAAC,IAAI;YAC5B,IAAI,EAAE,iBAAiB,CAAC,QAAQ;YAChC,QAAQ,EAAE,iBAAiB,CAAC,QAAQ;YACpC,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;QACH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,qBAAqB,CAAC,QAAgB;QAC5C,OAAO,MAAM,GAAG,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IACvE,CAAC;CACF;AA1CD,kDA0CC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SqljsConnectionOptions } from "typeorm/driver/sqljs/SqljsConnectionOptions";
|
|
2
|
+
import { TestDbInitializer } from "./test-db-initializer";
|
|
3
|
+
export declare class SqljsInitializer implements TestDbInitializer<SqljsConnectionOptions> {
|
|
4
|
+
private dataDir;
|
|
5
|
+
private postPopulateTimeoutMs;
|
|
6
|
+
private dbFilePath;
|
|
7
|
+
private connectionOptions;
|
|
8
|
+
/**
|
|
9
|
+
* @param dataDir
|
|
10
|
+
* @param postPopulateTimeoutMs Allows you to specify a timeout to wait after the population
|
|
11
|
+
* step and before the server is shut down. Can resolve occasional race condition issues with
|
|
12
|
+
* the job queue.
|
|
13
|
+
*/
|
|
14
|
+
constructor(dataDir: string, postPopulateTimeoutMs?: number);
|
|
15
|
+
init(testFileName: string, connectionOptions: SqljsConnectionOptions): Promise<SqljsConnectionOptions>;
|
|
16
|
+
populate(populateFn: () => Promise<void>): Promise<void>;
|
|
17
|
+
destroy(): void | Promise<void>;
|
|
18
|
+
private getDbFilePath;
|
|
19
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SqljsInitializer = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
class SqljsInitializer {
|
|
10
|
+
/**
|
|
11
|
+
* @param dataDir
|
|
12
|
+
* @param postPopulateTimeoutMs Allows you to specify a timeout to wait after the population
|
|
13
|
+
* step and before the server is shut down. Can resolve occasional race condition issues with
|
|
14
|
+
* the job queue.
|
|
15
|
+
*/
|
|
16
|
+
constructor(dataDir, postPopulateTimeoutMs = 0) {
|
|
17
|
+
this.dataDir = dataDir;
|
|
18
|
+
this.postPopulateTimeoutMs = postPopulateTimeoutMs;
|
|
19
|
+
}
|
|
20
|
+
async init(testFileName, connectionOptions) {
|
|
21
|
+
this.dbFilePath = this.getDbFilePath(testFileName);
|
|
22
|
+
this.connectionOptions = connectionOptions;
|
|
23
|
+
connectionOptions.location =
|
|
24
|
+
this.dbFilePath;
|
|
25
|
+
return connectionOptions;
|
|
26
|
+
}
|
|
27
|
+
async populate(populateFn) {
|
|
28
|
+
if (!fs_1.default.existsSync(this.dbFilePath)) {
|
|
29
|
+
const dirName = path_1.default.dirname(this.dbFilePath);
|
|
30
|
+
if (!fs_1.default.existsSync(dirName)) {
|
|
31
|
+
fs_1.default.mkdirSync(dirName);
|
|
32
|
+
}
|
|
33
|
+
this.connectionOptions.autoSave =
|
|
34
|
+
true;
|
|
35
|
+
this.connectionOptions.synchronize =
|
|
36
|
+
true;
|
|
37
|
+
await populateFn();
|
|
38
|
+
await new Promise((resolve) => setTimeout(resolve, this.postPopulateTimeoutMs));
|
|
39
|
+
this.connectionOptions.autoSave =
|
|
40
|
+
false;
|
|
41
|
+
this.connectionOptions.synchronize =
|
|
42
|
+
false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
destroy() {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
getDbFilePath(testFileName) {
|
|
49
|
+
const dbFileName = path_1.default.basename(testFileName) + ".sqlite";
|
|
50
|
+
const dbFilePath = path_1.default.join(this.dataDir, dbFileName);
|
|
51
|
+
return dbFilePath;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.SqljsInitializer = SqljsInitializer;
|
|
55
|
+
//# sourceMappingURL=sqljs-initializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqljs-initializer.js","sourceRoot":"","sources":["../../src/initializers/sqljs-initializer.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAOxB,MAAa,gBAAgB;IAI3B;;;;;OAKG;IACH,YACU,OAAe,EACf,wBAAgC,CAAC;QADjC,YAAO,GAAP,OAAO,CAAQ;QACf,0BAAqB,GAArB,qBAAqB,CAAY;IACxC,CAAC;IAEJ,KAAK,CAAC,IAAI,CACR,YAAoB,EACpB,iBAAyC;QAEzC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;QACnD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC1C,iBAAqD,CAAC,QAAQ;YAC7D,IAAI,CAAC,UAAU,CAAC;QAClB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,UAA+B;QAC5C,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACpC,MAAM,OAAO,GAAG,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9C,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC5B,YAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC;YACA,IAAI,CAAC,iBAAqD,CAAC,QAAQ;gBAClE,IAAI,CAAC;YACN,IAAI,CAAC,iBAAqD,CAAC,WAAW;gBACrE,IAAI,CAAC;YACP,MAAM,UAAU,EAAE,CAAC;YACnB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5B,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAChD,CAAC;YACD,IAAI,CAAC,iBAAqD,CAAC,QAAQ;gBAClE,KAAK,CAAC;YACP,IAAI,CAAC,iBAAqD,CAAC,WAAW;gBACrE,KAAK,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,aAAa,CAAC,YAAoB;QACxC,MAAM,UAAU,GAAG,cAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;QAC3D,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACvD,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAxDD,4CAwDC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseConnectionOptions } from "typeorm/connection/BaseConnectionOptions";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* Defines how the e2e TestService sets up a particular DB to run a single test suite.
|
|
5
|
+
* The `\@deenruv/testing` package ships with initializers for sql.js, MySQL & Postgres.
|
|
6
|
+
*
|
|
7
|
+
* Custom initializers can be created by implementing this interface and registering
|
|
8
|
+
* it with the {@link registerInitializer} function:
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* export class CockroachDbInitializer implements TestDbInitializer<CockroachConnectionOptions> {
|
|
13
|
+
* // database-specific implementation goes here
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* registerInitializer('cockroachdb', new CockroachDbInitializer());
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @docsCategory testing
|
|
20
|
+
*/
|
|
21
|
+
export interface TestDbInitializer<T extends BaseConnectionOptions> {
|
|
22
|
+
/**
|
|
23
|
+
* @description
|
|
24
|
+
* Responsible for creating a database for the current test suite.
|
|
25
|
+
* Typically, this method will:
|
|
26
|
+
*
|
|
27
|
+
* * use the testFileName parameter to derive a database name
|
|
28
|
+
* * create the database
|
|
29
|
+
* * mutate the `connetionOptions` object to point to that new database
|
|
30
|
+
*/
|
|
31
|
+
init(testFileName: string, connectionOptions: T): Promise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* @description
|
|
34
|
+
* Execute the populateFn to populate your database.
|
|
35
|
+
*/
|
|
36
|
+
populate(populateFn: () => Promise<void>): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* @description
|
|
39
|
+
* Clean up any resources used during the init() phase (i.e. close open DB connections)
|
|
40
|
+
*/
|
|
41
|
+
destroy(): void | Promise<void>;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-db-initializer.js","sourceRoot":"","sources":["../../src/initializers/test-db-initializer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
|
2
|
+
import { DeenruvConfig } from "@deenruv/core";
|
|
3
|
+
import { DocumentNode } from "graphql";
|
|
4
|
+
import { RequestInit, Response } from "node-fetch";
|
|
5
|
+
import { QueryParams } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* A minimalistic GraphQL client for populating and querying test data.
|
|
9
|
+
*
|
|
10
|
+
* @docsCategory testing
|
|
11
|
+
*/
|
|
12
|
+
export declare class SimpleGraphQLClient {
|
|
13
|
+
private deenruvConfig;
|
|
14
|
+
private apiUrl;
|
|
15
|
+
private authToken;
|
|
16
|
+
private channelToken;
|
|
17
|
+
private headers;
|
|
18
|
+
constructor(deenruvConfig: Required<DeenruvConfig>, apiUrl?: string);
|
|
19
|
+
/**
|
|
20
|
+
* @description
|
|
21
|
+
* Sets the authToken to be used in each GraphQL request.
|
|
22
|
+
*/
|
|
23
|
+
setAuthToken(token: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* @description
|
|
26
|
+
* Sets the authToken to be used in each GraphQL request.
|
|
27
|
+
*/
|
|
28
|
+
setChannelToken(token: string | null): void;
|
|
29
|
+
/**
|
|
30
|
+
* @description
|
|
31
|
+
* Returns the authToken currently being used.
|
|
32
|
+
*/
|
|
33
|
+
getAuthToken(): string;
|
|
34
|
+
/**
|
|
35
|
+
* @description
|
|
36
|
+
* Performs both query and mutation operations.
|
|
37
|
+
*/
|
|
38
|
+
query<T = any, V extends Record<string, any> = Record<string, any>>(query: DocumentNode | TypedDocumentNode<T, V>, variables?: V, queryParams?: QueryParams): Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* @description
|
|
41
|
+
* Performs a raw HTTP request to the given URL, but also includes the authToken & channelToken
|
|
42
|
+
* headers if they have been set. Useful for testing non-GraphQL endpoints, e.g. for plugins
|
|
43
|
+
* which make use of REST controllers.
|
|
44
|
+
*/
|
|
45
|
+
fetch(url: string, options?: RequestInit): Promise<Response>;
|
|
46
|
+
/**
|
|
47
|
+
* @description
|
|
48
|
+
* Performs a query or mutation and returns the resulting status code.
|
|
49
|
+
*/
|
|
50
|
+
queryStatus<T = any, V extends Record<string, any> = Record<string, any>>(query: DocumentNode, variables?: V): Promise<number>;
|
|
51
|
+
/**
|
|
52
|
+
* @description
|
|
53
|
+
* Attempts to log in with the specified credentials.
|
|
54
|
+
*/
|
|
55
|
+
asUserWithCredentials(username: string, password: string): Promise<any>;
|
|
56
|
+
/**
|
|
57
|
+
* @description
|
|
58
|
+
* Logs in as the SuperAdmin user.
|
|
59
|
+
*/
|
|
60
|
+
asSuperAdmin(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* @description
|
|
63
|
+
* Logs out so that the client is then treated as an anonymous user.
|
|
64
|
+
*/
|
|
65
|
+
asAnonymousUser(): Promise<void>;
|
|
66
|
+
private makeGraphQlRequest;
|
|
67
|
+
private getResult;
|
|
68
|
+
/**
|
|
69
|
+
* @description
|
|
70
|
+
* Perform a file upload mutation.
|
|
71
|
+
*
|
|
72
|
+
* Upload spec: https://github.com/jaydenseric/graphql-multipart-request-spec
|
|
73
|
+
* Discussion of issue: https://github.com/jaydenseric/apollo-upload-client/issues/32
|
|
74
|
+
*/
|
|
75
|
+
fileUploadMutation(options: {
|
|
76
|
+
mutation: DocumentNode;
|
|
77
|
+
filePaths: string[];
|
|
78
|
+
mapVariables: (filePaths: string[]) => any;
|
|
79
|
+
}): Promise<any>;
|
|
80
|
+
}
|
|
81
|
+
export declare class ClientError extends Error {
|
|
82
|
+
response: any;
|
|
83
|
+
request: any;
|
|
84
|
+
constructor(response: any, request: any);
|
|
85
|
+
private static extractMessage;
|
|
86
|
+
}
|