##// END OF EJS Templates
fixes, tests...
fixes, tests di/configuration now works

File last commit:

r44:7a410676c874 di-typescript
r44:7a410676c874 di-typescript
Show More
TestTraits.ts
89 lines | 2.5 KiB | video/mp2t | TypeScriptLexer
cin
Code cleanup,...
r22 import { IObservable, ICancellation, IDestroyable } from "@implab/core/interfaces";
import { Cancellation } from "@implab/core/Cancellation";
cin
fixes, tests...
r44 import { TraceEvent, LogLevel, WarnLevel, DebugLevel, TraceSource } from "@implab/core/log/TraceSource";
cin
tests, refactoring, fixes
r40 import * as tape from "tape";
cin
Code cleanup,...
r22 import { argumentNotNull } from "@implab/core/safe";
cin
fixed format-compile bug while formatting strings with new line symbols....
r15
export class TapeWriter implements IDestroyable {
cin
tests, refactoring, fixes
r40 readonly _tape: tape.Test;
cin
fixed format-compile bug while formatting strings with new line symbols....
r15
_subscriptions = new Array<IDestroyable>();
cin
tests, refactoring, fixes
r40 constructor(t: tape.Test) {
argumentNotNull(t, "tape");
this._tape = t;
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 }
writeEvents(source: IObservable<TraceEvent>, ct: ICancellation = Cancellation.none) {
cin
tests, refactoring, fixes
r40 const subscription = source.on(this.writeEvent.bind(this));
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 if (ct.isSupported()) {
ct.register(subscription.destroy.bind(subscription));
}
this._subscriptions.push(subscription);
}
writeEvent(next: TraceEvent) {
cin
fixes, tests...
r44 if (next.level >= DebugLevel) {
this._tape.comment(`DEBUG ${next.source.id} ${next.arg}`);
} else if (next.level >= LogLevel) {
this._tape.comment(`LOG ${next.source.id} ${next.arg}`);
cin
Code cleanup,...
r22 } else if (next.level >= WarnLevel) {
cin
fixes, tests...
r44 this._tape.comment(`WARN ${next.source.id} ${next.arg}`);
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 } else {
cin
fixes, tests...
r44 this._tape.comment(`ERROR ${next.source.id} ${next.arg}`);
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 }
}
destroy() {
this._subscriptions.forEach(x => x.destroy());
}
cin
added CancellationTests...
r18 }
export async function delay(timeout: number, ct: ICancellation = Cancellation.none) {
let un: IDestroyable;
cin
tests, refactoring, fixes
r40
cin
added CancellationTests...
r18 try {
cin
tests, refactoring, fixes
r40 await new Promise((resolve, reject) => {
cin
added CancellationTests...
r18 if (ct.isRequested()) {
cin
tests, refactoring, fixes
r40 un = ct.register(reject);
} else {
const ht = setTimeout(() => {
resolve();
}, timeout);
un = ct.register(e => {
clearTimeout(ht);
reject(e);
});
}
});
cin
added CancellationTests...
r18 } finally {
cin
tests, refactoring, fixes
r40 if (un)
un.destroy();
}
}
export function test(name: string, cb: (t: tape.Test) => any) {
tape(name, async t => {
cin
fixes, tests...
r44 const writer = new TapeWriter(t);
TraceSource.on(ts => {
ts.level = DebugLevel;
writer.writeEvents(ts.events);
});
cin
tests, refactoring, fixes
r40 try {
await cb(t);
} catch (e) {
cin
tests
r41
// verbose error information
// tslint:disable-next-line
cin
tests, refactoring, fixes
r40 console.error(e);
t.fail(e);
cin
tests
r41
cin
tests, refactoring, fixes
r40 } finally {
t.end();
cin
fixes, tests...
r44 writer.destroy();
cin
tests, refactoring, fixes
r40 }
});
}