@digitaldefiance/express-suite-test-utils 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Test utilities for Digital Defiance Express Suite projects.
4
4
 
5
+ Part of [Express Suite](https://github.com/Digital-Defiance/express-suite)
6
+
5
7
  ## Installation
6
8
 
7
9
  ```bash
@@ -12,6 +14,37 @@ yarn add @digitaldefiance/express-suite-test-utils
12
14
 
13
15
  ## Usage
14
16
 
17
+ ### Importing Test Utilities from Express Suite Packages
18
+
19
+ Test helpers and mocks are available via separate `/testing` entry points:
20
+
21
+ ```typescript
22
+ // node-express-suite test helpers
23
+ import {
24
+ createApplicationMock,
25
+ setupTestEnv
26
+ } from '@digitaldefiance/node-express-suite/testing';
27
+
28
+ // node-ecies-lib test mocks
29
+ import { mockBackendMember } from '@digitaldefiance/node-ecies-lib/testing';
30
+
31
+ // ecies-lib test mocks
32
+ import { mockFrontendMember } from '@digitaldefiance/ecies-lib/testing';
33
+
34
+ // Use in your tests
35
+ beforeAll(async () => {
36
+ await setupTestEnv();
37
+ });
38
+ ```
39
+
40
+ **Note:** All `/testing` entry points require `@faker-js/faker` as a peer dependency:
41
+
42
+ ```bash
43
+ npm install -D @faker-js/faker
44
+ # or
45
+ yarn add -D @faker-js/faker
46
+ ```
47
+
15
48
  ### toThrowType Matcher
16
49
 
17
50
  Custom Jest matcher for testing error types with optional validation:
@@ -70,6 +103,10 @@ MIT
70
103
 
71
104
  ## ChangeLog
72
105
 
106
+ ### v1.0.8
107
+
108
+ - Add directLog mocks
109
+
73
110
  ### v1.0.6
74
111
 
75
112
  - Add react mocks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/express-suite-test-utils",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Test utilities for Digital Defiance Express Suite",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './lib/to-throw-type';
2
2
  export * from './lib/console';
3
+ export * from './lib/direct-log';
3
4
  export * from './lib/localStorage-mock';
4
5
  export * from './lib/bson-mock';
5
6
  export * from './lib/react-mocks';
@@ -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,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,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"}
package/src/index.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./lib/to-throw-type"), exports);
5
5
  tslib_1.__exportStar(require("./lib/console"), exports);
6
+ tslib_1.__exportStar(require("./lib/direct-log"), exports);
6
7
  tslib_1.__exportStar(require("./lib/localStorage-mock"), exports);
7
8
  tslib_1.__exportStar(require("./lib/bson-mock"), exports);
8
9
  tslib_1.__exportStar(require("./lib/react-mocks"), exports);
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Spies returned from withDirectLogMocks
3
+ */
4
+ export interface DirectLogSpies {
5
+ writeSync: jest.SpyInstance;
6
+ }
7
+ /**
8
+ * Options for withDirectLogMocks
9
+ */
10
+ export interface WithDirectLogOptions {
11
+ /**
12
+ * If false, do not mute the output (let it pass through).
13
+ * By default (true), mutes output.
14
+ */
15
+ mute?: boolean;
16
+ }
17
+ /**
18
+ * Wrap a test body with fs.writeSync spy for directLog testing.
19
+ * By default mutes output (does nothing on write).
20
+ * The spy will capture calls with file descriptor and buffer.
21
+ */
22
+ export declare function withDirectLogMocks<T = unknown>(options: WithDirectLogOptions, fn: (spies: DirectLogSpies) => Promise<T> | T): Promise<T>;
23
+ /**
24
+ * Helper to check if writeSync was called with a specific file descriptor and message.
25
+ * @param spy The writeSync spy
26
+ * @param fd The file descriptor (1 for stdout, 2 for stderr)
27
+ * @param needles Substrings to search for in the buffer content
28
+ */
29
+ export declare function directLogContains(spy: jest.SpyInstance, fd: number, ...needles: string[]): boolean;
30
+ /**
31
+ * Get all messages written to a specific file descriptor.
32
+ * @param spy The writeSync spy
33
+ * @param fd The file descriptor (1 for stdout, 2 for stderr)
34
+ */
35
+ export declare function getDirectLogMessages(spy: jest.SpyInstance, fd: number): string[];
36
+ //# sourceMappingURL=direct-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-log.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-test-utils/src/lib/direct-log.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,GAAG,OAAO,EAClD,OAAO,EAAE,oBAAoB,EAC7B,EAAE,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAC5C,OAAO,CAAC,CAAC,CAAC,CAoBZ;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,IAAI,CAAC,WAAW,EACrB,EAAE,EAAE,MAAM,EACV,GAAG,OAAO,EAAE,MAAM,EAAE,GACnB,OAAO,CAWT;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,IAAI,CAAC,WAAW,EACrB,EAAE,EAAE,MAAM,GACT,MAAM,EAAE,CASV"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withDirectLogMocks = withDirectLogMocks;
4
+ exports.directLogContains = directLogContains;
5
+ exports.getDirectLogMessages = getDirectLogMessages;
6
+ const tslib_1 = require("tslib");
7
+ const fs = tslib_1.__importStar(require("fs"));
8
+ /**
9
+ * Wrap a test body with fs.writeSync spy for directLog testing.
10
+ * By default mutes output (does nothing on write).
11
+ * The spy will capture calls with file descriptor and buffer.
12
+ */
13
+ async function withDirectLogMocks(options, fn) {
14
+ const mute = options?.mute !== false; // default true
15
+ const noop = () => undefined;
16
+ const originalWriteSync = fs.writeSync;
17
+ const writeSync = jest
18
+ .spyOn(fs, 'writeSync')
19
+ .mockImplementation(mute
20
+ ? noop
21
+ : originalWriteSync);
22
+ const spies = { writeSync };
23
+ try {
24
+ return await fn(spies);
25
+ }
26
+ finally {
27
+ writeSync.mockRestore();
28
+ }
29
+ }
30
+ /**
31
+ * Helper to check if writeSync was called with a specific file descriptor and message.
32
+ * @param spy The writeSync spy
33
+ * @param fd The file descriptor (1 for stdout, 2 for stderr)
34
+ * @param needles Substrings to search for in the buffer content
35
+ */
36
+ function directLogContains(spy, fd, ...needles) {
37
+ return spy.mock.calls.some((args) => {
38
+ const [calledFd, buffer] = args;
39
+ if (calledFd !== fd)
40
+ return false;
41
+ const text = buffer instanceof Buffer
42
+ ? buffer.toString('utf8')
43
+ : String(buffer);
44
+ return needles.every((n) => text.includes(n));
45
+ });
46
+ }
47
+ /**
48
+ * Get all messages written to a specific file descriptor.
49
+ * @param spy The writeSync spy
50
+ * @param fd The file descriptor (1 for stdout, 2 for stderr)
51
+ */
52
+ function getDirectLogMessages(spy, fd) {
53
+ return spy.mock.calls
54
+ .filter((args) => args[0] === fd)
55
+ .map((args) => {
56
+ const buffer = args[1];
57
+ return buffer instanceof Buffer
58
+ ? buffer.toString('utf8')
59
+ : String(buffer);
60
+ });
61
+ }