mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
parent
1fcc11a19d
commit
3a6d4e6260
2 changed files with 28 additions and 10 deletions
|
@ -181,29 +181,29 @@ export class Console {
|
||||||
constructor(private printFunc: PrintFunc) {}
|
constructor(private printFunc: PrintFunc) {}
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
log(...args: any[]): void {
|
log = (...args: any[]): void => {
|
||||||
this.printFunc(stringifyArgs(args));
|
this.printFunc(stringifyArgs(args));
|
||||||
}
|
};
|
||||||
|
|
||||||
debug = this.log;
|
debug = this.log;
|
||||||
info = this.log;
|
info = this.log;
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
dir(obj: any, options: ConsoleOptions = {}) {
|
dir = (obj: any, options: ConsoleOptions = {}) => {
|
||||||
this.printFunc(stringifyArgs([obj], options));
|
this.printFunc(stringifyArgs([obj], options));
|
||||||
}
|
};
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
warn(...args: any[]): void {
|
warn = (...args: any[]): void => {
|
||||||
this.printFunc(stringifyArgs(args), true);
|
this.printFunc(stringifyArgs(args), true);
|
||||||
}
|
};
|
||||||
|
|
||||||
error = this.warn;
|
error = this.warn;
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
assert(condition: boolean, ...args: any[]): void {
|
assert = (condition: boolean, ...args: any[]): void => {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
throw new Error(`Assertion failed: ${stringifyArgs(args)}`);
|
throw new Error(`Assertion failed: ${stringifyArgs(args)}`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { test, assertEqual } from "./test_util.ts";
|
import { test, assert, assertEqual } from "./test_util.ts";
|
||||||
import { stringifyArgs } from "./console.ts";
|
import { stringifyArgs } from "./console.ts";
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
|
@ -88,7 +88,7 @@ test(function consoleTestStringifyCircular() {
|
||||||
assertEqual(stringify(JSON), "{}");
|
assertEqual(stringify(JSON), "{}");
|
||||||
assertEqual(
|
assertEqual(
|
||||||
stringify(console),
|
stringify(console),
|
||||||
"Console { printFunc: [Function], debug: [Function: log], info: [Function: log], error: [Function: warn] }"
|
"Console { printFunc: [Function], log: [Function], debug: [Function], info: [Function], dir: [Function], warn: [Function], error: [Function], assert: [Function] }"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -122,3 +122,21 @@ test(function consoleTestError() {
|
||||||
assertEqual(stringify(e).split("\n")[0], "MyError: This is an error");
|
assertEqual(stringify(e).split("\n")[0], "MyError: This is an error");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test bound this issue
|
||||||
|
test(function consoleDetachedLog() {
|
||||||
|
const log = console.log;
|
||||||
|
const dir = console.dir;
|
||||||
|
const debug = console.debug;
|
||||||
|
const info = console.info;
|
||||||
|
const warn = console.warn;
|
||||||
|
const error = console.error;
|
||||||
|
const consoleAssert = console.assert;
|
||||||
|
log("Hello world");
|
||||||
|
dir("Hello world");
|
||||||
|
debug("Hello world");
|
||||||
|
info("Hello world");
|
||||||
|
warn("Hello world");
|
||||||
|
error("Hello world");
|
||||||
|
consoleAssert(true);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue