@jongodb/memory-server 0.1.2 → 0.1.3
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 +113 -139
- package/dist/cjs/index.js +50 -4
- package/dist/cjs/runtime.js +59 -17
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +50 -4
- package/dist/esm/jest.d.ts +1 -0
- package/dist/esm/jest.d.ts.map +1 -1
- package/dist/esm/runtime.d.ts +2 -0
- package/dist/esm/runtime.d.ts.map +1 -1
- package/dist/esm/runtime.js +59 -17
- package/dist/esm/vitest.d.ts +1 -0
- package/dist/esm/vitest.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,68 +1,38 @@
|
|
|
1
1
|
# @jongodb/memory-server
|
|
2
2
|
|
|
3
|
-
Node test runtime adapter for `jongodb
|
|
3
|
+
Node test runtime adapter for [`jongodb`](https://github.com/midagedev/jongodb).
|
|
4
4
|
|
|
5
|
-
It starts a local `jongodb` launcher process,
|
|
5
|
+
It starts a local `jongodb` launcher process, provides a MongoDB URI, and manages lifecycle for test runners.
|
|
6
|
+
|
|
7
|
+
## Why This Package Exists
|
|
8
|
+
|
|
9
|
+
`mongodb-memory-server` is useful, but it still depends on `mongod` bootstrap behavior.
|
|
10
|
+
|
|
11
|
+
`@jongodb/memory-server` focuses on a different tradeoff:
|
|
12
|
+
- faster integration-test startup loops
|
|
13
|
+
- deterministic local process lifecycle control
|
|
14
|
+
- simple test runner integration (Jest, Vitest, Nest Jest)
|
|
15
|
+
|
|
16
|
+
This package is for test runtime usage only. It is not a production MongoDB server.
|
|
17
|
+
|
|
18
|
+
## Value for Integration Test Suites
|
|
19
|
+
|
|
20
|
+
Observed benchmark summary on one NestJS integration suite shape:
|
|
21
|
+
- historical suite-scoped lifecycle: about `55.9%` faster than `mongodb-memory-server`
|
|
22
|
+
- current single-boot lifecycle: about `64.2%` faster than `mongodb-memory-server`
|
|
23
|
+
|
|
24
|
+
Actual deltas vary by test shape, dataset size, and CI machine characteristics.
|
|
6
25
|
|
|
7
26
|
## Scope
|
|
8
27
|
|
|
9
|
-
- integration-test runtime
|
|
10
|
-
- launcher
|
|
11
|
-
- framework-agnostic
|
|
12
|
-
- Jest
|
|
13
|
-
|
|
14
|
-
This package is not a production MongoDB server.
|
|
15
|
-
|
|
16
|
-
## Why This vs Embedded MongoDB (`mongodb-memory-server`)
|
|
17
|
-
|
|
18
|
-
`@jongodb/memory-server` can run in native binary mode instead of booting a full `mongod` test binary.
|
|
19
|
-
|
|
20
|
-
Practical effects:
|
|
21
|
-
|
|
22
|
-
- no `mongod` binary download/extract step in cold environments
|
|
23
|
-
- lower launcher startup overhead in many integration-test loops
|
|
24
|
-
- fewer environment issues tied to `mongod` binary provisioning
|
|
25
|
-
|
|
26
|
-
Rough performance expectation (not a guarantee):
|
|
27
|
-
|
|
28
|
-
- cold CI/dev machine: often much faster because there is no `mongod` artifact fetch/unpack
|
|
29
|
-
- warm cache environment: startup-phase wins are usually smaller
|
|
30
|
-
|
|
31
|
-
Observed benchmarks (NestJS integration suite subset, same machine):
|
|
32
|
-
|
|
33
|
-
- Benchmark A: suite-scoped lifecycle (historical)
|
|
34
|
-
- workload: `9 suites / 102 tests` (`--runInBand`)
|
|
35
|
-
- server boots: `9` times per run (once per suite)
|
|
36
|
-
- `mongodb-memory-server` real:
|
|
37
|
-
- run1: `28.17s`
|
|
38
|
-
- run2: `27.19s`
|
|
39
|
-
- average: `27.68s`
|
|
40
|
-
- `jongodb` native real:
|
|
41
|
-
- run1: `12.35s`
|
|
42
|
-
- run2: `12.04s`
|
|
43
|
-
- average: `12.20s`
|
|
44
|
-
- delta: about `55.9%` faster (`15.48s` less wall clock)
|
|
45
|
-
- Benchmark B: single-boot lifecycle (current)
|
|
46
|
-
- workload: `45 suites / 510 tests` (`--runInBand`)
|
|
47
|
-
- server boots: `1` time per run (shared for full Jest process)
|
|
48
|
-
- `mongodb-memory-server` real:
|
|
49
|
-
- run1: `92.40s`
|
|
50
|
-
- run2: `91.84s`
|
|
51
|
-
- average: `92.12s`
|
|
52
|
-
- `jongodb` native real:
|
|
53
|
-
- run1: `33.03s`
|
|
54
|
-
- run2: `32.90s`
|
|
55
|
-
- average: `32.97s`
|
|
56
|
-
- delta: about `64.2%` faster (`59.15s` less wall clock)
|
|
57
|
-
|
|
58
|
-
Your actual delta depends on test shape, I/O, and query workload.
|
|
28
|
+
- integration-test runtime helper
|
|
29
|
+
- launcher process start/stop/detach lifecycle
|
|
30
|
+
- framework-agnostic runtime API
|
|
31
|
+
- convenience hooks for Jest, Vitest, and Nest Jest
|
|
59
32
|
|
|
60
33
|
## Requirements
|
|
61
34
|
|
|
62
35
|
- Node.js 20+
|
|
63
|
-
- one launcher runtime:
|
|
64
|
-
- native binary, or
|
|
65
|
-
- Java 17+ with `jongodb` classpath
|
|
66
36
|
|
|
67
37
|
## Install
|
|
68
38
|
|
|
@@ -73,20 +43,21 @@ npm i -D @jongodb/memory-server
|
|
|
73
43
|
## Module Format
|
|
74
44
|
|
|
75
45
|
This package supports both:
|
|
76
|
-
|
|
77
46
|
- ESM (`import`)
|
|
78
47
|
- CommonJS (`require`)
|
|
79
48
|
|
|
80
|
-
## Quick Start
|
|
49
|
+
## Quick Start
|
|
81
50
|
|
|
82
|
-
|
|
51
|
+
Recommended pattern: one runtime per test process.
|
|
83
52
|
|
|
84
53
|
```ts
|
|
85
54
|
import { beforeAll, afterAll } from "@jest/globals";
|
|
86
55
|
import { createJongodbEnvRuntime } from "@jongodb/memory-server/runtime";
|
|
87
56
|
|
|
88
57
|
const runtime = createJongodbEnvRuntime({
|
|
89
|
-
databaseName: "test"
|
|
58
|
+
databaseName: "test",
|
|
59
|
+
databaseNameStrategy: "worker",
|
|
60
|
+
envVarNames: ["MONGODB_URI", "DATABASE_URL"],
|
|
90
61
|
});
|
|
91
62
|
|
|
92
63
|
beforeAll(async () => {
|
|
@@ -98,85 +69,67 @@ afterAll(async () => {
|
|
|
98
69
|
});
|
|
99
70
|
```
|
|
100
71
|
|
|
72
|
+
Runtime behavior:
|
|
73
|
+
- `setup()` starts launcher and writes URI to configured env key(s)
|
|
74
|
+
- `teardown()` stops launcher and restores previous env values
|
|
75
|
+
|
|
101
76
|
CommonJS example:
|
|
102
77
|
|
|
103
78
|
```js
|
|
104
79
|
const { createJongodbEnvRuntime } = require("@jongodb/memory-server/runtime");
|
|
105
|
-
|
|
106
80
|
const runtime = createJongodbEnvRuntime({ databaseName: "test" });
|
|
107
81
|
```
|
|
108
82
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
- `setup()` starts launcher and writes `process.env.MONGODB_URI` (default)
|
|
112
|
-
- `teardown()` stops launcher and restores previous env value
|
|
113
|
-
|
|
114
|
-
## Launcher Modes
|
|
115
|
-
|
|
116
|
-
`launchMode` values:
|
|
117
|
-
|
|
118
|
-
- `auto` (default): binary first, Java fallback
|
|
119
|
-
- `binary`: binary only, fail fast if binary not resolvable
|
|
120
|
-
- `java`: Java only, fail fast if classpath not configured
|
|
121
|
-
|
|
122
|
-
In `auto` mode, launch failures are attempted in order and reported with source tags.
|
|
83
|
+
## Migration from `mongodb-memory-server`
|
|
123
84
|
|
|
124
|
-
|
|
85
|
+
Basic Jest migration:
|
|
125
86
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
1. `options.binaryPath`
|
|
129
|
-
2. `JONGODB_BINARY_PATH`
|
|
130
|
-
3. bundled platform package (if installed)
|
|
131
|
-
|
|
132
|
-
Current bundled package targets:
|
|
133
|
-
|
|
134
|
-
- `@jongodb/memory-server-bin-darwin-arm64`
|
|
135
|
-
- `@jongodb/memory-server-bin-linux-x64-gnu`
|
|
136
|
-
- `@jongodb/memory-server-bin-win32-x64`
|
|
87
|
+
Before:
|
|
137
88
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
- binary package versions are pinned to the core package version (`optionalDependencies`)
|
|
141
|
-
- if a bundled binary is not installed/available for your version, `auto` mode can still run with Java fallback
|
|
89
|
+
```ts
|
|
90
|
+
import { MongoMemoryServer } from "mongodb-memory-server";
|
|
142
91
|
|
|
143
|
-
|
|
92
|
+
let mongod: MongoMemoryServer;
|
|
144
93
|
|
|
145
|
-
|
|
146
|
-
|
|
94
|
+
beforeAll(async () => {
|
|
95
|
+
mongod = await MongoMemoryServer.create();
|
|
96
|
+
process.env.MONGODB_URI = mongod.getUri();
|
|
97
|
+
});
|
|
147
98
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
binaryPath: process.env.JONGODB_BINARY_PATH
|
|
99
|
+
afterAll(async () => {
|
|
100
|
+
await mongod.stop();
|
|
151
101
|
});
|
|
152
102
|
```
|
|
153
103
|
|
|
154
|
-
|
|
104
|
+
After:
|
|
155
105
|
|
|
156
|
-
|
|
106
|
+
```ts
|
|
107
|
+
import { beforeAll, afterAll } from "@jest/globals";
|
|
108
|
+
import { createJongodbEnvRuntime } from "@jongodb/memory-server/runtime";
|
|
157
109
|
|
|
158
|
-
|
|
159
|
-
2. `JONGODB_CLASSPATH`
|
|
110
|
+
const runtime = createJongodbEnvRuntime({ databaseName: "test" });
|
|
160
111
|
|
|
161
|
-
|
|
112
|
+
beforeAll(async () => {
|
|
113
|
+
await runtime.setup();
|
|
114
|
+
});
|
|
162
115
|
|
|
163
|
-
|
|
164
|
-
|
|
116
|
+
afterAll(async () => {
|
|
117
|
+
await runtime.teardown();
|
|
118
|
+
});
|
|
165
119
|
```
|
|
166
120
|
|
|
167
|
-
|
|
121
|
+
Option mapping:
|
|
122
|
+
- `MongoMemoryServer.create({ instance: { port } })` -> `createJongodbEnvRuntime({ port })`
|
|
123
|
+
- `MongoMemoryServer.create({ instance: { dbName } })` -> `createJongodbEnvRuntime({ databaseName })`
|
|
124
|
+
- `mongod.getUri()` -> `runtime.uri` (after `setup`) or configured env var
|
|
125
|
+
- `mongod.stop()` -> `runtime.teardown()`
|
|
168
126
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
- readiness line on stdout: `JONGODB_URI=mongodb://...`
|
|
172
|
-
- optional failure line on stderr: `JONGODB_START_FAILURE=...`
|
|
173
|
-
- process remains alive until terminated by signal (`SIGTERM`/`SIGINT`)
|
|
174
|
-
|
|
175
|
-
The adapter relies on this contract for deterministic startup/teardown handling.
|
|
127
|
+
Parallel test tip:
|
|
128
|
+
- set `databaseNameStrategy: "worker"` to isolate worker data by database name
|
|
176
129
|
|
|
177
|
-
## Runner
|
|
130
|
+
## Runner Integrations
|
|
178
131
|
|
|
179
|
-
|
|
132
|
+
Jest (per-file hooks):
|
|
180
133
|
|
|
181
134
|
```ts
|
|
182
135
|
import { beforeAll, afterAll } from "@jest/globals";
|
|
@@ -185,9 +138,9 @@ import { registerJongodbForJest } from "@jongodb/memory-server/jest";
|
|
|
185
138
|
registerJongodbForJest({ beforeAll, afterAll });
|
|
186
139
|
```
|
|
187
140
|
|
|
188
|
-
|
|
141
|
+
Jest (global setup/teardown):
|
|
189
142
|
|
|
190
|
-
`jest.global-setup.ts
|
|
143
|
+
`jest.global-setup.ts`
|
|
191
144
|
|
|
192
145
|
```ts
|
|
193
146
|
import { createJestGlobalSetup } from "@jongodb/memory-server/jest";
|
|
@@ -195,7 +148,7 @@ import { createJestGlobalSetup } from "@jongodb/memory-server/jest";
|
|
|
195
148
|
export default createJestGlobalSetup();
|
|
196
149
|
```
|
|
197
150
|
|
|
198
|
-
`jest.global-teardown.ts
|
|
151
|
+
`jest.global-teardown.ts`
|
|
199
152
|
|
|
200
153
|
```ts
|
|
201
154
|
import { createJestGlobalTeardown } from "@jongodb/memory-server/jest";
|
|
@@ -203,7 +156,7 @@ import { createJestGlobalTeardown } from "@jongodb/memory-server/jest";
|
|
|
203
156
|
export default createJestGlobalTeardown();
|
|
204
157
|
```
|
|
205
158
|
|
|
206
|
-
|
|
159
|
+
Vitest:
|
|
207
160
|
|
|
208
161
|
```ts
|
|
209
162
|
import { beforeAll, afterAll } from "vitest";
|
|
@@ -212,7 +165,7 @@ import { registerJongodbForVitest } from "@jongodb/memory-server/vitest";
|
|
|
212
165
|
registerJongodbForVitest({ beforeAll, afterAll });
|
|
213
166
|
```
|
|
214
167
|
|
|
215
|
-
|
|
168
|
+
NestJS (Jest E2E):
|
|
216
169
|
|
|
217
170
|
```ts
|
|
218
171
|
import { beforeAll, afterAll } from "@jest/globals";
|
|
@@ -221,25 +174,45 @@ import { registerJongodbForNestJest } from "@jongodb/memory-server/nestjs";
|
|
|
221
174
|
registerJongodbForNestJest({ beforeAll, afterAll });
|
|
222
175
|
```
|
|
223
176
|
|
|
224
|
-
|
|
177
|
+
Common patterns:
|
|
178
|
+
- NestJS + Mongoose: use `process.env.MONGODB_URI` in `forRootAsync`
|
|
179
|
+
- Prisma (Mongo): set runtime `envVarNames` to include `DATABASE_URL`
|
|
180
|
+
- TypeORM (Mongo): pass runtime URI into `url`
|
|
181
|
+
|
|
182
|
+
## Runtime Resolution
|
|
225
183
|
|
|
226
|
-
|
|
227
|
-
-
|
|
228
|
-
-
|
|
229
|
-
-
|
|
184
|
+
`launchMode` values:
|
|
185
|
+
- `auto` (default): binary first, Java fallback
|
|
186
|
+
- `binary`: binary only
|
|
187
|
+
- `java`: Java only
|
|
188
|
+
|
|
189
|
+
Binary resolution order:
|
|
190
|
+
1. `options.binaryPath`
|
|
191
|
+
2. `JONGODB_BINARY_PATH`
|
|
192
|
+
3. bundled platform binary package
|
|
193
|
+
|
|
194
|
+
Bundled targets:
|
|
195
|
+
- `@jongodb/memory-server-bin-darwin-arm64`
|
|
196
|
+
- `@jongodb/memory-server-bin-linux-x64-gnu`
|
|
197
|
+
- `@jongodb/memory-server-bin-win32-x64`
|
|
198
|
+
|
|
199
|
+
Java fallback:
|
|
200
|
+
- set `classpath` option or `JONGODB_CLASSPATH`
|
|
201
|
+
|
|
202
|
+
Launcher contract:
|
|
203
|
+
- stdout ready line: `JONGODB_URI=mongodb://...`
|
|
204
|
+
- optional stderr failure line: `JONGODB_START_FAILURE=...`
|
|
205
|
+
- process stays alive until termination signal
|
|
230
206
|
|
|
231
207
|
## API Surface
|
|
232
208
|
|
|
233
209
|
Main export (`@jongodb/memory-server`):
|
|
234
|
-
|
|
235
210
|
- `startJongodbMemoryServer(options?)`
|
|
236
211
|
|
|
237
212
|
Runtime export (`@jongodb/memory-server/runtime`):
|
|
238
|
-
|
|
239
213
|
- `createJongodbEnvRuntime(options?)`
|
|
240
214
|
|
|
241
215
|
Jest export (`@jongodb/memory-server/jest`):
|
|
242
|
-
|
|
243
216
|
- `registerJongodbForJest(hooks, options?)`
|
|
244
217
|
- `createJestGlobalSetup(options?)`
|
|
245
218
|
- `createJestGlobalTeardown(options?)`
|
|
@@ -247,39 +220,40 @@ Jest export (`@jongodb/memory-server/jest`):
|
|
|
247
220
|
- `readJestGlobalUri(options?)`
|
|
248
221
|
|
|
249
222
|
Nest export (`@jongodb/memory-server/nestjs`):
|
|
250
|
-
|
|
251
223
|
- `registerJongodbForNestJest(hooks, options?)`
|
|
252
224
|
|
|
253
225
|
Vitest export (`@jongodb/memory-server/vitest`):
|
|
254
|
-
|
|
255
226
|
- `registerJongodbForVitest(hooks, options?)`
|
|
256
227
|
|
|
257
228
|
## Options Reference
|
|
258
229
|
|
|
259
|
-
Core
|
|
260
|
-
|
|
230
|
+
Core:
|
|
261
231
|
- `launchMode`: `auto` | `binary` | `java` (default: `auto`)
|
|
262
|
-
- `binaryPath`: binary executable path
|
|
232
|
+
- `binaryPath`: binary executable override path
|
|
263
233
|
- `classpath`: Java classpath string or string array
|
|
264
234
|
- `javaPath`: Java executable path (default: `java`)
|
|
265
235
|
- `launcherClass`: Java launcher class (default: `org.jongodb.server.TcpMongoServerLauncher`)
|
|
266
|
-
- `databaseName`:
|
|
236
|
+
- `databaseName`: base DB name (default: `test`)
|
|
237
|
+
- `databaseNameSuffix`: suffix appended to `databaseName` (example: `_ci`)
|
|
238
|
+
- `databaseNameStrategy`: `static` | `worker` (default: `static`)
|
|
267
239
|
- `host`: bind host (default: `127.0.0.1`)
|
|
268
|
-
- `port`: bind port (`0`
|
|
240
|
+
- `port`: bind port (`0` means ephemeral)
|
|
269
241
|
- `startupTimeoutMs`: startup timeout (default: `15000`)
|
|
270
242
|
- `stopTimeoutMs`: stop timeout before forced kill (default: `5000`)
|
|
271
|
-
- `env`:
|
|
243
|
+
- `env`: extra child process environment variables
|
|
272
244
|
- `logLevel`: `silent` | `info` | `debug` (default: `silent`)
|
|
273
|
-
|
|
245
|
+
|
|
246
|
+
Runtime helper options:
|
|
247
|
+
- `envVarName`: single target env key (default: `MONGODB_URI`)
|
|
248
|
+
- `envVarNames`: multiple target env keys (example: `["MONGODB_URI", "DATABASE_URL"]`)
|
|
274
249
|
|
|
275
250
|
## Troubleshooting
|
|
276
251
|
|
|
277
|
-
- `No launcher runtime configured`: set
|
|
252
|
+
- `No launcher runtime configured`: set `binaryPath` / `JONGODB_BINARY_PATH` / `classpath` / `JONGODB_CLASSPATH`
|
|
278
253
|
- `Binary launch mode requested but no binary was found`: provide `binaryPath` or `JONGODB_BINARY_PATH`
|
|
279
254
|
- `Java launch mode requested but Java classpath is not configured`: provide `classpath` or `JONGODB_CLASSPATH`
|
|
280
|
-
- `spawn ... ENOENT`: missing
|
|
255
|
+
- `spawn ... ENOENT`: missing runtime executable path
|
|
281
256
|
- startup timeout: launcher did not emit `JONGODB_URI=...`
|
|
282
257
|
|
|
283
258
|
Parallel test tip:
|
|
284
|
-
|
|
285
|
-
- use unique `databaseName` per worker/process to avoid data collisions
|
|
259
|
+
- use `databaseNameStrategy: "worker"` or per-worker suffixes to prevent data collisions
|
package/dist/cjs/index.js
CHANGED
|
@@ -21,7 +21,7 @@ async function startJongodbMemoryServer(options = {}) {
|
|
|
21
21
|
const stopTimeoutMs = normalizeTimeout(options.stopTimeoutMs, DEFAULT_STOP_TIMEOUT_MS, "stopTimeoutMs");
|
|
22
22
|
const host = normalizeHost(options.host);
|
|
23
23
|
const port = normalizePort(options.port);
|
|
24
|
-
const databaseName =
|
|
24
|
+
const databaseName = resolveDatabaseName(options);
|
|
25
25
|
const logLevel = options.logLevel ?? "silent";
|
|
26
26
|
const launchConfigs = resolveLaunchConfigs(options, {
|
|
27
27
|
host,
|
|
@@ -347,13 +347,59 @@ function normalizePort(port) {
|
|
|
347
347
|
}
|
|
348
348
|
return normalized;
|
|
349
349
|
}
|
|
350
|
-
function
|
|
351
|
-
const
|
|
350
|
+
function resolveDatabaseName(options) {
|
|
351
|
+
const base = normalizeDatabaseNameBase(options.databaseName);
|
|
352
|
+
const explicitSuffix = normalizeDatabaseNameSuffix(options.databaseNameSuffix);
|
|
353
|
+
const workerSuffix = resolveWorkerDatabaseNameSuffix(options.databaseNameStrategy);
|
|
354
|
+
return `${base}${explicitSuffix}${workerSuffix}`;
|
|
355
|
+
}
|
|
356
|
+
function normalizeDatabaseNameBase(databaseName) {
|
|
357
|
+
return databaseName?.trim() || DEFAULT_DATABASE;
|
|
358
|
+
}
|
|
359
|
+
function normalizeDatabaseNameSuffix(databaseNameSuffix) {
|
|
360
|
+
if (databaseNameSuffix === undefined) {
|
|
361
|
+
return "";
|
|
362
|
+
}
|
|
363
|
+
const normalized = databaseNameSuffix.trim();
|
|
352
364
|
if (normalized.length === 0) {
|
|
353
|
-
throw new Error("
|
|
365
|
+
throw new Error("databaseNameSuffix must not be empty when provided.");
|
|
354
366
|
}
|
|
355
367
|
return normalized;
|
|
356
368
|
}
|
|
369
|
+
function resolveWorkerDatabaseNameSuffix(strategy) {
|
|
370
|
+
const resolvedStrategy = strategy ?? "static";
|
|
371
|
+
if (resolvedStrategy !== "static" && resolvedStrategy !== "worker") {
|
|
372
|
+
throw new Error(`databaseNameStrategy must be one of: static, worker (got: ${String(strategy)}).`);
|
|
373
|
+
}
|
|
374
|
+
if (resolvedStrategy === "static") {
|
|
375
|
+
return "";
|
|
376
|
+
}
|
|
377
|
+
const workerToken = resolveWorkerToken();
|
|
378
|
+
return `_w${sanitizeDatabaseNameToken(workerToken)}`;
|
|
379
|
+
}
|
|
380
|
+
function resolveWorkerToken() {
|
|
381
|
+
const envCandidates = [
|
|
382
|
+
process.env.JONGODB_WORKER_ID,
|
|
383
|
+
process.env.JEST_WORKER_ID,
|
|
384
|
+
process.env.VITEST_WORKER_ID,
|
|
385
|
+
process.env.VITEST_POOL_ID,
|
|
386
|
+
process.env.NODE_UNIQUE_ID,
|
|
387
|
+
];
|
|
388
|
+
for (const candidate of envCandidates) {
|
|
389
|
+
const normalized = candidate?.trim();
|
|
390
|
+
if (normalized !== undefined && normalized.length > 0) {
|
|
391
|
+
return normalized;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return String(process.pid);
|
|
395
|
+
}
|
|
396
|
+
function sanitizeDatabaseNameToken(token) {
|
|
397
|
+
const sanitized = token.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
398
|
+
if (sanitized.length > 0) {
|
|
399
|
+
return sanitized;
|
|
400
|
+
}
|
|
401
|
+
return "unknown";
|
|
402
|
+
}
|
|
357
403
|
function resolveClasspathOrNull(classpath) {
|
|
358
404
|
const explicit = resolveExplicitClasspath(classpath);
|
|
359
405
|
if (explicit !== null) {
|
package/dist/cjs/runtime.js
CHANGED
|
@@ -4,14 +4,15 @@ exports.createJongodbEnvRuntime = createJongodbEnvRuntime;
|
|
|
4
4
|
const index_js_1 = require("./index.js");
|
|
5
5
|
const DEFAULT_ENV_VAR_NAME = "MONGODB_URI";
|
|
6
6
|
function createJongodbEnvRuntime(options = {}) {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const envVarNames = resolveEnvVarNames(options);
|
|
8
|
+
const envVarName = envVarNames[0];
|
|
9
|
+
const { envVarName: _envVarName, envVarNames: _envVarNames, ...serverOptions } = options;
|
|
9
10
|
let runtimeServer = null;
|
|
10
11
|
let uri = null;
|
|
11
|
-
let
|
|
12
|
-
let hadPreviousEnv = false;
|
|
12
|
+
let previousEnvState = captureEnvState(envVarNames);
|
|
13
13
|
return {
|
|
14
14
|
envVarName,
|
|
15
|
+
envVarNames,
|
|
15
16
|
get running() {
|
|
16
17
|
return runtimeServer !== null;
|
|
17
18
|
},
|
|
@@ -25,11 +26,12 @@ function createJongodbEnvRuntime(options = {}) {
|
|
|
25
26
|
if (runtimeServer !== null && uri !== null) {
|
|
26
27
|
return uri;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
previousEnvValue = process.env[envVarName];
|
|
29
|
+
previousEnvState = captureEnvState(envVarNames);
|
|
30
30
|
runtimeServer = await (0, index_js_1.startJongodbMemoryServer)(serverOptions);
|
|
31
31
|
uri = runtimeServer.uri;
|
|
32
|
-
|
|
32
|
+
for (const candidate of envVarNames) {
|
|
33
|
+
process.env[candidate] = uri;
|
|
34
|
+
}
|
|
33
35
|
return uri;
|
|
34
36
|
},
|
|
35
37
|
async teardown() {
|
|
@@ -37,22 +39,62 @@ function createJongodbEnvRuntime(options = {}) {
|
|
|
37
39
|
await runtimeServer.stop();
|
|
38
40
|
runtimeServer = null;
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
process.env[envVarName] = previousEnvValue;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
delete process.env[envVarName];
|
|
45
|
-
}
|
|
42
|
+
restoreEnvState(previousEnvState);
|
|
46
43
|
uri = null;
|
|
47
|
-
|
|
48
|
-
hadPreviousEnv = false;
|
|
44
|
+
previousEnvState = captureEnvState(envVarNames);
|
|
49
45
|
},
|
|
50
46
|
};
|
|
51
47
|
}
|
|
48
|
+
function resolveEnvVarNames(options) {
|
|
49
|
+
const explicitCandidates = [];
|
|
50
|
+
if (options.envVarName !== undefined) {
|
|
51
|
+
explicitCandidates.push(options.envVarName);
|
|
52
|
+
}
|
|
53
|
+
if (options.envVarNames !== undefined) {
|
|
54
|
+
explicitCandidates.push(...options.envVarNames);
|
|
55
|
+
}
|
|
56
|
+
if (explicitCandidates.length === 0) {
|
|
57
|
+
return [DEFAULT_ENV_VAR_NAME];
|
|
58
|
+
}
|
|
59
|
+
const resolved = [];
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
for (const candidate of explicitCandidates) {
|
|
62
|
+
const normalized = normalizeEnvVarName(candidate);
|
|
63
|
+
if (seen.has(normalized)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
seen.add(normalized);
|
|
67
|
+
resolved.push(normalized);
|
|
68
|
+
}
|
|
69
|
+
if (resolved.length === 0) {
|
|
70
|
+
return [DEFAULT_ENV_VAR_NAME];
|
|
71
|
+
}
|
|
72
|
+
return resolved;
|
|
73
|
+
}
|
|
52
74
|
function normalizeEnvVarName(name) {
|
|
53
|
-
const normalized = name
|
|
75
|
+
const normalized = name.trim();
|
|
54
76
|
if (normalized.length === 0) {
|
|
55
|
-
throw new Error("envVarName must not be empty.");
|
|
77
|
+
throw new Error("envVarName/envVarNames entries must not be empty.");
|
|
56
78
|
}
|
|
57
79
|
return normalized;
|
|
58
80
|
}
|
|
81
|
+
function captureEnvState(envVarNames) {
|
|
82
|
+
const state = new Map();
|
|
83
|
+
for (const envVarName of envVarNames) {
|
|
84
|
+
state.set(envVarName, {
|
|
85
|
+
hadPrevious: Object.prototype.hasOwnProperty.call(process.env, envVarName),
|
|
86
|
+
previousValue: process.env[envVarName],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return state;
|
|
90
|
+
}
|
|
91
|
+
function restoreEnvState(state) {
|
|
92
|
+
for (const [envVarName, previous] of state.entries()) {
|
|
93
|
+
if (previous.hadPrevious) {
|
|
94
|
+
process.env[envVarName] = previous.previousValue;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
delete process.env[envVarName];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
type LogLevel = "silent" | "info" | "debug";
|
|
2
2
|
type LaunchMode = "auto" | "binary" | "java";
|
|
3
|
+
type DatabaseNameStrategy = "static" | "worker";
|
|
3
4
|
export interface JongodbMemoryServerOptions {
|
|
4
5
|
host?: string;
|
|
5
6
|
port?: number;
|
|
6
7
|
databaseName?: string;
|
|
8
|
+
databaseNameSuffix?: string;
|
|
9
|
+
databaseNameStrategy?: DatabaseNameStrategy;
|
|
7
10
|
startupTimeoutMs?: number;
|
|
8
11
|
stopTimeoutMs?: number;
|
|
9
12
|
javaPath?: string;
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAqBA,KAAK,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAC5C,KAAK,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAqBA,KAAK,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAC5C,KAAK,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAC7C,KAAK,oBAAoB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEhD,MAAM,WAAW,0BAA0B;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,MAAM,IAAI,IAAI,CAAC;IACf,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAcD,wBAAsB,wBAAwB,CAC5C,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,mBAAmB,CAAC,CA6C9B"}
|
package/dist/esm/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export async function startJongodbMemoryServer(options = {}) {
|
|
|
18
18
|
const stopTimeoutMs = normalizeTimeout(options.stopTimeoutMs, DEFAULT_STOP_TIMEOUT_MS, "stopTimeoutMs");
|
|
19
19
|
const host = normalizeHost(options.host);
|
|
20
20
|
const port = normalizePort(options.port);
|
|
21
|
-
const databaseName =
|
|
21
|
+
const databaseName = resolveDatabaseName(options);
|
|
22
22
|
const logLevel = options.logLevel ?? "silent";
|
|
23
23
|
const launchConfigs = resolveLaunchConfigs(options, {
|
|
24
24
|
host,
|
|
@@ -344,13 +344,59 @@ function normalizePort(port) {
|
|
|
344
344
|
}
|
|
345
345
|
return normalized;
|
|
346
346
|
}
|
|
347
|
-
function
|
|
348
|
-
const
|
|
347
|
+
function resolveDatabaseName(options) {
|
|
348
|
+
const base = normalizeDatabaseNameBase(options.databaseName);
|
|
349
|
+
const explicitSuffix = normalizeDatabaseNameSuffix(options.databaseNameSuffix);
|
|
350
|
+
const workerSuffix = resolveWorkerDatabaseNameSuffix(options.databaseNameStrategy);
|
|
351
|
+
return `${base}${explicitSuffix}${workerSuffix}`;
|
|
352
|
+
}
|
|
353
|
+
function normalizeDatabaseNameBase(databaseName) {
|
|
354
|
+
return databaseName?.trim() || DEFAULT_DATABASE;
|
|
355
|
+
}
|
|
356
|
+
function normalizeDatabaseNameSuffix(databaseNameSuffix) {
|
|
357
|
+
if (databaseNameSuffix === undefined) {
|
|
358
|
+
return "";
|
|
359
|
+
}
|
|
360
|
+
const normalized = databaseNameSuffix.trim();
|
|
349
361
|
if (normalized.length === 0) {
|
|
350
|
-
throw new Error("
|
|
362
|
+
throw new Error("databaseNameSuffix must not be empty when provided.");
|
|
351
363
|
}
|
|
352
364
|
return normalized;
|
|
353
365
|
}
|
|
366
|
+
function resolveWorkerDatabaseNameSuffix(strategy) {
|
|
367
|
+
const resolvedStrategy = strategy ?? "static";
|
|
368
|
+
if (resolvedStrategy !== "static" && resolvedStrategy !== "worker") {
|
|
369
|
+
throw new Error(`databaseNameStrategy must be one of: static, worker (got: ${String(strategy)}).`);
|
|
370
|
+
}
|
|
371
|
+
if (resolvedStrategy === "static") {
|
|
372
|
+
return "";
|
|
373
|
+
}
|
|
374
|
+
const workerToken = resolveWorkerToken();
|
|
375
|
+
return `_w${sanitizeDatabaseNameToken(workerToken)}`;
|
|
376
|
+
}
|
|
377
|
+
function resolveWorkerToken() {
|
|
378
|
+
const envCandidates = [
|
|
379
|
+
process.env.JONGODB_WORKER_ID,
|
|
380
|
+
process.env.JEST_WORKER_ID,
|
|
381
|
+
process.env.VITEST_WORKER_ID,
|
|
382
|
+
process.env.VITEST_POOL_ID,
|
|
383
|
+
process.env.NODE_UNIQUE_ID,
|
|
384
|
+
];
|
|
385
|
+
for (const candidate of envCandidates) {
|
|
386
|
+
const normalized = candidate?.trim();
|
|
387
|
+
if (normalized !== undefined && normalized.length > 0) {
|
|
388
|
+
return normalized;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return String(process.pid);
|
|
392
|
+
}
|
|
393
|
+
function sanitizeDatabaseNameToken(token) {
|
|
394
|
+
const sanitized = token.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
395
|
+
if (sanitized.length > 0) {
|
|
396
|
+
return sanitized;
|
|
397
|
+
}
|
|
398
|
+
return "unknown";
|
|
399
|
+
}
|
|
354
400
|
function resolveClasspathOrNull(classpath) {
|
|
355
401
|
const explicit = resolveExplicitClasspath(classpath);
|
|
356
402
|
if (explicit !== null) {
|
package/dist/esm/jest.d.ts
CHANGED
package/dist/esm/jest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.d.ts","sourceRoot":"","sources":["../../src/jest.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,0BAA0B,EAEhC,MAAM,YAAY,CAAC;AAWpB,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,QAAQ,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED,MAAM,WAAW,eAAgB,SAAQ,0BAA0B;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"jest.d.ts","sourceRoot":"","sources":["../../src/jest.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,0BAA0B,EAEhC,MAAM,YAAY,CAAC;AAWpB,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,QAAQ,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED,MAAM,WAAW,eAAgB,SAAQ,0BAA0B;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,0BAA2B,SAAQ,0BAA0B;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,iBAAiB,EACxB,OAAO,GAAE,eAAoB,GAC5B,2BAA2B,CAgB7B;AAED,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,0BAA+B,GACvC,MAAM,OAAO,CAAC,IAAI,CAAC,CAiBrB;AAED,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,0BAA+B,GACvC,MAAM,OAAO,CAAC,IAAI,CAAC,CAkBrB;AAED,wBAAsB,mBAAmB,CAAC,OAAO,GAAE;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAmBvC;AAED,wBAAsB,iBAAiB,CAAC,OAAO,GAAE;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAM9B"}
|
package/dist/esm/runtime.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type JongodbMemoryServerOptions } from "./index.js";
|
|
2
2
|
export interface JongodbEnvRuntimeOptions extends JongodbMemoryServerOptions {
|
|
3
3
|
envVarName?: string;
|
|
4
|
+
envVarNames?: string[];
|
|
4
5
|
}
|
|
5
6
|
export interface JongodbEnvRuntime {
|
|
6
7
|
readonly envVarName: string;
|
|
8
|
+
readonly envVarNames: readonly string[];
|
|
7
9
|
readonly running: boolean;
|
|
8
10
|
readonly uri: string;
|
|
9
11
|
setup(): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAEhC,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,wBAAyB,SAAQ,0BAA0B;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAEhC,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,wBAAyB,SAAQ,0BAA0B;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,wBAA6B,GACrC,iBAAiB,CAmDnB"}
|
package/dist/esm/runtime.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { startJongodbMemoryServer, } from "./index.js";
|
|
2
2
|
const DEFAULT_ENV_VAR_NAME = "MONGODB_URI";
|
|
3
3
|
export function createJongodbEnvRuntime(options = {}) {
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const envVarNames = resolveEnvVarNames(options);
|
|
5
|
+
const envVarName = envVarNames[0];
|
|
6
|
+
const { envVarName: _envVarName, envVarNames: _envVarNames, ...serverOptions } = options;
|
|
6
7
|
let runtimeServer = null;
|
|
7
8
|
let uri = null;
|
|
8
|
-
let
|
|
9
|
-
let hadPreviousEnv = false;
|
|
9
|
+
let previousEnvState = captureEnvState(envVarNames);
|
|
10
10
|
return {
|
|
11
11
|
envVarName,
|
|
12
|
+
envVarNames,
|
|
12
13
|
get running() {
|
|
13
14
|
return runtimeServer !== null;
|
|
14
15
|
},
|
|
@@ -22,11 +23,12 @@ export function createJongodbEnvRuntime(options = {}) {
|
|
|
22
23
|
if (runtimeServer !== null && uri !== null) {
|
|
23
24
|
return uri;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
previousEnvValue = process.env[envVarName];
|
|
26
|
+
previousEnvState = captureEnvState(envVarNames);
|
|
27
27
|
runtimeServer = await startJongodbMemoryServer(serverOptions);
|
|
28
28
|
uri = runtimeServer.uri;
|
|
29
|
-
|
|
29
|
+
for (const candidate of envVarNames) {
|
|
30
|
+
process.env[candidate] = uri;
|
|
31
|
+
}
|
|
30
32
|
return uri;
|
|
31
33
|
},
|
|
32
34
|
async teardown() {
|
|
@@ -34,22 +36,62 @@ export function createJongodbEnvRuntime(options = {}) {
|
|
|
34
36
|
await runtimeServer.stop();
|
|
35
37
|
runtimeServer = null;
|
|
36
38
|
}
|
|
37
|
-
|
|
38
|
-
process.env[envVarName] = previousEnvValue;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
delete process.env[envVarName];
|
|
42
|
-
}
|
|
39
|
+
restoreEnvState(previousEnvState);
|
|
43
40
|
uri = null;
|
|
44
|
-
|
|
45
|
-
hadPreviousEnv = false;
|
|
41
|
+
previousEnvState = captureEnvState(envVarNames);
|
|
46
42
|
},
|
|
47
43
|
};
|
|
48
44
|
}
|
|
45
|
+
function resolveEnvVarNames(options) {
|
|
46
|
+
const explicitCandidates = [];
|
|
47
|
+
if (options.envVarName !== undefined) {
|
|
48
|
+
explicitCandidates.push(options.envVarName);
|
|
49
|
+
}
|
|
50
|
+
if (options.envVarNames !== undefined) {
|
|
51
|
+
explicitCandidates.push(...options.envVarNames);
|
|
52
|
+
}
|
|
53
|
+
if (explicitCandidates.length === 0) {
|
|
54
|
+
return [DEFAULT_ENV_VAR_NAME];
|
|
55
|
+
}
|
|
56
|
+
const resolved = [];
|
|
57
|
+
const seen = new Set();
|
|
58
|
+
for (const candidate of explicitCandidates) {
|
|
59
|
+
const normalized = normalizeEnvVarName(candidate);
|
|
60
|
+
if (seen.has(normalized)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
seen.add(normalized);
|
|
64
|
+
resolved.push(normalized);
|
|
65
|
+
}
|
|
66
|
+
if (resolved.length === 0) {
|
|
67
|
+
return [DEFAULT_ENV_VAR_NAME];
|
|
68
|
+
}
|
|
69
|
+
return resolved;
|
|
70
|
+
}
|
|
49
71
|
function normalizeEnvVarName(name) {
|
|
50
|
-
const normalized = name
|
|
72
|
+
const normalized = name.trim();
|
|
51
73
|
if (normalized.length === 0) {
|
|
52
|
-
throw new Error("envVarName must not be empty.");
|
|
74
|
+
throw new Error("envVarName/envVarNames entries must not be empty.");
|
|
53
75
|
}
|
|
54
76
|
return normalized;
|
|
55
77
|
}
|
|
78
|
+
function captureEnvState(envVarNames) {
|
|
79
|
+
const state = new Map();
|
|
80
|
+
for (const envVarName of envVarNames) {
|
|
81
|
+
state.set(envVarName, {
|
|
82
|
+
hadPrevious: Object.prototype.hasOwnProperty.call(process.env, envVarName),
|
|
83
|
+
previousValue: process.env[envVarName],
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return state;
|
|
87
|
+
}
|
|
88
|
+
function restoreEnvState(state) {
|
|
89
|
+
for (const [envVarName, previous] of state.entries()) {
|
|
90
|
+
if (previous.hadPrevious) {
|
|
91
|
+
process.env[envVarName] = previous.previousValue;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
delete process.env[envVarName];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
package/dist/esm/vitest.d.ts
CHANGED
package/dist/esm/vitest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../../src/vitest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAG7D,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,QAAQ,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED,MAAM,WAAW,iBAAkB,SAAQ,0BAA0B;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../../src/vitest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAG7D,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,QAAQ,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED,MAAM,WAAW,iBAAkB,SAAQ,0BAA0B;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,mBAAmB,EAC1B,OAAO,GAAE,iBAAsB,GAC9B,6BAA6B,CAgB/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jongodb/memory-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Node.js test runtime adapter for jongodb standalone launcher (MongoDB-compatible integration tests).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mongodb",
|
|
@@ -90,9 +90,9 @@
|
|
|
90
90
|
"access": "public"
|
|
91
91
|
},
|
|
92
92
|
"optionalDependencies": {
|
|
93
|
-
"@jongodb/memory-server-bin-darwin-arm64": "0.1.
|
|
94
|
-
"@jongodb/memory-server-bin-linux-x64-gnu": "0.1.
|
|
95
|
-
"@jongodb/memory-server-bin-win32-x64": "0.1.
|
|
93
|
+
"@jongodb/memory-server-bin-darwin-arm64": "0.1.3",
|
|
94
|
+
"@jongodb/memory-server-bin-linux-x64-gnu": "0.1.3",
|
|
95
|
+
"@jongodb/memory-server-bin-win32-x64": "0.1.3"
|
|
96
96
|
},
|
|
97
97
|
"files": [
|
|
98
98
|
"dist",
|