diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 22:39:18 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 22:39:18 -0800 |
| commit | 666674327f009e9b1013218fc384f193b64c6997 (patch) | |
| tree | acebae7b425b469584eb0a5bec396899c2739501 /tst/test_utils.ts | |
| parent | 594ce452693a71b501d3aff3f35ef3732c06c341 (diff) | |
| download | pengueno-666674327f009e9b1013218fc384f193b64c6997.tar.gz pengueno-666674327f009e9b1013218fc384f193b64c6997.zip | |
Adds unit tests
Diffstat (limited to 'tst/test_utils.ts')
| -rw-r--r-- | tst/test_utils.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tst/test_utils.ts b/tst/test_utils.ts new file mode 100644 index 0000000..5c6237c --- /dev/null +++ b/tst/test_utils.ts @@ -0,0 +1,30 @@ +import { type ITrace, type ITraceWith, TraceableImpl } from '../lib/index'; + +export class CollectingTrace<TraceWith> implements ITrace<TraceWith> { + constructor( + private readonly collector: Array<Array<ITraceWith<TraceWith>>> = [], + private readonly scopes: Array<ITraceWith<TraceWith>> = [], + ) {} + + public get events() { + return this.collector; + } + + public traceScope(trace: ITraceWith<TraceWith>): ITrace<TraceWith> { + return new CollectingTrace(this.collector, this.scopes.concat([trace])); + } + + public trace(trace: ITraceWith<TraceWith>) { + this.collector.push(this.scopes.concat([trace])); + } +} + +export class TestTraceable<T, TraceWith> extends TraceableImpl<T, TraceWith> { + constructor(item: T, trace: ITrace<TraceWith>) { + super(item, trace); + } + + static of<T, TraceWith>(item: T, trace: ITrace<TraceWith>) { + return new TestTraceable<T, TraceWith>(item, trace); + } +} |
