1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00

misc: reduce unnecesarry output in cli/js tests (#4182)

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Yusuke Sakurai 2020-03-03 23:51:07 +09:00 committed by GitHub
parent 3968308886
commit 4dc004f0a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 76 additions and 75 deletions

View file

@ -37,16 +37,17 @@ test(function consoleHasRightInstance(): void {
}); });
test(function consoleTestAssertShouldNotThrowError(): void { test(function consoleTestAssertShouldNotThrowError(): void {
console.assert(true); mockConsole(console => {
console.assert(true);
let hasThrown = undefined; let hasThrown = undefined;
try { try {
console.assert(false); console.assert(false);
hasThrown = false; hasThrown = false;
} catch { } catch {
hasThrown = true; hasThrown = true;
} }
assertEquals(hasThrown, false); assertEquals(hasThrown, false);
});
}); });
test(function consoleTestStringifyComplexObjects(): void { test(function consoleTestStringifyComplexObjects(): void {
@ -302,19 +303,18 @@ test(function consoleTestWithVariousOrInvalidFormatSpecifier(): void {
test(function consoleTestCallToStringOnLabel(): void { test(function consoleTestCallToStringOnLabel(): void {
const methods = ["count", "countReset", "time", "timeLog", "timeEnd"]; const methods = ["count", "countReset", "time", "timeLog", "timeEnd"];
mockConsole(console => {
for (const method of methods) { for (const method of methods) {
let hasCalled = false; let hasCalled = false;
// @ts-ignore
// @ts-ignore console[method]({
console[method]({ toString(): void {
toString(): void { hasCalled = true;
hasCalled = true; }
} });
}); assertEquals(hasCalled, true);
}
assertEquals(hasCalled, true); });
}
}); });
test(function consoleTestError(): void { test(function consoleTestError(): void {
@ -355,40 +355,42 @@ test(function consoleTestClear(): void {
// Test bound this issue // Test bound this issue
test(function consoleDetachedLog(): void { test(function consoleDetachedLog(): void {
const log = console.log; mockConsole(console => {
const dir = console.dir; const log = console.log;
const dirxml = console.dirxml; const dir = console.dir;
const debug = console.debug; const dirxml = console.dirxml;
const info = console.info; const debug = console.debug;
const warn = console.warn; const info = console.info;
const error = console.error; const warn = console.warn;
const consoleAssert = console.assert; const error = console.error;
const consoleCount = console.count; const consoleAssert = console.assert;
const consoleCountReset = console.countReset; const consoleCount = console.count;
const consoleTable = console.table; const consoleCountReset = console.countReset;
const consoleTime = console.time; const consoleTable = console.table;
const consoleTimeLog = console.timeLog; const consoleTime = console.time;
const consoleTimeEnd = console.timeEnd; const consoleTimeLog = console.timeLog;
const consoleGroup = console.group; const consoleTimeEnd = console.timeEnd;
const consoleGroupEnd = console.groupEnd; const consoleGroup = console.group;
const consoleClear = console.clear; const consoleGroupEnd = console.groupEnd;
log("Hello world"); const consoleClear = console.clear;
dir("Hello world"); log("Hello world");
dirxml("Hello world"); dir("Hello world");
debug("Hello world"); dirxml("Hello world");
info("Hello world"); debug("Hello world");
warn("Hello world"); info("Hello world");
error("Hello world"); warn("Hello world");
consoleAssert(true); error("Hello world");
consoleCount("Hello world"); consoleAssert(true);
consoleCountReset("Hello world"); consoleCount("Hello world");
consoleTable({ test: "Hello world" }); consoleCountReset("Hello world");
consoleTime("Hello world"); consoleTable({ test: "Hello world" });
consoleTimeLog("Hello world"); consoleTime("Hello world");
consoleTimeEnd("Hello world"); consoleTimeLog("Hello world");
consoleGroup("Hello world"); consoleTimeEnd("Hello world");
consoleGroupEnd(); consoleGroup("Hello world");
consoleClear(); consoleGroupEnd();
consoleClear();
});
}); });
class StringBuffer { class StringBuffer {
@ -652,14 +654,16 @@ test(function consoleTable(): void {
// console.log(Error) test // console.log(Error) test
test(function consoleLogShouldNotThrowError(): void { test(function consoleLogShouldNotThrowError(): void {
let result = 0; mockConsole(console => {
try { let result = 0;
console.log(new Error("foo")); try {
result = 1; console.log(new Error("foo"));
} catch (e) { result = 1;
result = 2; } catch (e) {
} result = 2;
assertEquals(result, 1); }
assertEquals(result, 1);
});
// output errors to the console should not include "Uncaught" // output errors to the console should not include "Uncaught"
mockConsole((console, out): void => { mockConsole((console, out): void => {

View file

@ -30,7 +30,7 @@ testPerm({ write: true }, function dirCwdError(): void {
throw Error("current directory removed, should throw error"); throw Error("current directory removed, should throw error");
} catch (err) { } catch (err) {
if (err instanceof Deno.errors.NotFound) { if (err instanceof Deno.errors.NotFound) {
console.log(err.name === "NotFound"); assert(err.name === "NotFound");
} else { } else {
throw Error("raised different exception"); throw Error("raised different exception");
} }
@ -46,7 +46,7 @@ testPerm({ write: true }, function dirChdirError(): void {
throw Error("directory not available, should throw error"); throw Error("directory not available, should throw error");
} catch (err) { } catch (err) {
if (err instanceof Deno.errors.NotFound) { if (err instanceof Deno.errors.NotFound) {
console.log(err.name === "NotFound"); assert(err.name === "NotFound");
} else { } else {
throw Error("raised different exception"); throw Error("raised different exception");
} }

View file

@ -19,7 +19,6 @@ async function getTwoEvents(
): Promise<Deno.FsEvent[]> { ): Promise<Deno.FsEvent[]> {
const events = []; const events = [];
for await (const event of iter) { for await (const event of iter) {
console.log(">>>> event", event);
events.push(event); events.push(event);
if (events.length > 2) break; if (events.length > 2) break;
} }
@ -43,7 +42,6 @@ testPerm({ read: true, write: true }, async function fsEventsBasic(): Promise<
// We should have gotten two fs events. // We should have gotten two fs events.
const events = await eventsPromise; const events = await eventsPromise;
console.log("events", events);
assert(events.length >= 2); assert(events.length >= 2);
assert(events[0].kind == "create"); assert(events[0].kind == "create");
assert(events[0].paths[0].includes(testDir)); assert(events[0].paths[0].includes(testDir));

View file

@ -3,6 +3,5 @@ import { test, assert } from "./test_util.ts";
test(function locationBasic(): void { test(function locationBasic(): void {
// location example: file:///Users/rld/src/deno/js/unit_tests.ts // location example: file:///Users/rld/src/deno/js/unit_tests.ts
console.log("location", window.location.toString());
assert(window.location.toString().endsWith("unit_tests.ts")); assert(window.location.toString().endsWith("unit_tests.ts"));
}); });

View file

@ -13,7 +13,7 @@ test(async function metrics(): Promise<void> {
// Write to stdout to ensure a "data" message gets sent instead of just // Write to stdout to ensure a "data" message gets sent instead of just
// control messages. // control messages.
const dataMsg = new Uint8Array([41, 42, 43]); const dataMsg = new Uint8Array([13, 13, 13]); // "\r\r\r",
await Deno.stdout.write(dataMsg); await Deno.stdout.write(dataMsg);
const m2 = Deno.metrics(); const m2 = Deno.metrics();

View file

@ -112,7 +112,6 @@ if (Deno.build.os === "win") {
} }
test(function osPid(): void { test(function osPid(): void {
console.log("pid", Deno.pid);
assert(Deno.pid > 0); assert(Deno.pid > 0);
}); });

View file

@ -21,13 +21,15 @@ test(function runPermissions(): void {
testPerm({ run: true }, async function runSuccess(): Promise<void> { testPerm({ run: true }, async function runSuccess(): Promise<void> {
const p = run({ const p = run({
args: ["python", "-c", "print('hello world')"] args: ["python", "-c", "print('hello world')"],
stdout: "piped",
stderr: "null"
}); });
const status = await p.status(); const status = await p.status();
console.log("status", status);
assertEquals(status.success, true); assertEquals(status.success, true);
assertEquals(status.code, 0); assertEquals(status.code, 0);
assertEquals(status.signal, undefined); assertEquals(status.signal, undefined);
p.stdout!.close();
p.close(); p.close();
}); });

View file

@ -297,7 +297,6 @@ test(async function timerMaxCpuBug(): Promise<void> {
const { opsDispatched } = Deno.metrics(); const { opsDispatched } = Deno.metrics();
await waitForMs(100); await waitForMs(100);
const opsDispatched_ = Deno.metrics().opsDispatched; const opsDispatched_ = Deno.metrics().opsDispatched;
console.log("opsDispatched", opsDispatched, "opsDispatched_", opsDispatched_);
assert(opsDispatched_ - opsDispatched < 10); assert(opsDispatched_ - opsDispatched < 10);
}); });