summaryrefslogtreecommitdiff
path: root/tst/test_utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tst/test_utils.ts')
-rw-r--r--tst/test_utils.ts30
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);
+ }
+}