@dudousxd/nestjs-telescope-testing 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Davi Carvalho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @dudousxd/nestjs-telescope-testing
2
+
3
+ Test utilities for [`@dudousxd/nestjs-telescope`](https://github.com/DavideCarvalho/nestjs-telescope).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add -D @dudousxd/nestjs-telescope-testing
9
+ ```
10
+
11
+ ## `FakeClock`
12
+
13
+ A deterministic clock you can pass as the `now` option to `Recorder`.
14
+
15
+ ```ts
16
+ import { FakeClock } from '@dudousxd/nestjs-telescope-testing';
17
+
18
+ const clock = new FakeClock(0);
19
+ clock.now(); // 0
20
+ clock.advance(500); // move forward 500 ms
21
+ clock.now(); // 500
22
+ clock.set(1000); // jump to absolute ms
23
+ clock.now(); // 1000
24
+ ```
25
+
26
+ ## `collectWatcherEntries`
27
+
28
+ Registers a `Watcher` against a minimal capturing `WatcherContext` and returns everything it recorded — no NestJS app required.
29
+
30
+ ```ts
31
+ import { collectWatcherEntries } from '@dudousxd/nestjs-telescope-testing';
32
+ import type { Watcher, WatcherContext } from '@dudousxd/nestjs-telescope';
33
+
34
+ const myWatcher: Watcher = {
35
+ type: 'demo',
36
+ register(ctx: WatcherContext) {
37
+ ctx.record({ type: 'demo', content: { hello: 'world' } });
38
+ },
39
+ };
40
+
41
+ const { recorded, context } = await collectWatcherEntries(myWatcher);
42
+ // recorded[0] => { type: 'demo', content: { hello: 'world' } }
43
+
44
+ // You can also drive batch handles:
45
+ const handle = context.beginBatch('manual');
46
+ // handle.id => 'batch-0'
47
+ handle.end();
48
+ ```
49
+
50
+ ## `InMemoryStorageProvider` (re-export)
51
+
52
+ `@dudousxd/nestjs-telescope-testing` re-exports `InMemoryStorageProvider` from core so tests only need one import.
53
+
54
+ ```ts
55
+ import { InMemoryStorageProvider } from '@dudousxd/nestjs-telescope-testing';
56
+
57
+ const storage = new InMemoryStorageProvider();
58
+ ```
@@ -0,0 +1,8 @@
1
+ import { type RecordInput, type Watcher, type WatcherContext } from '@dudousxd/nestjs-telescope';
2
+ export interface CollectedWatcher {
3
+ recorded: RecordInput[];
4
+ context: WatcherContext;
5
+ }
6
+ /** Register `watcher` against a capturing context; returns recorded inputs + the context. */
7
+ export declare function collectWatcherEntries(watcher: Watcher): Promise<CollectedWatcher>;
8
+ //# sourceMappingURL=collect-watcher-entries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect-watcher-entries.d.ts","sourceRoot":"","sources":["../src/collect-watcher-entries.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,cAAc,EAEpB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,OAAO,EAAE,cAAc,CAAC;CACzB;AAED,6FAA6F;AAC7F,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqBvF"}
@@ -0,0 +1,23 @@
1
+ import { resolveConfig, } from '@dudousxd/nestjs-telescope';
2
+ /** Register `watcher` against a capturing context; returns recorded inputs + the context. */
3
+ export async function collectWatcherEntries(watcher) {
4
+ const recorded = [];
5
+ const config = resolveConfig({});
6
+ let counter = 0;
7
+ const context = {
8
+ record: (input) => {
9
+ recorded.push(input);
10
+ },
11
+ runInBatch: (_origin, fn) => fn(),
12
+ beginBatch: () => ({ id: `batch-${counter++}`, end: () => { } }),
13
+ config,
14
+ moduleRef: {
15
+ get: () => {
16
+ throw new Error('moduleRef.get is not available in collectWatcherEntries');
17
+ },
18
+ },
19
+ };
20
+ await watcher.register(context);
21
+ return { recorded, context };
22
+ }
23
+ //# sourceMappingURL=collect-watcher-entries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect-watcher-entries.js","sourceRoot":"","sources":["../src/collect-watcher-entries.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,GACd,MAAM,4BAA4B,CAAC;AAOpC,6FAA6F;AAC7F,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAAgB;IAC1D,MAAM,QAAQ,GAAkB,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IACjC,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,MAAM,OAAO,GAAmB;QAC9B,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YAChB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,UAAU,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE;QACjC,UAAU,EAAE,GAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;QAC5E,MAAM;QACN,SAAS,EAAE;YACT,GAAG,EAAE,GAAG,EAAE;gBACR,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;YAC7E,CAAC;SACwC;KAC5C,CAAC;IAEF,MAAM,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** A controllable clock for deterministic tests. */
2
+ export declare class FakeClock {
3
+ private current;
4
+ constructor(current?: number);
5
+ /** Returns the current epoch-ms; pass as the Recorder's `now`. */
6
+ now: () => number;
7
+ /** Advance the clock by `ms`. */
8
+ advance(ms: number): void;
9
+ /** Set the clock to an absolute epoch-ms. */
10
+ set(ms: number): void;
11
+ }
12
+ //# sourceMappingURL=fake-clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-clock.d.ts","sourceRoot":"","sources":["../src/fake-clock.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,qBAAa,SAAS;IACR,OAAO,CAAC,OAAO;gBAAP,OAAO,SAAI;IAE/B,kEAAkE;IAClE,GAAG,QAAO,MAAM,CAAiB;IAEjC,iCAAiC;IACjC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIzB,6CAA6C;IAC7C,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAGtB"}
@@ -0,0 +1,18 @@
1
+ /** A controllable clock for deterministic tests. */
2
+ export class FakeClock {
3
+ current;
4
+ constructor(current = 0) {
5
+ this.current = current;
6
+ }
7
+ /** Returns the current epoch-ms; pass as the Recorder's `now`. */
8
+ now = () => this.current;
9
+ /** Advance the clock by `ms`. */
10
+ advance(ms) {
11
+ this.current += ms;
12
+ }
13
+ /** Set the clock to an absolute epoch-ms. */
14
+ set(ms) {
15
+ this.current = ms;
16
+ }
17
+ }
18
+ //# sourceMappingURL=fake-clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-clock.js","sourceRoot":"","sources":["../src/fake-clock.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,OAAO,SAAS;IACA;IAApB,YAAoB,UAAU,CAAC;QAAX,YAAO,GAAP,OAAO,CAAI;IAAG,CAAC;IAEnC,kEAAkE;IAClE,GAAG,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;IAEjC,iCAAiC;IACjC,OAAO,CAAC,EAAU;QAChB,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;IACrB,CAAC;IAED,6CAA6C;IAC7C,GAAG,CAAC,EAAU;QACZ,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export { InMemoryStorageProvider } from '@dudousxd/nestjs-telescope';
2
+ export * from './fake-clock.js';
3
+ export * from './collect-watcher-entries.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { InMemoryStorageProvider } from '@dudousxd/nestjs-telescope';
2
+ export * from './fake-clock.js';
3
+ export * from './collect-watcher-entries.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@dudousxd/nestjs-telescope-testing",
3
+ "version": "1.0.0",
4
+ "description": "Test utilities for @dudousxd/nestjs-telescope — FakeClock, watcher harness, InMemoryStorageProvider re-export.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/DavideCarvalho/nestjs-telescope.git",
9
+ "directory": "packages/testing"
10
+ },
11
+ "author": "Davi Carvalho <davi@goflip.ai>",
12
+ "type": "module",
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist/",
24
+ "README.md"
25
+ ],
26
+ "peerDependencies": {
27
+ "@dudousxd/nestjs-telescope": "1.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^20.0.0",
31
+ "typescript": "^5.4.0",
32
+ "vitest": "^3.0.0",
33
+ "@dudousxd/nestjs-telescope": "1.0.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=20"
37
+ },
38
+ "keywords": [
39
+ "nestjs",
40
+ "telescope",
41
+ "testing",
42
+ "observability"
43
+ ],
44
+ "scripts": {
45
+ "build": "tsc -p tsconfig.json",
46
+ "test": "vitest run --passWithNoTests",
47
+ "test:watch": "vitest",
48
+ "typecheck": "tsc -p tsconfig.json --noEmit"
49
+ }
50
+ }