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,8 +37,8 @@ test(function consoleHasRightInstance(): void {
}); });
test(function consoleTestAssertShouldNotThrowError(): void { test(function consoleTestAssertShouldNotThrowError(): void {
mockConsole(console => {
console.assert(true); console.assert(true);
let hasThrown = undefined; let hasThrown = undefined;
try { try {
console.assert(false); console.assert(false);
@ -48,6 +48,7 @@ test(function consoleTestAssertShouldNotThrowError(): void {
} }
assertEquals(hasThrown, false); assertEquals(hasThrown, false);
}); });
});
test(function consoleTestStringifyComplexObjects(): void { test(function consoleTestStringifyComplexObjects(): void {
assertEquals(stringify("foo"), "foo"); assertEquals(stringify("foo"), "foo");
@ -302,20 +303,19 @@ 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 {
class MyError extends Error { class MyError extends Error {
@ -355,6 +355,7 @@ test(function consoleTestClear(): void {
// Test bound this issue // Test bound this issue
test(function consoleDetachedLog(): void { test(function consoleDetachedLog(): void {
mockConsole(console => {
const log = console.log; const log = console.log;
const dir = console.dir; const dir = console.dir;
const dirxml = console.dirxml; const dirxml = console.dirxml;
@ -390,6 +391,7 @@ test(function consoleDetachedLog(): void {
consoleGroupEnd(); consoleGroupEnd();
consoleClear(); consoleClear();
}); });
});
class StringBuffer { class StringBuffer {
chunks: string[] = []; chunks: string[] = [];
@ -652,6 +654,7 @@ test(function consoleTable(): void {
// console.log(Error) test // console.log(Error) test
test(function consoleLogShouldNotThrowError(): void { test(function consoleLogShouldNotThrowError(): void {
mockConsole(console => {
let result = 0; let result = 0;
try { try {
console.log(new Error("foo")); console.log(new Error("foo"));
@ -660,6 +663,7 @@ test(function consoleLogShouldNotThrowError(): void {
result = 2; 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);
}); });