@dolphjs/testing 1.0.0 → 2.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 CHANGED
@@ -108,12 +108,11 @@ At enterprise scale — hundreds of spec files — `ts-jest` type-checking every
108
108
  - **`TestingRegistry.override(ServiceClass, mock)`** — seed a mock directly, for cases `createTestingApp`'s `overrides` doesn't cover.
109
109
  - **`TestingRegistry.get(ServiceClass)` / `.has(...)`** — read the current registry state.
110
110
  - **`TestingRegistry.reset()`** — clear every cached service. Call between test files, never mid-file.
111
- - **`createTestingApp({ components, overrides?, middlewares? })`** — see above. Returns `{ engine, get, close }`; `close()` is async — it closes the ephemeral server before resolving, so `afterAll(() => app.close())` is enough (Jest awaits the returned promise).
111
+ - **`createTestingApp({ components, overrides?, middlewares?, connect? })`** — see above. Returns `{ engine, get, close }`; `close()` is async — it closes the ephemeral server before resolving, so `afterAll(() => app.close())` is enough (Jest awaits the returned promise).
112
112
  - **`createSqliteTestDataSource({ entities })`** — in-memory `better-sqlite3` TypeORM `DataSource`, entity classes passed directly (no glob strings, no `dolph_config.yaml`).
113
- - **`createSqliteTestSequelize()`** — in-memory `sqlite3` Sequelize instance; call `Model.init({...}, { sequelize })` against it yourself.
114
113
  - **`createMongoMemoryTestServer()`** — real ephemeral MongoDB via `mongodb-memory-server`; returns `{ uri, stop }`.
115
114
 
116
- The three DB helpers lazily `require()` their driver, so an app that only uses Mongoose never resolves `typeorm`/`sequelize`, and vice versa — install only what you use.
115
+ The two DB helpers lazily `require()` their driver, so an app that only uses Mongoose never resolves `typeorm`, and vice versa — install only what you use.
117
116
 
118
117
  ## Development
119
118
 
