@leoribeiroweb/nest-testing 0.0.0-stage → 0.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/README.md +154 -2
- package/dist/http/axios-double.d.ts +9 -0
- package/dist/http/axios-double.js +45 -0
- package/dist/http/index.d.ts +1 -0
- package/dist/http/index.js +7 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +2 -0
- package/dist/logging/capture-output.d.ts +14 -0
- package/dist/logging/capture-output.js +31 -0
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +5 -0
- package/dist/mongo/global-setup.d.ts +11 -0
- package/dist/mongo/global-setup.js +34 -0
- package/dist/mongo/global-teardown.d.ts +5 -0
- package/dist/mongo/global-teardown.js +11 -0
- package/dist/mongo/index.d.ts +2 -0
- package/dist/mongo/index.js +7 -0
- package/dist/mongo/runtime-adapters-shim.d.ts +30 -0
- package/dist/mongo/runtime-adapters-shim.js +62 -0
- package/dist/mongo/shared-uri-env.d.ts +7 -0
- package/dist/mongo/shared-uri-env.js +10 -0
- package/dist/mongo/test-mongo.d.ts +20 -0
- package/dist/mongo/test-mongo.js +44 -0
- package/dist/pii/index.d.ts +1 -0
- package/dist/pii/index.js +6 -0
- package/dist/pii/log-meta-pii-guard.d.ts +38 -0
- package/dist/pii/log-meta-pii-guard.js +88 -0
- package/dist/redis/fake-redis.d.ts +55 -0
- package/dist/redis/fake-redis.js +215 -0
- package/dist/redis/index.d.ts +1 -0
- package/dist/redis/index.js +5 -0
- package/dist/tracing/in-memory-tracing.d.ts +8 -0
- package/dist/tracing/in-memory-tracing.js +31 -0
- package/dist/tracing/index.d.ts +1 -0
- package/dist/tracing/index.js +5 -0
- package/package.json +149 -4
package/README.md
CHANGED
|
@@ -1,3 +1,155 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @leoribeiroweb/nest-testing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Test helpers the NestJS services of the platform used to copy from each other:
|
|
4
|
+
a shared in-memory mongod for jest, an in-memory OpenTelemetry tracer,
|
|
5
|
+
stdout/stderr capture, an axios double, a Redis fake that runs the real Lua,
|
|
6
|
+
and a guard that fails a test whose structured log metas carry PII.
|
|
7
|
+
|
|
8
|
+
This package is part of the shared framework behind my own services. It is
|
|
9
|
+
published publicly so builds need no registry credentials, but it is **not an
|
|
10
|
+
open-source project**: there is no support commitment, and the API changes to
|
|
11
|
+
suit the services that consume it. Pin a major version.
|
|
12
|
+
|
|
13
|
+
Install it as a **dev dependency**:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install --save-dev @leoribeiroweb/nest-testing
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## One subpath per family
|
|
20
|
+
|
|
21
|
+
The root entry exports nothing. Import the family you use; each subpath loads
|
|
22
|
+
only its own peers (pinned by `src/package-contract.spec.ts`).
|
|
23
|
+
|
|
24
|
+
| Subpath | Exports | Loads at import |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| `@leoribeiroweb/nest-testing/mongo` | `useTestMongo()`, `SHARED_MONGO_URI_ENV`, type `TestMongo` | `mongoose` |
|
|
27
|
+
| `@leoribeiroweb/nest-testing/mongo/global-setup` | default: the jest `globalSetup` | `mongodb-memory-server` |
|
|
28
|
+
| `@leoribeiroweb/nest-testing/mongo/global-teardown` | default: the jest `globalTeardown` | nothing |
|
|
29
|
+
| `@leoribeiroweb/nest-testing/mongo/runtime-adapters-shim` | the driver's `runtime_adapters` contract, for `moduleNameMapper` | nothing |
|
|
30
|
+
| `@leoribeiroweb/nest-testing/tracing` | `installInMemoryTracing()`, type `InMemoryTracing` | `@opentelemetry/api`, `@opentelemetry/sdk-trace-base`, `@opentelemetry/context-async-hooks` |
|
|
31
|
+
| `@leoribeiroweb/nest-testing/logging` | `captureOutput(fn)`, type `CapturedOutput` | nothing |
|
|
32
|
+
| `@leoribeiroweb/nest-testing/http` | `axiosDouble()`, `okResponse(status?)`, `resolveAll(axios, status?)` | nothing (`axios` types only) |
|
|
33
|
+
| `@leoribeiroweb/nest-testing/redis` | `FakeRedis`, type `ScriptableRedis` | `fengari` |
|
|
34
|
+
| `@leoribeiroweb/nest-testing/pii` | `guardLogMetasAgainstPii(forbidden?, loggers?)`, `recordingLoggerModule()`, type `LoggerMockLike` | nothing (the core package, lazily, inside its hooks) |
|
|
35
|
+
|
|
36
|
+
Only importing `./mongo/global-setup` loads `mongodb-memory-server`.
|
|
37
|
+
|
|
38
|
+
## Requirements
|
|
39
|
+
|
|
40
|
+
Peers, never dependencies: a private copy of `mongoose`, the OpenTelemetry API
|
|
41
|
+
or the core package would not be the instance the code under test uses.
|
|
42
|
+
|
|
43
|
+
| Peer | Range | Needed by |
|
|
44
|
+
| --- | --- | --- |
|
|
45
|
+
| `@leoribeiroweb/nest-core` | `>=0.2.0 <1.0.0` (required) | `./pii` |
|
|
46
|
+
| `jest` | `^29 \|\| ^30` (optional) | every family: the helpers use the `jest` globals |
|
|
47
|
+
| `mongoose` | `^9` (optional) | `./mongo` |
|
|
48
|
+
| `mongodb-memory-server` | `^11` (optional) | `./mongo/global-setup` |
|
|
49
|
+
| `@opentelemetry/api` | `^1.9` (optional) | `./tracing` |
|
|
50
|
+
| `@opentelemetry/sdk-trace-base` | `^2` (optional) | `./tracing` |
|
|
51
|
+
| `@opentelemetry/context-async-hooks` | `^2` (optional) | `./tracing` |
|
|
52
|
+
| `axios` | `^1` (optional) | `./http` (types) |
|
|
53
|
+
| `fengari` | `^0.1.5` (optional) | `./redis` |
|
|
54
|
+
|
|
55
|
+
The core floor is 0.2.0, the first core whose root entry exports `createLogger`
|
|
56
|
+
and the `StructuredContextLogger` with the six level methods `./pii` watches.
|
|
57
|
+
The `sibling-peer-floor` CI job runs this package's typecheck and specs
|
|
58
|
+
against core 0.2.0 and mongoose 9.0.0 from npm.
|
|
59
|
+
|
|
60
|
+
The helpers call `jest.fn`, `jest.spyOn`, `beforeEach` and `expect` as
|
|
61
|
+
globals, so they work under jest's default `injectGlobals: true` only.
|
|
62
|
+
|
|
63
|
+
## Jest config for the Mongo harness
|
|
64
|
+
|
|
65
|
+
One mongod for the whole run, started before the workers, with a private
|
|
66
|
+
database per `useTestMongo()` call:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
// jest.config.js
|
|
70
|
+
module.exports = {
|
|
71
|
+
// ...
|
|
72
|
+
globalSetup: '@leoribeiroweb/nest-testing/mongo/global-setup',
|
|
73
|
+
globalTeardown: '@leoribeiroweb/nest-testing/mongo/global-teardown',
|
|
74
|
+
moduleNameMapper: {
|
|
75
|
+
// mongodb driver 7.7+ loads `os` with a dynamic import() that jest's
|
|
76
|
+
// CommonJS sandbox rejects; without this every connection is refused.
|
|
77
|
+
'^\\./runtime_adapters$': '@leoribeiroweb/nest-testing/mongo/runtime-adapters-shim',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The same keys work in the `"jest"` block of `package.json`. Jest resolves
|
|
83
|
+
all three by package name. Pin the mongod version as before, with
|
|
84
|
+
`"config": { "mongodbMemoryServer": { "version": "7.0.14" } }` in
|
|
85
|
+
`package.json` or `MONGOMS_VERSION`.
|
|
86
|
+
|
|
87
|
+
Map the shim only for a driver of 7.7 or later, whose `resolveRuntimeAdapters`
|
|
88
|
+
returns a promise. A worker that also loads an older driver copy (7.6 or
|
|
89
|
+
earlier returns synchronously) must not have that copy mapped.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { useTestMongo, type TestMongo } from '@leoribeiroweb/nest-testing/mongo';
|
|
93
|
+
|
|
94
|
+
let mongo: TestMongo;
|
|
95
|
+
beforeAll(async () => {
|
|
96
|
+
mongo = await useTestMongo();
|
|
97
|
+
// MongooseModule.forRoot(mongo.getUri()) ...
|
|
98
|
+
});
|
|
99
|
+
afterAll(() => mongo.drop());
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`useTestMongo()` throws, naming the missing `globalSetup`, when the config
|
|
103
|
+
above is absent.
|
|
104
|
+
|
|
105
|
+
## The other families
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { installInMemoryTracing } from '@leoribeiroweb/nest-testing/tracing';
|
|
109
|
+
|
|
110
|
+
const tracing = installInMemoryTracing(); // registers real OTel globals
|
|
111
|
+
// ... run code that opens spans ...
|
|
112
|
+
expect(tracing.spans().map((s) => s.name)).toEqual(['job.x']);
|
|
113
|
+
await tracing.uninstall(); // puts the noop globals back
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { captureOutput } from '@leoribeiroweb/nest-testing/logging';
|
|
118
|
+
|
|
119
|
+
const { out, err } = captureOutput(() => logger.info('type', 'message'));
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { axiosDouble, resolveAll } from '@leoribeiroweb/nest-testing/http';
|
|
124
|
+
|
|
125
|
+
const axios = axiosDouble();
|
|
126
|
+
resolveAll(axios, 200);
|
|
127
|
+
new HttpService(axios);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { FakeRedis } from '@leoribeiroweb/nest-testing/redis';
|
|
132
|
+
|
|
133
|
+
const redis = new FakeRedis(); // runs the script body in a Lua VM
|
|
134
|
+
redis.advance(1_000); // a fake clock instead of sleeping
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { guardLogMetasAgainstPii } from '@leoribeiroweb/nest-testing/pii';
|
|
139
|
+
|
|
140
|
+
describe('the console audit trail', () => {
|
|
141
|
+
// Every test here fails if a structured log meta contains an `@`
|
|
142
|
+
// or one of the listed values.
|
|
143
|
+
guardLogMetasAgainstPii(['tg:42']);
|
|
144
|
+
// ...
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
When a spec mocks its logging module, `recordingLoggerModule()` stands in for
|
|
149
|
+
it and still lets the guard see every meta:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
jest.mock('../logging/structured-logger', () =>
|
|
153
|
+
jest.requireActual('@leoribeiroweb/nest-testing/pii').recordingLoggerModule(),
|
|
154
|
+
);
|
|
155
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* A stand-in for an axios instance shaped the way `HttpService` drives it: the
|
|
4
|
+
* verb methods are called directly and must return promises.
|
|
5
|
+
*/
|
|
6
|
+
export declare const axiosDouble: () => AxiosInstance;
|
|
7
|
+
export declare const okResponse: (status?: number) => AxiosResponse;
|
|
8
|
+
/** Resolves every verb so a test can focus on what was sent, not what came back. */
|
|
9
|
+
export declare const resolveAll: (axios: AxiosInstance, status?: number) => void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAll = exports.okResponse = exports.axiosDouble = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A stand-in for an axios instance shaped the way `HttpService` drives it: the
|
|
6
|
+
* verb methods are called directly and must return promises.
|
|
7
|
+
*/
|
|
8
|
+
const axiosDouble = () => ({
|
|
9
|
+
defaults: { headers: { common: {} } },
|
|
10
|
+
interceptors: {
|
|
11
|
+
request: { use: jest.fn(), eject: jest.fn() },
|
|
12
|
+
response: { use: jest.fn(), eject: jest.fn() },
|
|
13
|
+
},
|
|
14
|
+
get: jest.fn(),
|
|
15
|
+
post: jest.fn(),
|
|
16
|
+
put: jest.fn(),
|
|
17
|
+
patch: jest.fn(),
|
|
18
|
+
delete: jest.fn(),
|
|
19
|
+
head: jest.fn(),
|
|
20
|
+
request: jest.fn(),
|
|
21
|
+
});
|
|
22
|
+
exports.axiosDouble = axiosDouble;
|
|
23
|
+
const okResponse = (status = 200) => ({
|
|
24
|
+
data: {},
|
|
25
|
+
status,
|
|
26
|
+
statusText: 'OK',
|
|
27
|
+
headers: {},
|
|
28
|
+
config: {},
|
|
29
|
+
});
|
|
30
|
+
exports.okResponse = okResponse;
|
|
31
|
+
/** Resolves every verb so a test can focus on what was sent, not what came back. */
|
|
32
|
+
const resolveAll = (axios, status = 200) => {
|
|
33
|
+
for (const verb of [
|
|
34
|
+
'get',
|
|
35
|
+
'post',
|
|
36
|
+
'put',
|
|
37
|
+
'patch',
|
|
38
|
+
'delete',
|
|
39
|
+
'head',
|
|
40
|
+
'request',
|
|
41
|
+
]) {
|
|
42
|
+
axios[verb].mockResolvedValue((0, exports.okResponse)(status));
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.resolveAll = resolveAll;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { axiosDouble, okResponse, resolveAll } from './axios-double';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAll = exports.okResponse = exports.axiosDouble = void 0;
|
|
4
|
+
var axios_double_1 = require("./axios-double");
|
|
5
|
+
Object.defineProperty(exports, "axiosDouble", { enumerable: true, get: function () { return axios_double_1.axiosDouble; } });
|
|
6
|
+
Object.defineProperty(exports, "okResponse", { enumerable: true, get: function () { return axios_double_1.okResponse; } });
|
|
7
|
+
Object.defineProperty(exports, "resolveAll", { enumerable: true, get: function () { return axios_double_1.resolveAll; } });
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The root entry exports nothing on purpose. Every helper is reached through
|
|
3
|
+
* the subpath of its family, so a spec loads only that family's peers:
|
|
4
|
+
*
|
|
5
|
+
* - `@leoribeiroweb/nest-testing/mongo` (+ `/mongo/global-setup`,
|
|
6
|
+
* `/mongo/global-teardown`, `/mongo/runtime-adapters-shim`)
|
|
7
|
+
* - `@leoribeiroweb/nest-testing/tracing`
|
|
8
|
+
* - `@leoribeiroweb/nest-testing/logging`
|
|
9
|
+
* - `@leoribeiroweb/nest-testing/http`
|
|
10
|
+
* - `@leoribeiroweb/nest-testing/redis`
|
|
11
|
+
* - `@leoribeiroweb/nest-testing/pii`
|
|
12
|
+
*
|
|
13
|
+
* Every peer except `@leoribeiroweb/nest-core` is optional, so a root barrel
|
|
14
|
+
* re-exporting the families would throw `MODULE_NOT_FOUND` for a consumer
|
|
15
|
+
* that installed only the peers of the family it uses.
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** What `fn` wrote, one entry per `write` call. */
|
|
2
|
+
export interface CapturedOutput {
|
|
3
|
+
out: string[];
|
|
4
|
+
err: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Runs `fn` with `process.stdout.write` and `process.stderr.write` replaced by
|
|
8
|
+
* recorders, and returns what it wrote. Nothing reaches the terminal, and both
|
|
9
|
+
* streams are restored even when `fn` throws.
|
|
10
|
+
*
|
|
11
|
+
* Synchronous on purpose: the structured logger writes synchronously, and a
|
|
12
|
+
* promise-returning `fn` would restore the streams before it finished.
|
|
13
|
+
*/
|
|
14
|
+
export declare function captureOutput(fn: () => void): CapturedOutput;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.captureOutput = captureOutput;
|
|
4
|
+
/**
|
|
5
|
+
* Runs `fn` with `process.stdout.write` and `process.stderr.write` replaced by
|
|
6
|
+
* recorders, and returns what it wrote. Nothing reaches the terminal, and both
|
|
7
|
+
* streams are restored even when `fn` throws.
|
|
8
|
+
*
|
|
9
|
+
* Synchronous on purpose: the structured logger writes synchronously, and a
|
|
10
|
+
* promise-returning `fn` would restore the streams before it finished.
|
|
11
|
+
*/
|
|
12
|
+
function captureOutput(fn) {
|
|
13
|
+
const out = [];
|
|
14
|
+
const err = [];
|
|
15
|
+
const outSpy = jest.spyOn(process.stdout, 'write').mockImplementation((chunk) => {
|
|
16
|
+
out.push(String(chunk));
|
|
17
|
+
return true;
|
|
18
|
+
});
|
|
19
|
+
const errSpy = jest.spyOn(process.stderr, 'write').mockImplementation((chunk) => {
|
|
20
|
+
err.push(String(chunk));
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
try {
|
|
24
|
+
fn();
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
outSpy.mockRestore();
|
|
28
|
+
errSpy.mockRestore();
|
|
29
|
+
}
|
|
30
|
+
return { out, err };
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { captureOutput, type CapturedOutput } from './capture-output';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.captureOutput = void 0;
|
|
4
|
+
var capture_output_1 = require("./capture-output");
|
|
5
|
+
Object.defineProperty(exports, "captureOutput", { enumerable: true, get: function () { return capture_output_1.captureOutput; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
2
|
+
declare global {
|
|
3
|
+
var __SHARED_MONGOD__: MongoMemoryServer | undefined;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Jest `globalSetup`: starts the one mongod every worker shares and publishes
|
|
7
|
+
* its URI on `SHARED_MONGO_URI_ENV`. The mongod version comes from the
|
|
8
|
+
* consumer's own `mongodbMemoryServer` config (`package.json`) or
|
|
9
|
+
* `MONGOMS_VERSION`, as with any `MongoMemoryServer`.
|
|
10
|
+
*/
|
|
11
|
+
export default function globalSetup(): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = globalSetup;
|
|
4
|
+
const mongodb_memory_server_1 = require("mongodb-memory-server");
|
|
5
|
+
const shared_uri_env_1 = require("./shared-uri-env");
|
|
6
|
+
/**
|
|
7
|
+
* Generous because it is paid once per run, while jest is still starting its
|
|
8
|
+
* workers, instead of 40+ times in parallel with them.
|
|
9
|
+
*/
|
|
10
|
+
const LAUNCH_TIMEOUT_MS = 60_000;
|
|
11
|
+
/**
|
|
12
|
+
* mongod runs at most 3 user index builds at once and queues the rest. That
|
|
13
|
+
* limit was per suite while every suite had its own server; shared, it queues
|
|
14
|
+
* the index builds of every worker behind each other ("Too many index builds
|
|
15
|
+
* running simultaneously" 109 times in one 16-worker run), long enough to push
|
|
16
|
+
* `createIndexes` calls past jest's 5 s test timeout.
|
|
17
|
+
*/
|
|
18
|
+
const MAX_ACTIVE_INDEX_BUILDS = 64;
|
|
19
|
+
/**
|
|
20
|
+
* Jest `globalSetup`: starts the one mongod every worker shares and publishes
|
|
21
|
+
* its URI on `SHARED_MONGO_URI_ENV`. The mongod version comes from the
|
|
22
|
+
* consumer's own `mongodbMemoryServer` config (`package.json`) or
|
|
23
|
+
* `MONGOMS_VERSION`, as with any `MongoMemoryServer`.
|
|
24
|
+
*/
|
|
25
|
+
async function globalSetup() {
|
|
26
|
+
const mongod = await mongodb_memory_server_1.MongoMemoryServer.create({
|
|
27
|
+
instance: {
|
|
28
|
+
launchTimeout: LAUNCH_TIMEOUT_MS,
|
|
29
|
+
args: ['--setParameter', `maxNumActiveUserIndexBuilds=${MAX_ACTIVE_INDEX_BUILDS}`],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
globalThis.__SHARED_MONGOD__ = mongod;
|
|
33
|
+
process.env[shared_uri_env_1.SHARED_MONGO_URI_ENV] = mongod.getUri();
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = globalTeardown;
|
|
4
|
+
/**
|
|
5
|
+
* Jest `globalTeardown`: stops the mongod `global-setup` started. It reads the
|
|
6
|
+
* server back from `globalThis`, so it loads no Mongo package itself.
|
|
7
|
+
*/
|
|
8
|
+
async function globalTeardown() {
|
|
9
|
+
await globalThis.__SHARED_MONGOD__?.stop();
|
|
10
|
+
globalThis.__SHARED_MONGOD__ = undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useTestMongo = exports.SHARED_MONGO_URI_ENV = void 0;
|
|
4
|
+
var shared_uri_env_1 = require("./shared-uri-env");
|
|
5
|
+
Object.defineProperty(exports, "SHARED_MONGO_URI_ENV", { enumerable: true, get: function () { return shared_uri_env_1.SHARED_MONGO_URI_ENV; } });
|
|
6
|
+
var test_mongo_1 = require("./test-mongo");
|
|
7
|
+
Object.defineProperty(exports, "useTestMongo", { enumerable: true, get: function () { return test_mongo_1.useTestMongo; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jest-only stand-in for the MongoDB driver's `lib/runtime_adapters.js`, wired
|
|
3
|
+
* through `moduleNameMapper` (social-api#921, affiliate-api#908; see the
|
|
4
|
+
* package README for the mapper line).
|
|
5
|
+
*
|
|
6
|
+
* Since driver 7.7 that module loads `os` with a dynamic `import('os')`. Jest
|
|
7
|
+
* runs CommonJS specs in a vm without `--experimental-vm-modules`, so the
|
|
8
|
+
* import rejects with ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG, the
|
|
9
|
+
* handshake metadata comes out as `{}`, and mongod refuses every connection
|
|
10
|
+
* ("Missing required sub-document 'driver' in the client metadata document").
|
|
11
|
+
* Production runs plain Node, where the dynamic import works, so the real
|
|
12
|
+
* module is used there.
|
|
13
|
+
*
|
|
14
|
+
* Same contract as the driver's module (7.7 and later: `resolveRuntimeAdapters`
|
|
15
|
+
* returns a promise), with a static `os` instead of the dynamic import. Driver
|
|
16
|
+
* 7.6 and earlier return the adapters synchronously: do not map their copy to
|
|
17
|
+
* this file. `runtime-adapters-shim.spec.ts` fails if the driver's exports
|
|
18
|
+
* drift. Drop the mapper once the driver stops using a dynamic import here, or
|
|
19
|
+
* the suite runs with `--experimental-vm-modules`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const ALLOWED_DRIVER_REQUIRE_PROPERTY_NAME = "allowedDriverRequire";
|
|
22
|
+
interface RuntimeAdapterOptions {
|
|
23
|
+
runtimeAdapters?: {
|
|
24
|
+
os?: unknown;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare function resolveRuntimeAdapters(options: RuntimeAdapterOptions): Promise<{
|
|
28
|
+
os: unknown;
|
|
29
|
+
}>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ALLOWED_DRIVER_REQUIRE_PROPERTY_NAME = void 0;
|
|
37
|
+
exports.resolveRuntimeAdapters = resolveRuntimeAdapters;
|
|
38
|
+
const os = __importStar(require("os"));
|
|
39
|
+
/**
|
|
40
|
+
* Jest-only stand-in for the MongoDB driver's `lib/runtime_adapters.js`, wired
|
|
41
|
+
* through `moduleNameMapper` (social-api#921, affiliate-api#908; see the
|
|
42
|
+
* package README for the mapper line).
|
|
43
|
+
*
|
|
44
|
+
* Since driver 7.7 that module loads `os` with a dynamic `import('os')`. Jest
|
|
45
|
+
* runs CommonJS specs in a vm without `--experimental-vm-modules`, so the
|
|
46
|
+
* import rejects with ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG, the
|
|
47
|
+
* handshake metadata comes out as `{}`, and mongod refuses every connection
|
|
48
|
+
* ("Missing required sub-document 'driver' in the client metadata document").
|
|
49
|
+
* Production runs plain Node, where the dynamic import works, so the real
|
|
50
|
+
* module is used there.
|
|
51
|
+
*
|
|
52
|
+
* Same contract as the driver's module (7.7 and later: `resolveRuntimeAdapters`
|
|
53
|
+
* returns a promise), with a static `os` instead of the dynamic import. Driver
|
|
54
|
+
* 7.6 and earlier return the adapters synchronously: do not map their copy to
|
|
55
|
+
* this file. `runtime-adapters-shim.spec.ts` fails if the driver's exports
|
|
56
|
+
* drift. Drop the mapper once the driver stops using a dynamic import here, or
|
|
57
|
+
* the suite runs with `--experimental-vm-modules`.
|
|
58
|
+
*/
|
|
59
|
+
exports.ALLOWED_DRIVER_REQUIRE_PROPERTY_NAME = 'allowedDriverRequire';
|
|
60
|
+
async function resolveRuntimeAdapters(options) {
|
|
61
|
+
return Promise.resolve({ os: options.runtimeAdapters?.os ?? os });
|
|
62
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environment variable `global-setup` publishes the shared server's URI
|
|
3
|
+
* on. Jest workers are forked after global setup runs, so they inherit it.
|
|
4
|
+
*
|
|
5
|
+
* In its own file so `global-setup` can read it without loading `mongoose`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SHARED_MONGO_URI_ENV = "SHARED_MONGO_TEST_URI";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SHARED_MONGO_URI_ENV = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The environment variable `global-setup` publishes the shared server's URI
|
|
6
|
+
* on. Jest workers are forked after global setup runs, so they inherit it.
|
|
7
|
+
*
|
|
8
|
+
* In its own file so `global-setup` can read it without loading `mongoose`.
|
|
9
|
+
*/
|
|
10
|
+
exports.SHARED_MONGO_URI_ENV = 'SHARED_MONGO_TEST_URI';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface TestMongo {
|
|
2
|
+
/**
|
|
3
|
+
* A URI into this suite's own database. There is deliberately no way to
|
|
4
|
+
* name another one: `drop()` could not clean it up, and on a server that
|
|
5
|
+
* outlives every suite it would leak into the next suite using that name.
|
|
6
|
+
*/
|
|
7
|
+
getUri(): string;
|
|
8
|
+
/** Drops this suite's database. The shared server keeps running. */
|
|
9
|
+
drop(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A private database on the one mongod the whole jest run shares
|
|
13
|
+
* (social-api#600, moved here unchanged from `affiliate-api` and `social-api`).
|
|
14
|
+
*
|
|
15
|
+
* Starting a `MongoMemoryServer` per spec file put 40+ mongod launches inside
|
|
16
|
+
* the same few seconds; under load they hit the 10 s launch timeout together
|
|
17
|
+
* and surfaced as `afterAll` TypeErrors. Every call gets a fresh database
|
|
18
|
+
* name, so suites running in parallel workers never see each other's data.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useTestMongo(): Promise<TestMongo>;
|
|
@@ -0,0 +1,44 @@
|
|
|
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.useTestMongo = useTestMongo;
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const shared_uri_env_1 = require("./shared-uri-env");
|
|
10
|
+
/**
|
|
11
|
+
* A private database on the one mongod the whole jest run shares
|
|
12
|
+
* (social-api#600, moved here unchanged from `affiliate-api` and `social-api`).
|
|
13
|
+
*
|
|
14
|
+
* Starting a `MongoMemoryServer` per spec file put 40+ mongod launches inside
|
|
15
|
+
* the same few seconds; under load they hit the 10 s launch timeout together
|
|
16
|
+
* and surfaced as `afterAll` TypeErrors. Every call gets a fresh database
|
|
17
|
+
* name, so suites running in parallel workers never see each other's data.
|
|
18
|
+
*/
|
|
19
|
+
async function useTestMongo() {
|
|
20
|
+
const baseUri = process.env[shared_uri_env_1.SHARED_MONGO_URI_ENV];
|
|
21
|
+
if (!baseUri) {
|
|
22
|
+
throw new Error(`${shared_uri_env_1.SHARED_MONGO_URI_ENV} is not set: the jest globalSetup ` +
|
|
23
|
+
'(@leoribeiroweb/nest-testing/mongo/global-setup) did not run. ' +
|
|
24
|
+
'Add it, and the globalTeardown, to the jest config (see the package README).');
|
|
25
|
+
}
|
|
26
|
+
const ownDbName = `test_${process.env.JEST_WORKER_ID ?? '0'}_${(0, crypto_1.randomUUID)().slice(0, 8)}`;
|
|
27
|
+
const getUri = () => {
|
|
28
|
+
const uri = new URL(baseUri);
|
|
29
|
+
uri.pathname = `/${ownDbName}`;
|
|
30
|
+
return uri.toString();
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
getUri,
|
|
34
|
+
drop: async () => {
|
|
35
|
+
const connection = await mongoose_1.default.createConnection(getUri()).asPromise();
|
|
36
|
+
try {
|
|
37
|
+
await connection.dropDatabase();
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
await connection.close();
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { guardLogMetasAgainstPii, recordingLoggerModule, type LoggerMockLike } from './log-meta-pii-guard';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recordingLoggerModule = exports.guardLogMetasAgainstPii = void 0;
|
|
4
|
+
var log_meta_pii_guard_1 = require("./log-meta-pii-guard");
|
|
5
|
+
Object.defineProperty(exports, "guardLogMetasAgainstPii", { enumerable: true, get: function () { return log_meta_pii_guard_1.guardLogMetasAgainstPii; } });
|
|
6
|
+
Object.defineProperty(exports, "recordingLoggerModule", { enumerable: true, get: function () { return log_meta_pii_guard_1.recordingLoggerModule; } });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type * as NestCore from '@leoribeiroweb/nest-core';
|
|
2
|
+
declare const LEVELS: readonly ["info", "warn", "error", "debug", "verbose", "fatal"];
|
|
3
|
+
type Level = (typeof LEVELS)[number];
|
|
4
|
+
/** A `jest.fn()`, or anything else that records its calls the same way. */
|
|
5
|
+
export interface LoggerMockLike {
|
|
6
|
+
readonly mock: {
|
|
7
|
+
readonly calls: unknown[][];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A stand-in for the logging module that writes nothing but lets
|
|
12
|
+
* `guardLogMetasAgainstPii` see every meta, for specs that mock the logger:
|
|
13
|
+
*
|
|
14
|
+
* jest.mock('../common/logging/structured-logger', () =>
|
|
15
|
+
* jest.requireActual('@leoribeiroweb/nest-testing/pii').recordingLoggerModule(),
|
|
16
|
+
* );
|
|
17
|
+
*/
|
|
18
|
+
export declare function recordingLoggerModule(): Pick<typeof NestCore, 'createLogger'>;
|
|
19
|
+
/**
|
|
20
|
+
* The guard without the jest hooks: `start()` resets the recordings and spies
|
|
21
|
+
* on the real logger, `stop()` restores it and returns the leaks seen since.
|
|
22
|
+
* Not exported from the subpath; `guardLogMetasAgainstPii` is the API.
|
|
23
|
+
*/
|
|
24
|
+
export declare function logMetaPiiGuard(forbidden: readonly string[], loggers: ReadonlyArray<Partial<Record<Level, LoggerMockLike>>>): {
|
|
25
|
+
start(): void;
|
|
26
|
+
stop(): string[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Test helper (social-api#638): every test of the enclosing `describe` fails
|
|
30
|
+
* when a structured log meta it produced contains an `@` (on the console the
|
|
31
|
+
* actor is the operator's e-mail, which is PII) or one of `forbidden` (for
|
|
32
|
+
* example a `tg:<id>` actor the spec uses). It watches the real logger, the
|
|
33
|
+
* recording one of `recordingLoggerModule()`, and any logger mock the spec
|
|
34
|
+
* hands in as `loggers` (all of their `mock.calls` so far are read after each
|
|
35
|
+
* test).
|
|
36
|
+
*/
|
|
37
|
+
export declare function guardLogMetasAgainstPii(forbidden?: readonly string[], loggers?: ReadonlyArray<Partial<Record<Level, LoggerMockLike>>>): void;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recordingLoggerModule = recordingLoggerModule;
|
|
4
|
+
exports.logMetaPiiGuard = logMetaPiiGuard;
|
|
5
|
+
exports.guardLogMetasAgainstPii = guardLogMetasAgainstPii;
|
|
6
|
+
/**
|
|
7
|
+
* Moved from `social-api` (`src/common/testing/log-meta-pii-guard.ts`, #638).
|
|
8
|
+
* The one change: the logger it watches is `@leoribeiroweb/nest-core`'s
|
|
9
|
+
* `StructuredContextLogger`, not a service-local copy.
|
|
10
|
+
*/
|
|
11
|
+
const CORE = '@leoribeiroweb/nest-core';
|
|
12
|
+
const LEVELS = ['info', 'warn', 'error', 'debug', 'verbose', 'fatal'];
|
|
13
|
+
/** Calls made to the loggers of `recordingLoggerModule()`, per test. */
|
|
14
|
+
const recorded = [];
|
|
15
|
+
/**
|
|
16
|
+
* Plain functions, not `jest.fn()`: a spec's `jest.resetAllMocks()` would
|
|
17
|
+
* strip a mock's implementation and silently blind the guard.
|
|
18
|
+
*/
|
|
19
|
+
function recorder(level) {
|
|
20
|
+
return (type, _message, options) => {
|
|
21
|
+
recorded.push({ level, type, meta: options?.meta });
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A stand-in for the logging module that writes nothing but lets
|
|
26
|
+
* `guardLogMetasAgainstPii` see every meta, for specs that mock the logger:
|
|
27
|
+
*
|
|
28
|
+
* jest.mock('../common/logging/structured-logger', () =>
|
|
29
|
+
* jest.requireActual('@leoribeiroweb/nest-testing/pii').recordingLoggerModule(),
|
|
30
|
+
* );
|
|
31
|
+
*/
|
|
32
|
+
function recordingLoggerModule() {
|
|
33
|
+
return {
|
|
34
|
+
createLogger: (() => Object.fromEntries(LEVELS.map((level) => [level, recorder(level)]))),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function leakOf(type, meta, forbidden) {
|
|
38
|
+
if (meta === undefined)
|
|
39
|
+
return [];
|
|
40
|
+
const text = JSON.stringify(meta) ?? '';
|
|
41
|
+
const hit = text.includes('@') || forbidden.some((value) => text.includes(value));
|
|
42
|
+
return hit ? [`${type} ${text}`] : [];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The guard without the jest hooks: `start()` resets the recordings and spies
|
|
46
|
+
* on the real logger, `stop()` restores it and returns the leaks seen since.
|
|
47
|
+
* Not exported from the subpath; `guardLogMetasAgainstPii` is the API.
|
|
48
|
+
*/
|
|
49
|
+
function logMetaPiiGuard(forbidden, loggers) {
|
|
50
|
+
let spies = [];
|
|
51
|
+
return {
|
|
52
|
+
start: () => {
|
|
53
|
+
recorded.splice(0, recorded.length);
|
|
54
|
+
const { StructuredContextLogger } = jest.requireActual(CORE);
|
|
55
|
+
spies = LEVELS.map((level) => jest.spyOn(StructuredContextLogger.prototype, level));
|
|
56
|
+
},
|
|
57
|
+
stop: () => {
|
|
58
|
+
const mocks = [
|
|
59
|
+
...spies,
|
|
60
|
+
...loggers.flatMap((logger) => Object.values(logger).filter((fn) => fn !== undefined)),
|
|
61
|
+
];
|
|
62
|
+
const leaks = [
|
|
63
|
+
...mocks.flatMap((fn) => fn.mock.calls.flatMap((args) => leakOf(String(args[0]), args[2]?.meta, forbidden))),
|
|
64
|
+
...recorded.flatMap((call) => leakOf(call.type, call.meta, forbidden)),
|
|
65
|
+
];
|
|
66
|
+
spies.forEach((spy) => spy.mockRestore());
|
|
67
|
+
spies = [];
|
|
68
|
+
recorded.splice(0, recorded.length);
|
|
69
|
+
return leaks;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Test helper (social-api#638): every test of the enclosing `describe` fails
|
|
75
|
+
* when a structured log meta it produced contains an `@` (on the console the
|
|
76
|
+
* actor is the operator's e-mail, which is PII) or one of `forbidden` (for
|
|
77
|
+
* example a `tg:<id>` actor the spec uses). It watches the real logger, the
|
|
78
|
+
* recording one of `recordingLoggerModule()`, and any logger mock the spec
|
|
79
|
+
* hands in as `loggers` (all of their `mock.calls` so far are read after each
|
|
80
|
+
* test).
|
|
81
|
+
*/
|
|
82
|
+
function guardLogMetasAgainstPii(forbidden = [], loggers = []) {
|
|
83
|
+
const guard = logMetaPiiGuard(forbidden, loggers);
|
|
84
|
+
beforeEach(() => guard.start());
|
|
85
|
+
afterEach(() => {
|
|
86
|
+
expect(guard.stop()).toEqual([]);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client surface `RedisScript.run` of `@leoribeiroweb/nest-redis` drives.
|
|
3
|
+
* Declared here, structurally identical, so this package needs no peer on
|
|
4
|
+
* `nest-redis`: a `FakeRedis` is accepted wherever that package asks for its
|
|
5
|
+
* own `ScriptableRedis`.
|
|
6
|
+
*/
|
|
7
|
+
export interface ScriptableRedis {
|
|
8
|
+
evalsha(sha: string, ...args: unknown[]): Promise<unknown>;
|
|
9
|
+
eval(script: string, ...args: unknown[]): Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* An in-memory Redis that really runs the Lua.
|
|
13
|
+
*
|
|
14
|
+
* The point of this fixture is that the scripts under test are **executed**,
|
|
15
|
+
* not transcribed: `eval` loads the actual script body into a Lua VM and
|
|
16
|
+
* bridges `redis.call` to the keyspace below. A fake that re-implemented each
|
|
17
|
+
* script in TypeScript would pass against a broken script, which is the whole
|
|
18
|
+
* failure mode an atomic primitive has.
|
|
19
|
+
*
|
|
20
|
+
* Time is a field, not `Date.now()`, so expiry is asserted by advancing the
|
|
21
|
+
* clock instead of by sleeping.
|
|
22
|
+
*/
|
|
23
|
+
export declare class FakeRedis implements ScriptableRedis {
|
|
24
|
+
private readonly keyspace;
|
|
25
|
+
/** Bodies the server has seen, keyed by SHA — Redis's own script cache. */
|
|
26
|
+
private readonly scriptCache;
|
|
27
|
+
/** Every command the scripts issued, in order — lets a test assert atomicity claims. */
|
|
28
|
+
readonly commands: string[][];
|
|
29
|
+
now: number;
|
|
30
|
+
/**
|
|
31
|
+
* A JS error thrown inside the `redis.call` bridge surfaces as a mangled Lua
|
|
32
|
+
* error, because fengari converts it at the VM boundary. Park it here and
|
|
33
|
+
* rethrow it after `lua_pcall` so the test sees the real message.
|
|
34
|
+
*/
|
|
35
|
+
private pendingError;
|
|
36
|
+
/** Advance the fake clock, expiring anything whose TTL has elapsed. */
|
|
37
|
+
advance(ms: number): void;
|
|
38
|
+
get size(): number;
|
|
39
|
+
evalsha(sha: string, ...args: unknown[]): Promise<unknown>;
|
|
40
|
+
eval(script: string, ...args: unknown[]): Promise<unknown>;
|
|
41
|
+
/** `SET key value PX ttl NX`, the one plain command the lock issues. */
|
|
42
|
+
set(key: string, value: string, mode: 'PX', ttlMs: number, condition: 'NX'): Promise<'OK' | null>;
|
|
43
|
+
/** Prime the script cache, the way a previous EVAL on this server would have. */
|
|
44
|
+
register(sha: string, body: string): void;
|
|
45
|
+
private read;
|
|
46
|
+
private ttlMs;
|
|
47
|
+
/**
|
|
48
|
+
* The command surface the shipped scripts use. Anything else throws, so a
|
|
49
|
+
* script that grows a new command cannot quietly pass against a fixture that
|
|
50
|
+
* does not implement it.
|
|
51
|
+
*/
|
|
52
|
+
private call;
|
|
53
|
+
private execute;
|
|
54
|
+
private installRedisTable;
|
|
55
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FakeRedis = void 0;
|
|
4
|
+
const fengari_1 = require("fengari");
|
|
5
|
+
/**
|
|
6
|
+
* An in-memory Redis that really runs the Lua.
|
|
7
|
+
*
|
|
8
|
+
* The point of this fixture is that the scripts under test are **executed**,
|
|
9
|
+
* not transcribed: `eval` loads the actual script body into a Lua VM and
|
|
10
|
+
* bridges `redis.call` to the keyspace below. A fake that re-implemented each
|
|
11
|
+
* script in TypeScript would pass against a broken script, which is the whole
|
|
12
|
+
* failure mode an atomic primitive has.
|
|
13
|
+
*
|
|
14
|
+
* Time is a field, not `Date.now()`, so expiry is asserted by advancing the
|
|
15
|
+
* clock instead of by sleeping.
|
|
16
|
+
*/
|
|
17
|
+
class FakeRedis {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.keyspace = new Map();
|
|
20
|
+
/** Bodies the server has seen, keyed by SHA — Redis's own script cache. */
|
|
21
|
+
this.scriptCache = new Map();
|
|
22
|
+
/** Every command the scripts issued, in order — lets a test assert atomicity claims. */
|
|
23
|
+
this.commands = [];
|
|
24
|
+
this.now = 1_000_000;
|
|
25
|
+
}
|
|
26
|
+
/** Advance the fake clock, expiring anything whose TTL has elapsed. */
|
|
27
|
+
advance(ms) {
|
|
28
|
+
this.now += ms;
|
|
29
|
+
}
|
|
30
|
+
get size() {
|
|
31
|
+
let live = 0;
|
|
32
|
+
for (const key of this.keyspace.keys())
|
|
33
|
+
if (this.read(key) !== undefined)
|
|
34
|
+
live += 1;
|
|
35
|
+
return live;
|
|
36
|
+
}
|
|
37
|
+
async evalsha(sha, ...args) {
|
|
38
|
+
const body = this.scriptCache.get(sha);
|
|
39
|
+
if (body === undefined) {
|
|
40
|
+
throw new Error('NOSCRIPT No matching script. Please use EVAL.');
|
|
41
|
+
}
|
|
42
|
+
return this.execute(body, args);
|
|
43
|
+
}
|
|
44
|
+
async eval(script, ...args) {
|
|
45
|
+
return this.execute(script, args);
|
|
46
|
+
}
|
|
47
|
+
/** `SET key value PX ttl NX`, the one plain command the lock issues. */
|
|
48
|
+
async set(key, value, mode, ttlMs, condition) {
|
|
49
|
+
return this.call(['SET', key, value, mode, String(ttlMs), condition]);
|
|
50
|
+
}
|
|
51
|
+
/** Prime the script cache, the way a previous EVAL on this server would have. */
|
|
52
|
+
register(sha, body) {
|
|
53
|
+
this.scriptCache.set(sha, body);
|
|
54
|
+
}
|
|
55
|
+
// ---- keyspace ---------------------------------------------------------
|
|
56
|
+
read(key) {
|
|
57
|
+
const entry = this.keyspace.get(key);
|
|
58
|
+
if (entry === undefined)
|
|
59
|
+
return undefined;
|
|
60
|
+
if (entry.expiresAt !== undefined && entry.expiresAt <= this.now) {
|
|
61
|
+
this.keyspace.delete(key);
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
return entry.value;
|
|
65
|
+
}
|
|
66
|
+
ttlMs(key) {
|
|
67
|
+
const entry = this.keyspace.get(key);
|
|
68
|
+
if (entry === undefined || this.read(key) === undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
return entry.expiresAt === undefined ? undefined : entry.expiresAt - this.now;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The command surface the shipped scripts use. Anything else throws, so a
|
|
74
|
+
* script that grows a new command cannot quietly pass against a fixture that
|
|
75
|
+
* does not implement it.
|
|
76
|
+
*/
|
|
77
|
+
call(args) {
|
|
78
|
+
this.commands.push(args);
|
|
79
|
+
const [name, key, ...rest] = args;
|
|
80
|
+
switch (name.toUpperCase()) {
|
|
81
|
+
case 'GET':
|
|
82
|
+
return this.read(key) ?? null;
|
|
83
|
+
case 'SET': {
|
|
84
|
+
const value = rest[0];
|
|
85
|
+
const nx = rest.some((a) => a.toUpperCase() === 'NX');
|
|
86
|
+
const pxIndex = rest.findIndex((a) => a.toUpperCase() === 'PX');
|
|
87
|
+
if (nx && this.read(key) !== undefined)
|
|
88
|
+
return null;
|
|
89
|
+
const expiresAt = pxIndex >= 0 ? this.now + Number(rest[pxIndex + 1]) : undefined;
|
|
90
|
+
this.keyspace.set(key, { value, expiresAt });
|
|
91
|
+
return 'OK';
|
|
92
|
+
}
|
|
93
|
+
case 'DEL': {
|
|
94
|
+
const existed = this.read(key) !== undefined;
|
|
95
|
+
this.keyspace.delete(key);
|
|
96
|
+
return existed ? 1 : 0;
|
|
97
|
+
}
|
|
98
|
+
case 'INCR': {
|
|
99
|
+
const next = Number(this.read(key) ?? '0') + 1;
|
|
100
|
+
const entry = this.keyspace.get(key);
|
|
101
|
+
this.keyspace.set(key, {
|
|
102
|
+
value: String(next),
|
|
103
|
+
expiresAt: this.read(key) === undefined ? undefined : entry?.expiresAt,
|
|
104
|
+
});
|
|
105
|
+
return next;
|
|
106
|
+
}
|
|
107
|
+
case 'EXPIRE': {
|
|
108
|
+
if (this.read(key) === undefined)
|
|
109
|
+
return 0;
|
|
110
|
+
const entry = this.keyspace.get(key);
|
|
111
|
+
entry.expiresAt = this.now + Number(rest[0]) * 1000;
|
|
112
|
+
return 1;
|
|
113
|
+
}
|
|
114
|
+
case 'PEXPIRE': {
|
|
115
|
+
if (this.read(key) === undefined)
|
|
116
|
+
return 0;
|
|
117
|
+
const entry = this.keyspace.get(key);
|
|
118
|
+
entry.expiresAt = this.now + Number(rest[0]);
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
case 'TTL': {
|
|
122
|
+
const ms = this.ttlMs(key);
|
|
123
|
+
if (this.read(key) === undefined)
|
|
124
|
+
return -2;
|
|
125
|
+
return ms === undefined ? -1 : Math.ceil(ms / 1000);
|
|
126
|
+
}
|
|
127
|
+
case 'PTTL': {
|
|
128
|
+
const ms = this.ttlMs(key);
|
|
129
|
+
if (this.read(key) === undefined)
|
|
130
|
+
return -2;
|
|
131
|
+
return ms === undefined ? -1 : ms;
|
|
132
|
+
}
|
|
133
|
+
default:
|
|
134
|
+
throw new Error(`FakeRedis does not implement ${name}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// ---- Lua --------------------------------------------------------------
|
|
138
|
+
execute(script, args) {
|
|
139
|
+
const numKeys = Number(args[0]);
|
|
140
|
+
const keys = args.slice(1, 1 + numKeys).map(String);
|
|
141
|
+
const argv = args.slice(1 + numKeys).map(String);
|
|
142
|
+
const L = fengari_1.lauxlib.luaL_newstate();
|
|
143
|
+
fengari_1.lualib.luaL_openlibs(L);
|
|
144
|
+
this.installRedisTable(L);
|
|
145
|
+
pushArray(L, 'KEYS', keys);
|
|
146
|
+
pushArray(L, 'ARGV', argv);
|
|
147
|
+
if (fengari_1.lauxlib.luaL_loadstring(L, (0, fengari_1.to_luastring)(script)) !== fengari_1.lua.LUA_OK) {
|
|
148
|
+
throw new Error(`Lua load error: ${fengari_1.lua.lua_tojsstring(L, -1)}`);
|
|
149
|
+
}
|
|
150
|
+
if (fengari_1.lua.lua_pcall(L, 0, 1, 0) !== fengari_1.lua.LUA_OK) {
|
|
151
|
+
const bridged = this.pendingError;
|
|
152
|
+
this.pendingError = undefined;
|
|
153
|
+
throw bridged ?? new Error(`Lua runtime error: ${fengari_1.lua.lua_tojsstring(L, -1)}`);
|
|
154
|
+
}
|
|
155
|
+
return readResult(L);
|
|
156
|
+
}
|
|
157
|
+
installRedisTable(L) {
|
|
158
|
+
fengari_1.lua.lua_newtable(L);
|
|
159
|
+
fengari_1.lua.lua_pushjsclosure(L, (state) => {
|
|
160
|
+
const top = fengari_1.lua.lua_gettop(state);
|
|
161
|
+
const args = [];
|
|
162
|
+
for (let i = 1; i <= top; i += 1)
|
|
163
|
+
args.push(fengari_1.lua.lua_tojsstring(state, i));
|
|
164
|
+
let result;
|
|
165
|
+
try {
|
|
166
|
+
result = this.call(args);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
this.pendingError = error;
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
// Redis converts a nil bulk reply to Lua `false`, not `nil`. The
|
|
173
|
+
// difference is invisible to the shipped scripts (both are falsy
|
|
174
|
+
// against a string compare) and decisive for one that tests
|
|
175
|
+
// `== false`, so the fixture models the real conversion.
|
|
176
|
+
if (result === null)
|
|
177
|
+
fengari_1.lua.lua_pushboolean(state, false);
|
|
178
|
+
else if (typeof result === 'number')
|
|
179
|
+
fengari_1.lua.lua_pushinteger(state, result);
|
|
180
|
+
else
|
|
181
|
+
fengari_1.lua.lua_pushstring(state, (0, fengari_1.to_luastring)(result));
|
|
182
|
+
return 1;
|
|
183
|
+
}, 0);
|
|
184
|
+
fengari_1.lua.lua_setfield(L, -2, (0, fengari_1.to_luastring)('call'));
|
|
185
|
+
fengari_1.lua.lua_setglobal(L, (0, fengari_1.to_luastring)('redis'));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.FakeRedis = FakeRedis;
|
|
189
|
+
function pushArray(L, name, values) {
|
|
190
|
+
fengari_1.lua.lua_createtable(L, values.length, 0);
|
|
191
|
+
values.forEach((value, index) => {
|
|
192
|
+
fengari_1.lua.lua_pushstring(L, (0, fengari_1.to_luastring)(value));
|
|
193
|
+
fengari_1.lua.lua_seti(L, -2, index + 1);
|
|
194
|
+
});
|
|
195
|
+
fengari_1.lua.lua_setglobal(L, (0, fengari_1.to_luastring)(name));
|
|
196
|
+
}
|
|
197
|
+
/** Convert the single Lua return value: nil, a number, or a flat array of numbers. */
|
|
198
|
+
function readResult(L) {
|
|
199
|
+
const type = fengari_1.lua.lua_type(L, -1);
|
|
200
|
+
// A script returning `nil` or `false` is a nil reply on the wire; both come
|
|
201
|
+
// back to the client as `null`.
|
|
202
|
+
if (type === fengari_1.lua.LUA_TNIL || type === fengari_1.lua.LUA_TBOOLEAN)
|
|
203
|
+
return null;
|
|
204
|
+
if (type === fengari_1.lua.LUA_TTABLE) {
|
|
205
|
+
const length = fengari_1.lua.lua_rawlen(L, -1);
|
|
206
|
+
const out = [];
|
|
207
|
+
for (let i = 1; i <= length; i += 1) {
|
|
208
|
+
fengari_1.lua.lua_rawgeti(L, -1, i);
|
|
209
|
+
out.push(fengari_1.lua.lua_tointeger(L, -1));
|
|
210
|
+
fengari_1.lua.lua_pop(L, 1);
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
213
|
+
}
|
|
214
|
+
return fengari_1.lua.lua_tointeger(L, -1);
|
|
215
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FakeRedis, type ScriptableRedis } from './fake-redis';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FakeRedis = void 0;
|
|
4
|
+
var fake_redis_1 = require("./fake-redis");
|
|
5
|
+
Object.defineProperty(exports, "FakeRedis", { enumerable: true, get: function () { return fake_redis_1.FakeRedis; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
2
|
+
export interface InMemoryTracing {
|
|
3
|
+
/** Every span ended since install (or the last `reset`). */
|
|
4
|
+
spans(): ReadableSpan[];
|
|
5
|
+
reset(): void;
|
|
6
|
+
uninstall(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare function installInMemoryTracing(): InMemoryTracing;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installInMemoryTracing = installInMemoryTracing;
|
|
4
|
+
/**
|
|
5
|
+
* A real tracer provider for specs that assert on the spans `runInRootSpan`
|
|
6
|
+
* produces. Registers a `BasicTracerProvider` with an in-memory exporter and
|
|
7
|
+
* an AsyncLocalStorage context manager as the OTel globals, which is what the
|
|
8
|
+
* NodeSDK does in production; `uninstall()` puts the noop globals back so no
|
|
9
|
+
* other spec in the same worker sees a live tracer.
|
|
10
|
+
*/
|
|
11
|
+
const api_1 = require("@opentelemetry/api");
|
|
12
|
+
const context_async_hooks_1 = require("@opentelemetry/context-async-hooks");
|
|
13
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
14
|
+
function installInMemoryTracing() {
|
|
15
|
+
const exporter = new sdk_trace_base_1.InMemorySpanExporter();
|
|
16
|
+
const provider = new sdk_trace_base_1.BasicTracerProvider({
|
|
17
|
+
spanProcessors: [new sdk_trace_base_1.SimpleSpanProcessor(exporter)],
|
|
18
|
+
});
|
|
19
|
+
const contextManager = new context_async_hooks_1.AsyncLocalStorageContextManager().enable();
|
|
20
|
+
api_1.context.setGlobalContextManager(contextManager);
|
|
21
|
+
api_1.trace.setGlobalTracerProvider(provider);
|
|
22
|
+
return {
|
|
23
|
+
spans: () => exporter.getFinishedSpans(),
|
|
24
|
+
reset: () => exporter.reset(),
|
|
25
|
+
uninstall: async () => {
|
|
26
|
+
await provider.shutdown();
|
|
27
|
+
api_1.trace.disable();
|
|
28
|
+
api_1.context.disable();
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { installInMemoryTracing, type InMemoryTracing } from './in-memory-tracing';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installInMemoryTracing = void 0;
|
|
4
|
+
var in_memory_tracing_1 = require("./in-memory-tracing");
|
|
5
|
+
Object.defineProperty(exports, "installInMemoryTracing", { enumerable: true, get: function () { return in_memory_tracing_1.installInMemoryTracing; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,151 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leoribeiroweb/nest-testing",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Test helpers for the NestJS services, one subpath per family: a shared in-memory mongod for jest (`./mongo`), an in-memory OpenTelemetry tracer (`./tracing`), stdout/stderr capture (`./logging`), an axios double (`./http`), a Redis fake that runs the real Lua (`./redis`) and a guard that fails a test whose log metas carry PII (`./pii`).",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/leoribeiro2/nest-core.git",
|
|
9
|
+
"directory": "packages/nest-testing"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/leoribeiro2/nest-core/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/leoribeiro2/nest-core#readme",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./http": {
|
|
23
|
+
"types": "./dist/http/index.d.ts",
|
|
24
|
+
"default": "./dist/http/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./logging": {
|
|
27
|
+
"types": "./dist/logging/index.d.ts",
|
|
28
|
+
"default": "./dist/logging/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./mongo": {
|
|
31
|
+
"types": "./dist/mongo/index.d.ts",
|
|
32
|
+
"default": "./dist/mongo/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./mongo/global-setup": {
|
|
35
|
+
"types": "./dist/mongo/global-setup.d.ts",
|
|
36
|
+
"default": "./dist/mongo/global-setup.js"
|
|
37
|
+
},
|
|
38
|
+
"./mongo/global-teardown": {
|
|
39
|
+
"types": "./dist/mongo/global-teardown.d.ts",
|
|
40
|
+
"default": "./dist/mongo/global-teardown.js"
|
|
41
|
+
},
|
|
42
|
+
"./mongo/runtime-adapters-shim": {
|
|
43
|
+
"types": "./dist/mongo/runtime-adapters-shim.d.ts",
|
|
44
|
+
"default": "./dist/mongo/runtime-adapters-shim.js"
|
|
45
|
+
},
|
|
46
|
+
"./pii": {
|
|
47
|
+
"types": "./dist/pii/index.d.ts",
|
|
48
|
+
"default": "./dist/pii/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./redis": {
|
|
51
|
+
"types": "./dist/redis/index.d.ts",
|
|
52
|
+
"default": "./dist/redis/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./tracing": {
|
|
55
|
+
"types": "./dist/tracing/index.d.ts",
|
|
56
|
+
"default": "./dist/tracing/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./package.json": "./package.json"
|
|
59
|
+
},
|
|
60
|
+
"typesVersions": {
|
|
61
|
+
"*": {
|
|
62
|
+
"http": [
|
|
63
|
+
"dist/http/index.d.ts"
|
|
64
|
+
],
|
|
65
|
+
"logging": [
|
|
66
|
+
"dist/logging/index.d.ts"
|
|
67
|
+
],
|
|
68
|
+
"mongo": [
|
|
69
|
+
"dist/mongo/index.d.ts"
|
|
70
|
+
],
|
|
71
|
+
"mongo/global-setup": [
|
|
72
|
+
"dist/mongo/global-setup.d.ts"
|
|
73
|
+
],
|
|
74
|
+
"mongo/global-teardown": [
|
|
75
|
+
"dist/mongo/global-teardown.d.ts"
|
|
76
|
+
],
|
|
77
|
+
"mongo/runtime-adapters-shim": [
|
|
78
|
+
"dist/mongo/runtime-adapters-shim.d.ts"
|
|
79
|
+
],
|
|
80
|
+
"pii": [
|
|
81
|
+
"dist/pii/index.d.ts"
|
|
82
|
+
],
|
|
83
|
+
"redis": [
|
|
84
|
+
"dist/redis/index.d.ts"
|
|
85
|
+
],
|
|
86
|
+
"tracing": [
|
|
87
|
+
"dist/tracing/index.d.ts"
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"files": [
|
|
92
|
+
"dist"
|
|
93
|
+
],
|
|
94
|
+
"engines": {
|
|
95
|
+
"node": ">=20.11.0"
|
|
96
|
+
},
|
|
97
|
+
"publishConfig": {
|
|
98
|
+
"access": "public"
|
|
99
|
+
},
|
|
100
|
+
"scripts": {
|
|
101
|
+
"build": "tsc -p tsconfig.build.json",
|
|
102
|
+
"prepublishOnly": "npm run build"
|
|
103
|
+
},
|
|
104
|
+
"peerDependencies": {
|
|
105
|
+
"@leoribeiroweb/nest-core": ">=0.2.0 <1.0.0",
|
|
106
|
+
"@opentelemetry/api": "^1.9",
|
|
107
|
+
"@opentelemetry/context-async-hooks": "^2",
|
|
108
|
+
"@opentelemetry/sdk-trace-base": "^2",
|
|
109
|
+
"axios": "^1",
|
|
110
|
+
"fengari": "^0.1.5",
|
|
111
|
+
"jest": "^29 || ^30",
|
|
112
|
+
"mongodb-memory-server": "^11",
|
|
113
|
+
"mongoose": "^9"
|
|
114
|
+
},
|
|
115
|
+
"peerDependenciesMeta": {
|
|
116
|
+
"@opentelemetry/api": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
119
|
+
"@opentelemetry/context-async-hooks": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"@opentelemetry/sdk-trace-base": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"axios": {
|
|
126
|
+
"optional": true
|
|
127
|
+
},
|
|
128
|
+
"fengari": {
|
|
129
|
+
"optional": true
|
|
130
|
+
},
|
|
131
|
+
"jest": {
|
|
132
|
+
"optional": true
|
|
133
|
+
},
|
|
134
|
+
"mongodb-memory-server": {
|
|
135
|
+
"optional": true
|
|
136
|
+
},
|
|
137
|
+
"mongoose": {
|
|
138
|
+
"optional": true
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"devDependencies": {
|
|
142
|
+
"@leoribeiroweb/nest-core": "*",
|
|
143
|
+
"@opentelemetry/api": "^1.9.1",
|
|
144
|
+
"@opentelemetry/context-async-hooks": "^2.11.0",
|
|
145
|
+
"@opentelemetry/sdk-trace-base": "^2.11.0",
|
|
146
|
+
"axios": "1.18.1",
|
|
147
|
+
"fengari": "^0.1.5",
|
|
148
|
+
"mongodb-memory-server": "^11.1.0",
|
|
149
|
+
"mongoose": "^9.12.1"
|
|
150
|
+
}
|
|
151
|
+
}
|