##// END OF EJS Templates
tests
tests

File last commit:

r41:eae7e609c38a di-typescript
r41:eae7e609c38a di-typescript
Show More
TestTraits.ts
79 lines | 2.1 KiB | video/mp2t | TypeScriptLexer
cin
Code cleanup,...
r22 import { IObservable, ICancellation, IDestroyable } from "@implab/core/interfaces";
import { Cancellation } from "@implab/core/Cancellation";
import { TraceEvent, LogLevel, WarnLevel } 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
Code cleanup,...
r22 if (next.level >= LogLevel) {
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 this._tape.comment("LOG " + next.arg);
cin
Code cleanup,...
r22 } else if (next.level >= WarnLevel) {
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 this._tape.comment("WARN " + next.arg);
} else {
this._tape.comment("ERROR " + next.arg);
}
}
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 => {
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();
}
});
}