@@ -5,7 +5,7 @@ export interface MongoMemoryTestServer {
5
5
  /**
6
6
  * Spins up a real, ephemeral MongoDB instance in-process for tests — no
7
7
  * mocked driver, no shared dev database. Pass `.uri` to `mongoose.connect()`
8
- * (or `autoInitMongo({ url: uri })`) in your test setup, and `.stop()` in
8
+ * in your test setup, and `.stop()` in
9
9
  * teardown. Requires `mongodb-memory-server` in the consuming app; lazily
10
10
  * required so apps that don't use Mongoose never pay to resolve it.
11
11
  */
@@ -4,7 +4,7 @@ exports.createMongoMemoryTestServer = createMongoMemoryTestServer;
4
4
  /**
5
5
  * Spins up a real, ephemeral MongoDB instance in-process for tests — no
6
6
  * mocked driver, no shared dev database. Pass `.uri` to `mongoose.connect()`
7
- * (or `autoInitMongo({ url: uri })`) in your test setup, and `.stop()` in
7
+ * in your test setup, and `.stop()` in
8
8
  * teardown. Requires `mongodb-memory-server` in the consuming app; lazily
9
9
  * required so apps that don't use Mongoose never pay to resolve it.
10
10
  */
@@ -8,7 +8,7 @@ export interface SqliteTestDataSourceOptions {
8
8
  /**
9
9
  * An in-memory, `better-sqlite3`-backed TypeORM `DataSource` for tests.
10
10
  *
11
- * Bypasses `autoInitTypeOrm`/`dolph_config.yaml` entirely — those exist to
11
+ * Bypasses `dolph_config.yaml` entirely — those exist to
12
12
  * wire a real database at app boot, which is unnecessary ceremony (and a
13
13
  * shared on-disk file mutation) for a test that just needs a throwaway
14
14
  * schema. Requires `typeorm` and `better-sqlite3` in the consuming app;
@@ -4,7 +4,7 @@ exports.createSqliteTestDataSource = createSqliteTestDataSource;
4
4
  /**
5
5
  * An in-memory, `better-sqlite3`-backed TypeORM `DataSource` for tests.
6
6
  *
7
- * Bypasses `autoInitTypeOrm`/`dolph_config.yaml` entirely — those exist to
7
+ * Bypasses `dolph_config.yaml` entirely — those exist to
8
8
  * wire a real database at app boot, which is unnecessary ceremony (and a
9
9
  * shared on-disk file mutation) for a test that just needs a throwaway
10
10
  * schema. Requires `typeorm` and `better-sqlite3` in the consuming app;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,5 @@ export { createTestingApp } from './testing-app';
4
4
  export type { TestingApp, TestingAppOptions, ComponentRef, ServiceOverride } from './testing-app';
5
5
  export { createSqliteTestDataSource } from './db/sqlite-typeorm';
6
6
  export type { SqliteTestDataSourceOptions } from './db/sqlite-typeorm';
7
- export { createSqliteTestSequelize } from './db/sqlite-sequelize';
8
7
  export { createMongoMemoryTestServer } from './db/mongo-memory';
9
8
  export type { MongoMemoryTestServer } from './db/mongo-memory';
package/dist/index.js CHANGED
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMongoMemoryTestServer = exports.createSqliteTestSequelize = exports.createSqliteTestDataSource = exports.createTestingApp = exports.TestingRegistry = void 0;
3
+ exports.createMongoMemoryTestServer = exports.createSqliteTestDataSource = exports.createTestingApp = exports.TestingRegistry = void 0;
4
4
  var testing_registry_1 = require("./testing-registry");
5
5
  Object.defineProperty(exports, "TestingRegistry", { enumerable: true, get: function () { return testing_registry_1.TestingRegistry; } });
6
6
  var testing_app_1 = require("./testing-app");
7
7
  Object.defineProperty(exports, "createTestingApp", { enumerable: true, get: function () { return testing_app_1.createTestingApp; } });
8
8
  var sqlite_typeorm_1 = require("./db/sqlite-typeorm");
9
9
  Object.defineProperty(exports, "createSqliteTestDataSource", { enumerable: true, get: function () { return sqlite_typeorm_1.createSqliteTestDataSource; } });
10
- var sqlite_sequelize_1 = require("./db/sqlite-sequelize");
11
- Object.defineProperty(exports, "createSqliteTestSequelize", { enumerable: true, get: function () { return sqlite_sequelize_1.createSqliteTestSequelize; } });
12
10
  var mongo_memory_1 = require("./db/mongo-memory");
13
11
  Object.defineProperty(exports, "createMongoMemoryTestServer", { enumerable: true, get: function () { return mongo_memory_1.createMongoMemoryTestServer; } });
14
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AAGxB,6CAAiD;AAAxC,+GAAA,gBAAgB,OAAA;AAGzB,sDAAiE;AAAxD,4HAAA,0BAA0B,OAAA;AAGnC,0DAAkE;AAAzD,6HAAA,yBAAyB,OAAA;AAElC,kDAAgE;AAAvD,2HAAA,2BAA2B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AAGxB,6CAAiD;AAAxC,+GAAA,gBAAgB,OAAA;AAGzB,sDAAiE;AAAxD,4HAAA,0BAA0B,OAAA;AAInC,kDAAgE;AAAvD,2HAAA,2BAA2B,OAAA"}
@@ -20,15 +20,17 @@ export interface TestingAppOptions {
20
20
  components: ComponentRef[];
21
21
  /** Mocks seeded into the registry before `components` are resolved. */
22
22
  overrides?: ServiceOverride[];
23
- /** Applied before route registration — same ordering as `DolphFactory`'s constructor. */
23
+ /** The `middlewares` option of `DolphFactory`, applied before routes. */
24
24
  middlewares?: RequestHandler[];
25
+ /** Connects the databases in `dolph_config.yaml` before returning. Off by default. */
26
+ connect?: boolean;
25
27
  }
26
28
  export interface TestingApp {
27
29
  /** A real, already-listening ephemeral server — hand it straight to supertest. */
28
30
  engine: Server;
29
31
  /** Reads a service instance (real or mocked) straight off the registry, for direct assertions. */
30
32
  get<T>(serviceClass: Ctor<T>): T | undefined;
31
- /** Closes the ephemeral server and clears the process-wide registry. Call in `afterAll`. */
33
+ /** Closes the ephemeral server and any databases, and clears the process-wide registry. Call in `afterAll`. */
32
34
  close(): Promise<void>;
33
35
  }
34
36
  /**
@@ -23,7 +23,7 @@ const isLoader = (ref) => typeof ref === 'function' && ref.prototype === undefin
23
23
  * side effects.
24
24
  */
25
25
  async function createTestingApp(options) {
26
- const { components, overrides = [], middlewares } = options;
26
+ const { components, overrides = [], middlewares, connect = false } = options;
27
27
  // 1. Seed mocks first — see the module-level doc comment on why ordering matters.
28
28
  for (const { service, useValue } of overrides) {
29
29
  dolph_1.GlobalServiceRegistry.set(service, useValue);
@@ -41,15 +41,19 @@ async function createTestingApp(options) {
41
41
  resolved.push(ref);
42
42
  }
43
43
  }
44
- const factory = new dolph_1.DolphFactory(resolved, middlewares);
44
+ const factory = new dolph_1.DolphFactory(resolved, { middlewares });
45
+ if (connect) {
46
+ await factory.ready();
47
+ }
45
48
  const server = (0, http_1.createServer)(factory.engine()).listen(0);
46
49
  return {
47
50
  engine: server,
48
51
  get: (serviceClass) => dolph_1.GlobalServiceRegistry.get(serviceClass),
49
- close: () => new Promise((resolve) => {
52
+ close: async () => {
50
53
  dolph_1.GlobalServiceRegistry._reset();
51
- server.close(() => resolve());
52
- }),
54
+ await new Promise((resolve) => server.close(() => resolve()));
55
+ await factory.stop();
56
+ },
53
57
  };
54
58
  }
55
59
  //# sourceMappingURL=testing-app.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing-app.js","sourceRoot":"","sources":["../src/testing-app.ts"],"names":[],"mappings":";;AAyDA,4CAiCC;AA1FD,4BAA0B;AAC1B,+BAA4C;AAC5C,0CAAqE;AAmCrE,MAAM,QAAQ,GAAG,CAAC,GAAiB,EAAkD,EAAE,CACnF,OAAO,GAAG,KAAK,UAAU,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,gBAAgB,CAAC,OAA0B;IAC7D,MAAM,EAAE,UAAU,EAAE,SAAS,GAAG,EAAE,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAE5D,kFAAkF;IAClF,KAAK,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,SAAS,EAAE,CAAC;QAC5C,6BAAqB,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;IAED,yEAAyE;IACzE,0EAA0E;IAC1E,2CAA2C;IAC3C,MAAM,QAAQ,GAAW,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC3B,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAChB,MAAM,GAAG,GAAG,MAAM,GAAG,EAAE,CAAC;YACxB,QAAQ,CAAC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N,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolphjs/testing",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Official testing utilities for DolphJS applications — fast, isolated unit tests and lightweight HTTP integration tests built for the framework's decoration-time DI model.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,19 +26,15 @@
26
26
  "test:examples": "jest --config jest.examples.config.js"
27
27
  },
