blob: ad31d05f536090dc379ef58e7b69f7ead50e66c2 [file] [log] [blame] [edit]
// TestFixture records log messages and errors in an array that will
// be returned to Go code. Each element in the result array is either
// an array of the form ["LOG", ...], or ["ERROR", ...].
class TestFixture {
constructor() {
this.context = ""; // Added to front of all log and error messages.
this.result = [];
}
run(name, subtest) {
this.result.push(["LOG", "===", name]);
this.context = "";
subtest();
this.context = "";
}
// setContext arranges to add name(args) to all messages added
// until the next setContext or run call.
setContext(name, ...args) {
this.context = name + "(" + args.join(",") + ")";
}
log(...args) {
this.result.push(["LOG", this.context, ...args]);
}
err(...args) {
this.result.push(["ERROR", this.context, ...args]);
}
}