@adaptivestone/framework 5.0.1 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/commands/OpenApi.d.ts +26 -0
- package/dist/commands/OpenApi.js +101 -0
- package/dist/commands/OpenApi.js.map +1 -0
- package/dist/commands/Routes.d.ts +17 -0
- package/dist/commands/Routes.js +35 -0
- package/dist/commands/Routes.js.map +1 -0
- package/dist/config/cache.d.ts +14 -0
- package/dist/config/cache.js +14 -0
- package/dist/config/cache.js.map +1 -0
- package/dist/controllers/index.js +28 -4
- package/dist/controllers/index.js.map +1 -1
- package/dist/helpers/appInstance.d.ts +6 -0
- package/dist/helpers/appInstance.js +13 -0
- package/dist/helpers/appInstance.js.map +1 -1
- package/dist/modules/BaseModel.d.ts +10 -0
- package/dist/modules/BaseModel.js +25 -0
- package/dist/modules/BaseModel.js.map +1 -1
- package/dist/server.d.ts +20 -1
- package/dist/server.js +24 -1
- package/dist/server.js.map +1 -1
- package/dist/services/cache/Cache.d.ts +3 -4
- package/dist/services/cache/Cache.js +43 -34
- package/dist/services/cache/Cache.js.map +1 -1
- package/dist/services/cache/CacheDriver.d.ts +19 -0
- package/dist/services/cache/CacheDriver.js +2 -0
- package/dist/services/cache/CacheDriver.js.map +1 -0
- package/dist/services/cache/drivers/MemoryDriver.d.ts +14 -0
- package/dist/services/cache/drivers/MemoryDriver.js +40 -0
- package/dist/services/cache/drivers/MemoryDriver.js.map +1 -0
- package/dist/services/cache/drivers/RedisDriver.d.ts +22 -0
- package/dist/services/cache/drivers/RedisDriver.js +44 -0
- package/dist/services/cache/drivers/RedisDriver.js.map +1 -0
- package/dist/services/documentation/OpenApiGenerator.d.ts +39 -0
- package/dist/services/documentation/OpenApiGenerator.js +296 -0
- package/dist/services/documentation/OpenApiGenerator.js.map +1 -0
- package/dist/services/http/HttpServer.d.ts +23 -0
- package/dist/services/http/HttpServer.js +57 -0
- package/dist/services/http/HttpServer.js.map +1 -1
- package/dist/services/http/builtinErrorHandlers.d.ts +36 -0
- package/dist/services/http/builtinErrorHandlers.js +71 -0
- package/dist/services/http/builtinErrorHandlers.js.map +1 -0
- package/dist/services/http/httpErrors.d.ts +30 -0
- package/dist/services/http/httpErrors.js +46 -0
- package/dist/services/http/httpErrors.js.map +1 -0
- package/dist/services/http/middleware/AbstractMiddleware.d.ts +25 -7
- package/dist/services/http/middleware/AbstractMiddleware.js +14 -0
- package/dist/services/http/middleware/AbstractMiddleware.js.map +1 -1
- package/dist/services/http/middleware/GetUserByToken.d.ts +13 -0
- package/dist/services/http/middleware/GetUserByToken.js +5 -1
- package/dist/services/http/middleware/GetUserByToken.js.map +1 -1
- package/dist/services/http/middleware/RateLimiter.d.ts +8 -2
- package/dist/services/http/middleware/RateLimiter.js +38 -13
- package/dist/services/http/middleware/RateLimiter.js.map +1 -1
- package/dist/services/http/routing/RouteNode.d.ts +2 -0
- package/dist/services/validate/drivers/StandardSchemaDriver.d.ts +5 -2
- package/dist/services/validate/drivers/StandardSchemaDriver.js +24 -3
- package/dist/services/validate/drivers/StandardSchemaDriver.js.map +1 -1
- package/dist/services/validate/drivers/YupDriver.js +91 -2
- package/dist/services/validate/drivers/YupDriver.js.map +1 -1
- package/dist/services/validate/types.d.ts +7 -4
- package/dist/tests/globalSetupNodeTest.d.ts +2 -0
- package/dist/tests/globalSetupNodeTest.js +23 -0
- package/dist/tests/globalSetupNodeTest.js.map +1 -0
- package/dist/tests/globalSetupVitest.js +6 -13
- package/dist/tests/globalSetupVitest.js.map +1 -1
- package/dist/tests/nodeRunner.node-test.d.ts +14 -0
- package/dist/tests/nodeRunner.node-test.js +41 -0
- package/dist/tests/nodeRunner.node-test.js.map +1 -0
- package/dist/tests/nodeRunnerShared.node-test.d.ts +14 -0
- package/dist/tests/nodeRunnerShared.node-test.js +39 -0
- package/dist/tests/nodeRunnerShared.node-test.js.map +1 -0
- package/dist/tests/setupFramework.d.ts +33 -0
- package/dist/tests/setupFramework.js +134 -0
- package/dist/tests/setupFramework.js.map +1 -0
- package/dist/tests/setupNodeTest.d.ts +1 -0
- package/dist/tests/setupNodeTest.js +16 -0
- package/dist/tests/setupNodeTest.js.map +1 -0
- package/dist/tests/setupVitest.js +8 -99
- package/dist/tests/setupVitest.js.map +1 -1
- package/package.json +10 -3
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smoke test for the **extracted / shared** Mongo-init pattern under `node:test`.
|
|
3
|
+
*
|
|
4
|
+
* This is a SECOND suite file in the same run: it proves the global-setup entry
|
|
5
|
+
* (`globalSetupNodeTest.ts`, wired via `--test-global-setup`) starts Mongo ONCE
|
|
6
|
+
* and shares it across every `*.node-test.ts` file via `TEST_MONGO_URI`. This
|
|
7
|
+
* file starts nothing itself — it asserts the URI arrived from the entry module
|
|
8
|
+
* and that it got its own fresh per-suite DB off the shared instance.
|
|
9
|
+
*
|
|
10
|
+
* The per-file server lifecycle comes from the shipped `setupNodeTest.ts` glue
|
|
11
|
+
* (it wires `before(startTestServer)` etc. but never touches Mongo init). Runs as
|
|
12
|
+
* part of `npm run test:node`.
|
|
13
|
+
*/
|
|
14
|
+
import "./setupNodeTest.js";
|
|
15
|
+
import assert from 'node:assert/strict';
|
|
16
|
+
import { describe, it } from 'node:test';
|
|
17
|
+
import mongoose from 'mongoose';
|
|
18
|
+
import { getTestServerURL } from "./testHelpers.js";
|
|
19
|
+
describe('node:test: second suite sharing the global Mongo', () => {
|
|
20
|
+
it('consumes a TEST_MONGO_URI provided by the global-setup entry', () => {
|
|
21
|
+
// This file never calls startTestMongo — the URI must come from the runner.
|
|
22
|
+
assert.ok(process.env.TEST_MONGO_URI, 'TEST_MONGO_URI must be published before the test process starts');
|
|
23
|
+
assert.match(process.env.TEST_MONGO_URI, /^mongodb:\/\//);
|
|
24
|
+
});
|
|
25
|
+
it('boots the per-suite Server against the shared Mongo', async () => {
|
|
26
|
+
await mongoose.connection.asPromise(); // resolves once the connection is open
|
|
27
|
+
assert.equal(mongoose.connection.readyState, 1);
|
|
28
|
+
// startTestServer derives a fresh per-suite DB (TEST_<uuid>) from the shared
|
|
29
|
+
// URI — proof the extracted init flowed through to this process correctly.
|
|
30
|
+
assert.match(mongoose.connection.name, /^TEST_/);
|
|
31
|
+
});
|
|
32
|
+
it('serves HTTP from the booted server', async () => {
|
|
33
|
+
const { status } = await fetch(getTestServerURL('/')).catch(() => ({
|
|
34
|
+
status: 500,
|
|
35
|
+
}));
|
|
36
|
+
assert.equal(status, 200);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=nodeRunnerShared.node-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeRunnerShared.node-test.js","sourceRoot":"","sources":["../../src/tests/nodeRunnerShared.node-test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,QAAQ,CAAC,kDAAkD,EAAE,GAAG,EAAE;IAChE,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;QACtE,4EAA4E;QAC5E,MAAM,CAAC,EAAE,CACP,OAAO,CAAC,GAAG,CAAC,cAAc,EAC1B,iEAAiE,CAClE,CAAC;QACF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;QACnE,MAAM,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC,uCAAuC;QAC9E,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QAChD,6EAA6E;QAC7E,2EAA2E;QAC3E,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;YACjE,MAAM,EAAE,GAAG;SACZ,CAAC,CAAC,CAAC;QACJ,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner-agnostic test setup. Plain async functions with **no test-runner
|
|
3
|
+
* import** (no vitest, no `node:test`) so the framework's test lifecycle can be
|
|
4
|
+
* driven from either runner — or programmatically.
|
|
5
|
+
*
|
|
6
|
+
* - vitest glue: `setupVitest.ts` (per-file) + `globalSetupVitest.ts` (once).
|
|
7
|
+
* - node:test glue: `setupNodeTest.ts`.
|
|
8
|
+
*
|
|
9
|
+
* Lifecycle pieces:
|
|
10
|
+
* - `startTestMongo` / `stopTestMongo` — once per run; spins up an in-memory
|
|
11
|
+
* Mongo replica set and publishes `process.env.TEST_MONGO_URI`.
|
|
12
|
+
* - `startTestServer` / `stopTestServer` — once per test file/suite; boots a
|
|
13
|
+
* framework `Server` against a fresh DB and tears it down.
|
|
14
|
+
* - `setTestRedisNamespace` / `clearTestRedisNamespace` — per test; isolate the
|
|
15
|
+
* cache/rate-limiter keyspace.
|
|
16
|
+
*/
|
|
17
|
+
import Server from '../server.ts';
|
|
18
|
+
/** Start an in-memory Mongo replica set and publish `TEST_MONGO_URI`. */
|
|
19
|
+
export declare function startTestMongo(): Promise<string>;
|
|
20
|
+
/** Stop the in-memory Mongo replica set. */
|
|
21
|
+
export declare function stopTestMongo(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Boot a framework `Server` against a fresh per-suite database (derived from
|
|
24
|
+
* `TEST_MONGO_URI`) and start its HTTP server on a random port. Registers the
|
|
25
|
+
* instance via `setServerInstance` so `testHelpers` can reach it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function startTestServer(): Promise<Server>;
|
|
28
|
+
/** Shut down the server, drop its database, and disconnect mongoose. */
|
|
29
|
+
export declare function stopTestServer(): Promise<void>;
|
|
30
|
+
/** Point the cache/rate-limiter keyspace at a fresh random namespace. */
|
|
31
|
+
export declare function setTestRedisNamespace(): void;
|
|
32
|
+
/** Best-effort clear of the current test's redis namespace (no-op without redis). */
|
|
33
|
+
export declare function clearTestRedisNamespace(): Promise<void>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner-agnostic test setup. Plain async functions with **no test-runner
|
|
3
|
+
* import** (no vitest, no `node:test`) so the framework's test lifecycle can be
|
|
4
|
+
* driven from either runner — or programmatically.
|
|
5
|
+
*
|
|
6
|
+
* - vitest glue: `setupVitest.ts` (per-file) + `globalSetupVitest.ts` (once).
|
|
7
|
+
* - node:test glue: `setupNodeTest.ts`.
|
|
8
|
+
*
|
|
9
|
+
* Lifecycle pieces:
|
|
10
|
+
* - `startTestMongo` / `stopTestMongo` — once per run; spins up an in-memory
|
|
11
|
+
* Mongo replica set and publishes `process.env.TEST_MONGO_URI`.
|
|
12
|
+
* - `startTestServer` / `stopTestServer` — once per test file/suite; boots a
|
|
13
|
+
* framework `Server` against a fresh DB and tears it down.
|
|
14
|
+
* - `setTestRedisNamespace` / `clearTestRedisNamespace` — per test; isolate the
|
|
15
|
+
* cache/rate-limiter keyspace.
|
|
16
|
+
*/
|
|
17
|
+
import crypto from 'node:crypto';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import mongoose from 'mongoose'; // we do not need create indexes on tests
|
|
20
|
+
import { clearNamespace } from "../helpers/redis/clearNamespace.js";
|
|
21
|
+
import Server from "../server.js";
|
|
22
|
+
import { serverInstance, setServerInstance } from "./testHelpers.js";
|
|
23
|
+
mongoose.set('autoIndex', false);
|
|
24
|
+
const basePath = new URL('.', import.meta.url).pathname;
|
|
25
|
+
// ── Global Mongo lifecycle (once per test run) ──────────────────────────────
|
|
26
|
+
// Only `.stop()` is needed at module scope; the full type comes from the lazy
|
|
27
|
+
// import inside `startTestMongo` so merely importing this module doesn't pull in
|
|
28
|
+
// `mongodb-memory-server` (an optional peer — a node:test consumer may supply
|
|
29
|
+
// `TEST_MONGO_URI` from an external Mongo instead).
|
|
30
|
+
let mongoServer = null;
|
|
31
|
+
/** Start an in-memory Mongo replica set and publish `TEST_MONGO_URI`. */
|
|
32
|
+
export async function startTestMongo() {
|
|
33
|
+
const { MongoMemoryReplSet } = await import('mongodb-memory-server');
|
|
34
|
+
const instance = await MongoMemoryReplSet.create({
|
|
35
|
+
replSet: { count: 1, storageEngine: 'wiredTiger' },
|
|
36
|
+
});
|
|
37
|
+
await instance.waitUntilRunning();
|
|
38
|
+
mongoServer = instance;
|
|
39
|
+
const uri = await instance.getUri('__DB_TO_REPLACE__');
|
|
40
|
+
process.env.TEST_MONGO_URI = uri;
|
|
41
|
+
return uri;
|
|
42
|
+
}
|
|
43
|
+
/** Stop the in-memory Mongo replica set. */
|
|
44
|
+
export async function stopTestMongo() {
|
|
45
|
+
await mongoServer?.stop();
|
|
46
|
+
mongoServer = null;
|
|
47
|
+
}
|
|
48
|
+
// ── Per-suite server lifecycle ──────────────────────────────────────────────
|
|
49
|
+
/**
|
|
50
|
+
* Boot a framework `Server` against a fresh per-suite database (derived from
|
|
51
|
+
* `TEST_MONGO_URI`) and start its HTTP server on a random port. Registers the
|
|
52
|
+
* instance via `setServerInstance` so `testHelpers` can reach it.
|
|
53
|
+
*/
|
|
54
|
+
export async function startTestServer() {
|
|
55
|
+
process.env.LOGGER_CONSOLE_LEVEL = 'error';
|
|
56
|
+
process.env.AUTH_SALT = crypto.randomBytes(16).toString('hex');
|
|
57
|
+
const server = new Server({
|
|
58
|
+
folders: {
|
|
59
|
+
config: process.env.TEST_FOLDER_CONFIG || path.resolve(basePath, '../config'),
|
|
60
|
+
controllers: process.env.TEST_FOLDER_CONTROLLERS ||
|
|
61
|
+
path.resolve(basePath, '../controllers'),
|
|
62
|
+
models: process.env.TEST_FOLDER_MODELS || path.resolve(basePath, '../models'),
|
|
63
|
+
emails: process.env.TEST_FOLDER_EMAIL ||
|
|
64
|
+
process.env.TEST_FOLDER_EMAILS ||
|
|
65
|
+
path.resolve(basePath, '../services/messaging/email/templates'),
|
|
66
|
+
locales: process.env.TEST_FOLDER_LOCALES || path.resolve(basePath, '../locales'),
|
|
67
|
+
commands: process.env.TEST_FOLDER_COMMANDS ||
|
|
68
|
+
path.resolve(basePath, '../commands'),
|
|
69
|
+
migrations: process.env.TEST_FOLDER_MIGRATIONS ||
|
|
70
|
+
path.resolve(basePath, '../migrations'),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
setServerInstance(server);
|
|
74
|
+
await server.init({ isSkipModelInit: true });
|
|
75
|
+
const connectionString = process.env.TEST_MONGO_URI.replace('__DB_TO_REPLACE__', `TEST_${crypto.randomUUID()}`);
|
|
76
|
+
server.updateConfig('mongo', { connectionString });
|
|
77
|
+
server.updateConfig('http', { port: 0 }); // allow to use random
|
|
78
|
+
server.updateConfig('mail', { transport: 'stub' });
|
|
79
|
+
// Use the in-memory rate limiter for the default (controller-mounted) limiter:
|
|
80
|
+
// it's synchronous, so it can't time out and fail-open under the CPU load of
|
|
81
|
+
// parallel workers (which made the Auth 429 test flaky). The Mongo/Redis
|
|
82
|
+
// drivers are still covered explicitly in RateLimiter.test.ts.
|
|
83
|
+
server.updateConfig('rateLimiter', { driver: 'memory' });
|
|
84
|
+
// scrypt is memory-hard: the production ln=17 (~0.5s/hash) run across parallel
|
|
85
|
+
// workers starves each other and trips hook timeouts. Lower the cost for tests
|
|
86
|
+
// (~15ms/hash). The verify/rehash paths read this same config, so the v2
|
|
87
|
+
// round-trip and upgrade logic are still exercised.
|
|
88
|
+
server.updateConfig('auth', { scrypt: { ln: 12, r: 8, p: 1 } });
|
|
89
|
+
await server.initAllModels();
|
|
90
|
+
await server.startServer();
|
|
91
|
+
return server;
|
|
92
|
+
}
|
|
93
|
+
/** Shut down the server, drop its database, and disconnect mongoose. */
|
|
94
|
+
export async function stopTestServer() {
|
|
95
|
+
if (serverInstance) {
|
|
96
|
+
serverInstance.app.httpServer?.shutdown();
|
|
97
|
+
serverInstance.app.events.emit('shutdown');
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
await mongoose.connection.db?.dropDatabase(); // clean database after test
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// that ok. No mongoose connection
|
|
104
|
+
}
|
|
105
|
+
await mongoose.disconnect();
|
|
106
|
+
}
|
|
107
|
+
// ── Per-test redis namespace isolation ──────────────────────────────────────
|
|
108
|
+
/** Point the cache/rate-limiter keyspace at a fresh random namespace. */
|
|
109
|
+
export function setTestRedisNamespace() {
|
|
110
|
+
if (serverInstance) {
|
|
111
|
+
const key = `test-${Math.random().toString(36).substring(7)}`;
|
|
112
|
+
serverInstance.app.updateConfig('redis', { namespace: key });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Best-effort clear of the current test's redis namespace (no-op without redis). */
|
|
116
|
+
export async function clearTestRedisNamespace() {
|
|
117
|
+
if (!serverInstance) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const { url, namespace } = serverInstance.getConfig('redis');
|
|
121
|
+
try {
|
|
122
|
+
// Lazy-import `@redis/client` so a memory-only consumer that uses this test
|
|
123
|
+
// setup never loads the (optional) redis package.
|
|
124
|
+
const { createClient } = await import('@redis/client');
|
|
125
|
+
const redisClient = createClient({ url });
|
|
126
|
+
await redisClient.connect();
|
|
127
|
+
await clearNamespace(redisClient, namespace);
|
|
128
|
+
await redisClient.destroy();
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// that ok. No redis connection
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=setupFramework.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupFramework.js","sourceRoot":"","sources":["../../src/tests/setupFramework.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,QAAQ,MAAM,UAAU,CAAC,CAAC,yCAAyC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErE,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AAEjC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;AAExD,+EAA+E;AAE/E,8EAA8E;AAC9E,iFAAiF;AACjF,8EAA8E;AAC9E,oDAAoD;AACpD,IAAI,WAAW,GAA4C,IAAI,CAAC;AAEhE,yEAAyE;AACzE,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC;QAC/C,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE;KACnD,CAAC,CAAC;IACH,MAAM,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IAClC,WAAW,GAAG,QAAQ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W,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,+BAA+B;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// node:test glue for the framework test lifecycle, mirroring `setupVitest.ts`.
|
|
2
|
+
// The setup logic is runner-agnostic in `setupFramework.ts`; this file only
|
|
3
|
+
// wires it to node:test's hooks.
|
|
4
|
+
//
|
|
5
|
+
// node:test runs each file in its own process, so there is no built-in
|
|
6
|
+
// run-once-globally hook like vitest's globalSetup. Ensure `TEST_MONGO_URI` is
|
|
7
|
+
// set before these hooks run — either start one shared Mongo outside the test
|
|
8
|
+
// processes (a preload that calls `startTestMongo`, see the testing docs) or
|
|
9
|
+
// point `TEST_MONGO_URI` at an external instance.
|
|
10
|
+
import { after, afterEach, before, beforeEach } from 'node:test';
|
|
11
|
+
import { clearTestRedisNamespace, setTestRedisNamespace, startTestServer, stopTestServer, } from "./setupFramework.js";
|
|
12
|
+
before(startTestServer);
|
|
13
|
+
beforeEach(setTestRedisNamespace);
|
|
14
|
+
afterEach(clearTestRedisNamespace);
|
|
15
|
+
after(stopTestServer);
|
|
16
|
+
//# sourceMappingURL=setupNodeTest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupNodeTest.js","sourceRoot":"","sources":["../../src/tests/setupNodeTest.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,4EAA4E;AAC5E,iCAAiC;AACjC,EAAE;AACF,uEAAuE;AACvE,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,kDAAkD;AAClD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,EACf,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAC,eAAe,CAAC,CAAC;AACxB,UAAU,CAAC,qBAAqB,CAAC,CAAC;AAClC,SAAS,CAAC,uBAAuB,CAAC,CAAC;AACnC,KAAK,CAAC,cAAc,CAAC,CAAC"}
|
|
@@ -1,101 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import mongoose from 'mongoose'; // we do not need create indexes on tests
|
|
1
|
+
// vitest glue for the framework test lifecycle. The actual setup logic is
|
|
2
|
+
// runner-agnostic in `setupFramework.ts`; this file only wires it to vitest's
|
|
3
|
+
// per-file hooks. (Global Mongo lifecycle is in `globalSetupVitest.ts`.)
|
|
5
4
|
import { afterAll, afterEach, beforeAll, beforeEach } from 'vitest';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
process.env.LOGGER_CONSOLE_LEVEL = 'error';
|
|
13
|
-
process.env.AUTH_SALT = crypto.randomBytes(16).toString('hex');
|
|
14
|
-
const server = new Server({
|
|
15
|
-
folders: {
|
|
16
|
-
config: process.env.TEST_FOLDER_CONFIG || path.resolve(basePath, '../config'),
|
|
17
|
-
controllers: process.env.TEST_FOLDER_CONTROLLERS ||
|
|
18
|
-
path.resolve(basePath, '../controllers'),
|
|
19
|
-
models: process.env.TEST_FOLDER_MODELS || path.resolve(basePath, '../models'),
|
|
20
|
-
emails: process.env.TEST_FOLDER_EMAIL ||
|
|
21
|
-
process.env.TEST_FOLDER_EMAILS ||
|
|
22
|
-
path.resolve(basePath, '../services/messaging/email/templates'),
|
|
23
|
-
locales: process.env.TEST_FOLDER_LOCALES || path.resolve(basePath, '../locales'),
|
|
24
|
-
commands: process.env.TEST_FOLDER_COMMANDS ||
|
|
25
|
-
path.resolve(basePath, '../commands'),
|
|
26
|
-
migrations: process.env.TEST_FOLDER_MIGRATIONS ||
|
|
27
|
-
path.resolve(basePath, '../migrations'),
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
setServerInstance(server);
|
|
31
|
-
await server.init({ isSkipModelInit: true });
|
|
32
|
-
const connectionString = process.env.TEST_MONGO_URI.replace('__DB_TO_REPLACE__', `TEST_${crypto.randomUUID()}`);
|
|
33
|
-
server.updateConfig('mongo', {
|
|
34
|
-
connectionString,
|
|
35
|
-
});
|
|
36
|
-
server.updateConfig('http', { port: 0 }); // allow to use random
|
|
37
|
-
server.updateConfig('mail', { transport: 'stub' });
|
|
38
|
-
// Use the in-memory rate limiter for the default (controller-mounted) limiter:
|
|
39
|
-
// it's synchronous, so it can't time out and fail-open under the CPU load of
|
|
40
|
-
// parallel workers (which made the Auth 429 test flaky). The Mongo/Redis
|
|
41
|
-
// drivers are still covered explicitly in RateLimiter.test.ts.
|
|
42
|
-
server.updateConfig('rateLimiter', { driver: 'memory' });
|
|
43
|
-
// scrypt is memory-hard: the production ln=17 (~0.5s/hash) run across vitest's
|
|
44
|
-
// parallel workers starves each other and trips hook timeouts. Lower the cost
|
|
45
|
-
// for tests (~15ms/hash). The verify/rehash paths read this same config, so
|
|
46
|
-
// the v2 round-trip and upgrade logic are still exercised.
|
|
47
|
-
server.updateConfig('auth', { scrypt: { ln: 12, r: 8, p: 1 } });
|
|
48
|
-
await server.initAllModels();
|
|
49
|
-
// if (!global.testSetup) {
|
|
50
|
-
// global.testSetup = {};
|
|
51
|
-
// }
|
|
52
|
-
// server.testingGetUrl = (urlPart) => {
|
|
53
|
-
// console.error(
|
|
54
|
-
// 'global.server.testingGetUrl is deprcated. Please use testHelper.getServerBaseURL()',
|
|
55
|
-
// );
|
|
56
|
-
// return `http://127.0.0.1:${global.server.getConfig('http').port}${urlPart}`;
|
|
57
|
-
// };
|
|
58
|
-
// if (typeof global.testSetup.beforeAll === 'function') {
|
|
59
|
-
// await global.testSetup.beforeAll();
|
|
60
|
-
// }
|
|
61
|
-
await server.startServer();
|
|
62
|
-
});
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
if (serverInstance) {
|
|
65
|
-
const key = `test-${Math.random().toString(36).substring(7)}`;
|
|
66
|
-
serverInstance.app.updateConfig('redis', {
|
|
67
|
-
namespace: key,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
afterEach(async () => {
|
|
72
|
-
if (serverInstance) {
|
|
73
|
-
const { url, namespace } = serverInstance.getConfig('redis');
|
|
74
|
-
const redisClient = createClient({ url });
|
|
75
|
-
try {
|
|
76
|
-
await redisClient.connect();
|
|
77
|
-
await clearNamespace(redisClient, namespace);
|
|
78
|
-
await redisClient.destroy();
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
// that ok. No redis connection
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
afterAll(async () => {
|
|
86
|
-
if (serverInstance) {
|
|
87
|
-
serverInstance.app.httpServer?.shutdown();
|
|
88
|
-
serverInstance.app.events.emit('shutdown');
|
|
89
|
-
}
|
|
90
|
-
// if (typeof global.testSetup.afterAll === 'function') {
|
|
91
|
-
// await global.testSetup.afterAll();
|
|
92
|
-
// }
|
|
93
|
-
try {
|
|
94
|
-
await mongoose.connection.db?.dropDatabase(); // clean database after test
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
// that ok. No mongoose connection
|
|
98
|
-
}
|
|
99
|
-
await mongoose.disconnect();
|
|
100
|
-
});
|
|
5
|
+
import { clearTestRedisNamespace, setTestRedisNamespace, startTestServer, stopTestServer, } from "./setupFramework.js";
|
|
6
|
+
beforeAll(startTestServer);
|
|
7
|
+
beforeEach(setTestRedisNamespace);
|
|
8
|
+
afterEach(clearTestRedisNamespace);
|
|
9
|
+
afterAll(stopTestServer);
|
|
101
10
|
//# sourceMappingURL=setupVitest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupVitest.js","sourceRoot":"","sources":["../../src/tests/setupVitest.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"setupVitest.js","sourceRoot":"","sources":["../../src/tests/setupVitest.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAC9E,yEAAyE;AACzE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,EACf,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B,SAAS,CAAC,eAAe,CAAC,CAAC;AAC3B,UAAU,CAAC,qBAAqB,CAAC,CAAC;AAClC,SAAS,CAAC,uBAAuB,CAAC,CAAC;AACnC,QAAQ,CAAC,cAAc,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaptivestone/framework",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Adaptive stone node js framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"prod": "node --watch ./src/cluster.ts",
|
|
37
37
|
"test": "vitest run",
|
|
38
38
|
"t": "vitest --coverage=false --reporter=default",
|
|
39
|
+
"test:node": "node --test --test-global-setup=./src/tests/globalSetupNodeTest.ts 'src/tests/**/*.node-test.ts'",
|
|
39
40
|
"format": "biome format",
|
|
40
41
|
"format:fix": "biome format --write",
|
|
41
42
|
"lint": "biome lint",
|
|
@@ -46,6 +47,8 @@
|
|
|
46
47
|
"smoke": "./scripts/packaging-smoke-test.sh",
|
|
47
48
|
"cli": "node cliCommand.ts",
|
|
48
49
|
"gen": "node cliCommand.ts generatetypes",
|
|
50
|
+
"openapi": "node cliCommand.ts openapi",
|
|
51
|
+
"routes": "node cliCommand.ts routes",
|
|
49
52
|
"dev:bench:realistic": "node ./benchmark/fixtures/realistic.ts",
|
|
50
53
|
"benchmark": "h2load -n 10000 -c 50 -p 'http/1.1' http://localhost:3300/",
|
|
51
54
|
"benchmark2": "h2load -n 10000 -c 50 https://localhost:3300/",
|
|
@@ -56,20 +59,20 @@
|
|
|
56
59
|
"author": "Andrei Lahunou",
|
|
57
60
|
"license": "MIT",
|
|
58
61
|
"dependencies": {
|
|
59
|
-
"@redis/client": "^6.0.0",
|
|
60
62
|
"deepmerge": "^4.2.2",
|
|
61
63
|
"express": "^5.0.1",
|
|
62
64
|
"formidable": "^3.5.1",
|
|
63
65
|
"i18next": "^26.0.1",
|
|
64
66
|
"i18next-fs-backend": "^2.0.0",
|
|
65
67
|
"mongoose": "^9.0.0",
|
|
66
|
-
"oxc-parser": "^0.
|
|
68
|
+
"oxc-parser": "^0.138.0",
|
|
67
69
|
"rate-limiter-flexible": "^11.0.0",
|
|
68
70
|
"winston": "^3.3.3",
|
|
69
71
|
"winston-transport": "^4.9.0"
|
|
70
72
|
},
|
|
71
73
|
"devDependencies": {
|
|
72
74
|
"@biomejs/biome": "^2.0.6",
|
|
75
|
+
"@redis/client": "^6.0.0",
|
|
73
76
|
"@sentry/core": "^10.34.0",
|
|
74
77
|
"@sentry/node": "^10.34.0",
|
|
75
78
|
"@types/express": "^5.0.1",
|
|
@@ -86,6 +89,7 @@
|
|
|
86
89
|
},
|
|
87
90
|
"peerDependencies": {
|
|
88
91
|
"@adaptivestone/framework-module-email": "^1.0.0 || ^2.0.0",
|
|
92
|
+
"@redis/client": "^6.0.0",
|
|
89
93
|
"@sentry/core": "^10.34.0",
|
|
90
94
|
"@sentry/node": "^10.34.0",
|
|
91
95
|
"mongodb-memory-server": "^11.0.0",
|
|
@@ -97,6 +101,9 @@
|
|
|
97
101
|
"@adaptivestone/framework-module-email": {
|
|
98
102
|
"optional": true
|
|
99
103
|
},
|
|
104
|
+
"@redis/client": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
100
107
|
"@sentry/core": {
|
|
101
108
|
"optional": true
|
|
102
109
|
},
|