|
|
import { IObservable, ICancellation, IDestroyable } from "@implab/core-amd/interfaces";
|
|
|
import { Cancellation } from "@implab/core-amd/Cancellation";
|
|
|
import { TraceEvent, LogLevel, WarnLevel, DebugLevel, TraceSource } from "@implab/core-amd/log/TraceSource";
|
|
|
import { argumentNotNull, destroy } from "@implab/core-amd/safe";
|
|
|
import { TapWriter } from "./Tap";
|
|
|
|
|
|
|
|
|
|
|
|
export class TapeWriter implements IDestroyable {
|
|
|
|
|
|
private readonly _t: TapWriter;
|
|
|
|
|
|
private readonly _subscriptions = new Array<IDestroyable>();
|
|
|
private _destroyed;
|
|
|
|
|
|
constructor(t: TapWriter) {
|
|
|
argumentNotNull(t, "test");
|
|
|
|
|
|
}
|
|
|
|
|
|
writeEvents(source: IObservable<TraceEvent>, ct: ICancellation = Cancellation.none) {
|
|
|
if (!this._destroyed) {
|
|
|
const subscription = source.on(this.writeEvent.bind(this));
|
|
|
if (ct.isSupported()) {
|
|
|
ct.register(subscription.destroy.bind(subscription));
|
|
|
}
|
|
|
this._subscriptions.push(subscription);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
writeEvent(next: TraceEvent) {
|
|
|
if (next.level >= DebugLevel) {
|
|
|
this._t.comment(`DEBUG ${next.source.id} ${next}`);
|
|
|
} else if (next.level >= LogLevel) {
|
|
|
this._t.comment(`LOG ${next.source.id} ${next}`);
|
|
|
} else if (next.level >= WarnLevel) {
|
|
|
this._t.comment(`WARN ${next.source.id} ${next}`);
|
|
|
} else {
|
|
|
this._t.comment(`ERROR ${next.source.id} ${next}`);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
destroy() {
|
|
|
this._subscriptions.forEach(destroy);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
type TestCallback = (ok: (msg:string) => void, fail: (msg:string) => void, trace: TraceSource) => void;
|
|
|
type AsyncTestCallback = (trace: TraceSource) => PromiseLike<void> | void;
|
|
|
|
|
|
export function test(name: string, cb: TestCallback | AsyncTestCallback) {
|
|
|
|
|
|
}
|
|
|
|
|
|
export function run() {
|
|
|
|
|
|
}
|
|
|
|