##// END OF EJS Templates
added provided and configure methods to the fluent container configuration, added applyConfig method to the container
added provided and configure methods to the fluent container configuration, added applyConfig method to the container

File last commit:

r115:691199f665e0 ioc ts support
r142:be7edf08a115 v1.4.0-rc3 default
Show More
TestTraits.ts
77 lines | 2.3 KiB | video/mp2t | TypeScriptLexer
cin
migrating tests to the new project structure
r89 import { IObservable, ICancellation, IDestroyable } from "../interfaces";
import { Cancellation } from "../Cancellation";
import { TraceEvent, LogLevel, WarnLevel, DebugLevel, TraceSource } from "../log/TraceSource";
import * as tape from "tape";
import { argumentNotNull, destroy } from "../safe";
export class TapeWriter implements IDestroyable {
private readonly _tape: tape.Test;
private readonly _subscriptions = new Array<IDestroyable>();
cin
corrected code to support ts strict mode...
r115 private _destroyed = false;
cin
migrating tests to the new project structure
r89
constructor(t: tape.Test) {
argumentNotNull(t, "tape");
this._tape = 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._tape.comment(`DEBUG ${next.source.id} ${next}`);
} else if (next.level >= LogLevel) {
this._tape.comment(`LOG ${next.source.id} ${next}`);
} else if (next.level >= WarnLevel) {
this._tape.comment(`WARN ${next.source.id} ${next}`);
} else {
this._tape.comment(`ERROR ${next.source.id} ${next}`);
}
}
destroy() {
cin
corrected code to support ts strict mode...
r115 if (this._destroyed)
return;
this._destroyed = true;
cin
migrating tests to the new project structure
r89 this._subscriptions.forEach(destroy);
}
}
export function test(name: string, cb: (t: tape.Test, trace: TraceSource) => any) {
tape(name, async t => {
const writer = new TapeWriter(t);
// this trace is not announced through the TraceSource global registry
const trace = new TraceSource(name);
trace.level = DebugLevel;
writer.writeEvents(trace.events);
const h = TraceSource.on(ts => {
ts.level = DebugLevel;
writer.writeEvents(ts.events);
});
try {
await cb(t, trace);
} catch (e) {
// verbose error information
// tslint:disable-next-line
console.error(e);
t.fail(e);
} finally {
t.end();
destroy(writer);
destroy(h);
}
});
}