28
28
  "peerDependencies": {
29
- "@dolphjs/dolph": ">=2.0.0",
29
+ "@dolphjs/dolph": ">=3.0.0",
30
30
  "reflect-metadata": "^0.1.13 || ^0.2.0",
31
31
  "mongodb-memory-server": ">=9.0.0",
32
- "sequelize": ">=6.0.0",
33
32
  "typeorm": ">=0.3.0"
34
33
  },
35
34
  "peerDependenciesMeta": {
36
35
  "mongodb-memory-server": {
37
36
  "optional": true
38
37
  },
39
- "sequelize": {
40
- "optional": true
41
- },
42
38
  "typeorm": {
43
39
  "optional": true
44
40
  }
@@ -53,7 +49,6 @@
53
49
  "mongodb-memory-server": "^9.2.0",
54
50
  "reflect-metadata": "^0.2.2",
55
51
  "rimraf": "^5.0.7",
56
- "sequelize": "^6.37.3",
57
52
  "supertest": "^7.0.0",
58
53
  "ts-jest": "^29.2.3",
59
54
  "typeorm": "^0.3.20",
@@ -1,12 +0,0 @@
1
- import type { Sequelize } from 'sequelize';
2
- /**
3
- * An in-memory `sqlite3`-backed Sequelize instance for tests.
4
- *
5
- * Hands back a bare, connected instance only — Sequelize models are bound to
6
- * an instance at `Model.init({...}, { sequelize, ... })`, so re-attaching
7
- * already-initialized models the way `autoInitSql` does for a real app isn't
8
- * meaningful here. Call `Model.init` against the returned instance in your
9
- * test setup. Requires `sequelize` and `sqlite3` in the consuming app;
10
- * lazily required so apps that don't use Sequelize never pay to resolve them.
11
- */
12
- export declare function createSqliteTestSequelize(): Promise<Sequelize>;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSqliteTestSequelize = createSqliteTestSequelize;
4
- /**
5
- * An in-memory `sqlite3`-backed Sequelize instance for tests.
6
- *
7
- * Hands back a bare, connected instance only — Sequelize models are bound to
8
- * an instance at `Model.init({...}, { sequelize, ... })`, so re-attaching
9
- * already-initialized models the way `autoInitSql` does for a real app isn't
10
- * meaningful here. Call `Model.init` against the returned instance in your
11
- * test setup. Requires `sequelize` and `sqlite3` in the consuming app;
12
- * lazily required so apps that don't use Sequelize never pay to resolve them.
13
- */
14
- async function createSqliteTestSequelize() {
15
- let SequelizeCtor;
16
- try {
17
- ({ Sequelize: SequelizeCtor } = require('sequelize'));
18
- }
19
- catch {
20
- throw new Error('`sequelize` is not installed. Run `npm i -D sequelize sqlite3` to use createSqliteTestSequelize().');
21
- }
22
- const sequelize = new SequelizeCtor({
23
- dialect: 'sqlite',
24
- storage: ':memory:',
25
- logging: false,
26
- });
27
- await sequelize.authenticate();
28
- return sequelize;
29
- }
30
- //# sourceMappingURL=sqlite-sequelize.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite-sequelize.js","sourceRoot":"","sources":["../../src/db/sqlite-sequelize.ts"],"names":[],"mappings":";;AAYA,8DAkBC;AA5BD;;;;;;;;;GASG;AACI,KAAK,UAAU,yBAAyB;IAC3C,IAAI,aAA+B,CAAC;IACpC,IAAI,CAAC;QACD,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACL,MAAM,IAAI,KAAK,CACX,oGAAoG,CACvG,CAAC;IACN,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,aAAa,CAAC;QAChC,OAAO,EAAE,QAAQ;QACjB,OAAO,EAAE,UAAU;QACnB,OAAO,EAAE,KAAK;KACjB,CAAC,CAAC;IAEH,MAAM,SAAS,CAAC,YAAY,EAAE,CAAC;IAC/B,OAAO,SAAS,CAAC;AACrB,CAAC"}