@digitaldefiance/express-suite-test-utils 1.0.13 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/express-suite-test-utils",
3
- "version": "1.0.13",
3
+ "version": "1.1.0",
4
4
  "homepage": "https://github.com/Digital-Defiance/test-utils",
5
5
  "repository": {
6
6
  "type": "git",
@@ -48,6 +48,17 @@
48
48
  "peerDependencies": {
49
49
  "mongoose": "^8.0.0"
50
50
  },
51
+ "peerDependenciesMeta": {
52
+ "@digitaldefiance/suite-core-lib": {
53
+ "optional": true
54
+ },
55
+ "@digitaldefiance/ecies-lib": {
56
+ "optional": true
57
+ },
58
+ "@digitaldefiance/node-ecies-lib": {
59
+ "optional": true
60
+ }
61
+ },
51
62
  "devDependencies": {
52
63
  "@types/node": "^22.0.0",
53
64
  "mongoose": "^8.9.3"
package/src/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export * from './lib/localStorage-mock';
5
5
  export * from './lib/bson-mock';
6
6
  export * from './lib/react-mocks';
7
7
  export * from './lib/mongoose-memory';
8
+ export * from './lib/i18n-setup';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-express-suite-test-utils/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-express-suite-test-utils/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
package/src/index.js CHANGED
@@ -8,3 +8,4 @@ tslib_1.__exportStar(require("./lib/localStorage-mock"), exports);
8
8
  tslib_1.__exportStar(require("./lib/bson-mock"), exports);
9
9
  tslib_1.__exportStar(require("./lib/react-mocks"), exports);
10
10
  tslib_1.__exportStar(require("./lib/mongoose-memory"), exports);
11
+ tslib_1.__exportStar(require("./lib/i18n-setup"), exports);
@@ -0,0 +1,40 @@
1
+ /**
2
+ * i18n Test Setup Helper
3
+ *
4
+ * Initializes all available i18n engines for testing.
5
+ * Uses real i18n-lib implementations to expose real problems in tests.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import { setupI18nForTests } from '@digitaldefiance/express-suite-test-utils';
10
+ *
11
+ * let cleanupI18n: () => void;
12
+ *
13
+ * beforeAll(() => {
14
+ * cleanupI18n = setupI18nForTests();
15
+ * });
16
+ *
17
+ * afterAll(() => {
18
+ * cleanupI18n();
19
+ * });
20
+ * ```
21
+ */
22
+ /**
23
+ * Initialize all available i18n engines for testing.
24
+ *
25
+ * This function attempts to initialize:
26
+ * - suite-core-lib i18n engine (initSuiteCoreI18nEngine)
27
+ * - ecies-lib i18n engine (getEciesI18nEngine)
28
+ * - node-ecies-lib i18n engine (getNodeEciesI18nEngine)
29
+ *
30
+ * @returns A cleanup function that resets all initialized engines
31
+ */
32
+ export declare function setupI18nForTests(): () => void;
33
+ /**
34
+ * Initialize specific i18n engines for testing.
35
+ *
36
+ * @param engines - Array of engine names to initialize: 'suite-core', 'ecies', 'node-ecies'
37
+ * @returns A cleanup function that resets the initialized engines
38
+ */
39
+ export declare function setupSpecificI18nForTests(engines: Array<'suite-core' | 'ecies' | 'node-ecies'>): () => void;
40
+ //# sourceMappingURL=i18n-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n-setup.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-test-utils/src/lib/i18n-setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAkCH;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,IAAI,CA2C9C;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,KAAK,CAAC,YAAY,GAAG,OAAO,GAAG,YAAY,CAAC,GACpD,MAAM,IAAI,CA2CZ"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ /**
3
+ * i18n Test Setup Helper
4
+ *
5
+ * Initializes all available i18n engines for testing.
6
+ * Uses real i18n-lib implementations to expose real problems in tests.
7
+ *
8
+ * Usage:
9
+ * ```typescript
10
+ * import { setupI18nForTests } from '@digitaldefiance/express-suite-test-utils';
11
+ *
12
+ * let cleanupI18n: () => void;
13
+ *
14
+ * beforeAll(() => {
15
+ * cleanupI18n = setupI18nForTests();
16
+ * });
17
+ *
18
+ * afterAll(() => {
19
+ * cleanupI18n();
20
+ * });
21
+ * ```
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.setupI18nForTests = setupI18nForTests;
25
+ exports.setupSpecificI18nForTests = setupSpecificI18nForTests;
26
+ /**
27
+ * Attempts to load and initialize an i18n module.
28
+ * Returns the reset function if successful, undefined otherwise.
29
+ */
30
+ function tryLoadModule(moduleName, initFnName, resetFnName) {
31
+ try {
32
+ // Dynamic require to handle optional dependencies
33
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-assignment
34
+ const mod = require(moduleName);
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
36
+ const initFn = mod[initFnName];
37
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
38
+ const resetFn = mod[resetFnName];
39
+ if (initFn && typeof initFn === 'function') {
40
+ initFn();
41
+ return resetFn;
42
+ }
43
+ }
44
+ catch {
45
+ // Module not available, skip silently
46
+ }
47
+ return undefined;
48
+ }
49
+ /**
50
+ * Initialize all available i18n engines for testing.
51
+ *
52
+ * This function attempts to initialize:
53
+ * - suite-core-lib i18n engine (initSuiteCoreI18nEngine)
54
+ * - ecies-lib i18n engine (getEciesI18nEngine)
55
+ * - node-ecies-lib i18n engine (getNodeEciesI18nEngine)
56
+ *
57
+ * @returns A cleanup function that resets all initialized engines
58
+ */
59
+ function setupI18nForTests() {
60
+ const resetFunctions = [];
61
+ // Try to initialize suite-core-lib
62
+ const suiteCoreReset = tryLoadModule('@digitaldefiance/suite-core-lib', 'initSuiteCoreI18nEngine', 'resetSuiteCoreI18nEngine');
63
+ if (suiteCoreReset) {
64
+ resetFunctions.push(suiteCoreReset);
65
+ }
66
+ // Try to initialize ecies-lib
67
+ const eciesReset = tryLoadModule('@digitaldefiance/ecies-lib', 'getEciesI18nEngine', 'resetEciesI18nEngine');
68
+ if (eciesReset) {
69
+ resetFunctions.push(eciesReset);
70
+ }
71
+ // Try to initialize node-ecies-lib
72
+ const nodeEciesReset = tryLoadModule('@digitaldefiance/node-ecies-lib', 'getNodeEciesI18nEngine', 'resetNodeEciesI18nEngine');
73
+ if (nodeEciesReset) {
74
+ resetFunctions.push(nodeEciesReset);
75
+ }
76
+ // Return cleanup function
77
+ return () => {
78
+ for (const reset of resetFunctions) {
79
+ try {
80
+ reset();
81
+ }
82
+ catch {
83
+ // Ignore cleanup errors
84
+ }
85
+ }
86
+ };
87
+ }
88
+ /**
89
+ * Initialize specific i18n engines for testing.
90
+ *
91
+ * @param engines - Array of engine names to initialize: 'suite-core', 'ecies', 'node-ecies'
92
+ * @returns A cleanup function that resets the initialized engines
93
+ */
94
+ function setupSpecificI18nForTests(engines) {
95
+ const resetFunctions = [];
96
+ const moduleMap = {
97
+ 'suite-core': {
98
+ module: '@digitaldefiance/suite-core-lib',
99
+ init: 'initSuiteCoreI18nEngine',
100
+ reset: 'resetSuiteCoreI18nEngine',
101
+ },
102
+ ecies: {
103
+ module: '@digitaldefiance/ecies-lib',
104
+ init: 'getEciesI18nEngine',
105
+ reset: 'resetEciesI18nEngine',
106
+ },
107
+ 'node-ecies': {
108
+ module: '@digitaldefiance/node-ecies-lib',
109
+ init: 'getNodeEciesI18nEngine',
110
+ reset: 'resetNodeEciesI18nEngine',
111
+ },
112
+ };
113
+ for (const engine of engines) {
114
+ const config = moduleMap[engine];
115
+ if (config) {
116
+ const resetFn = tryLoadModule(config.module, config.init, config.reset);
117
+ if (resetFn) {
118
+ resetFunctions.push(resetFn);
119
+ }
120
+ }
121
+ }
122
+ return () => {
123
+ for (const reset of resetFunctions) {
124
+ try {
125
+ reset();
126
+ }
127
+ catch {
128
+ // Ignore cleanup errors
129
+ }
130
+ }
131
+ };
132
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"mongoose-memory.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-test-utils/src/lib/mongoose-memory.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAMvE;;;GAGG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC;IAC/C,UAAU,EAAE,UAAU,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC,CAsBD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAWxD;AAED;;GAEG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAOnD"}
1
+ {"version":3,"file":"mongoose-memory.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-test-utils/src/lib/mongoose-memory.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAMvE;;;GAGG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC;IAC/C,UAAU,EAAE,UAAU,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC,CA2BD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAWxD;AAED;;GAEG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAOnD"}
@@ -20,7 +20,12 @@ async function connectMemoryDB() {
20
20
  }
21
21
  // Create new server if needed
22
22
  if (!mongoServer) {
23
- mongoServer = await mongodb_memory_server_1.MongoMemoryServer.create();
23
+ mongoServer = await mongodb_memory_server_1.MongoMemoryServer.create({
24
+ instance: {
25
+ // Increase timeout for slow CI environments
26
+ launchTimeout: 60000,
27
+ },
28
+ });
24
29
  }
25
30
  const uri = mongoServer.getUri();
26
31
  // Connect if not already connected