@digitaldefiance/express-suite-test-utils 1.0.7 → 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 +16 -6
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -0
- package/src/lib/direct-log.d.ts +36 -0
- package/src/lib/direct-log.d.ts.map +1 -0
- package/src/lib/direct-log.js +61 -0
package/README.md
CHANGED
|
@@ -14,24 +14,30 @@ yarn add @digitaldefiance/express-suite-test-utils
|
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
|
-
### Importing Test Utilities from
|
|
17
|
+
### Importing Test Utilities from Express Suite Packages
|
|
18
18
|
|
|
19
|
-
Test helpers and mocks
|
|
19
|
+
Test helpers and mocks are available via separate `/testing` entry points:
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
+
// node-express-suite test helpers
|
|
22
23
|
import {
|
|
23
|
-
|
|
24
|
-
setupTestEnv
|
|
25
|
-
// ... other test helpers
|
|
24
|
+
createApplicationMock,
|
|
25
|
+
setupTestEnv
|
|
26
26
|
} from '@digitaldefiance/node-express-suite/testing';
|
|
27
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
|
+
|
|
28
34
|
// Use in your tests
|
|
29
35
|
beforeAll(async () => {
|
|
30
36
|
await setupTestEnv();
|
|
31
37
|
});
|
|
32
38
|
```
|
|
33
39
|
|
|
34
|
-
**Note:**
|
|
40
|
+
**Note:** All `/testing` entry points require `@faker-js/faker` as a peer dependency:
|
|
35
41
|
|
|
36
42
|
```bash
|
|
37
43
|
npm install -D @faker-js/faker
|
|
@@ -97,6 +103,10 @@ MIT
|
|
|
97
103
|
|
|
98
104
|
## ChangeLog
|
|
99
105
|
|
|
106
|
+
### v1.0.8
|
|
107
|
+
|
|
108
|
+
- Add directLog mocks
|
|
109
|
+
|
|
100
110
|
### v1.0.6
|
|
101
111
|
|
|
102
112
|
- Add react mocks
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
package/src/index.d.ts.map
CHANGED
|
@@ -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
|
+
}
|