##// END OF EJS Templates
fixed dependencies
fixed dependencies

File last commit:

r2:8ec37bf1b4d1 default
r3:fb4d13ff05ae default
Show More
TestTraits.ts
62 lines | 2.0 KiB | video/mp2t | TypeScriptLexer
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 = false;
constructor(t: TapWriter) {
argumentNotNull(t, "test");
this._t = t;
}
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() {
if (this._destroyed)
return;
this._destroyed = true;
this._subscriptions.forEach(destroy);
}
}
type TestCallback = (ok: (msg: string) => void, fail: (msg: string) => void, trace: TraceSource) => void;
type AsyncTestCallback = (trace: TraceSource) => PromiseLike<void>;
export function test(name: string, cb: TestCallback ): void;
export function test(name: string, cb: AsyncTestCallback): void;
export function test(name: string, cb: TestCallback | AsyncTestCallback) {
}
export function run() {
}