0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-04 01:44:26 -05:00

reduce unnecessary output on tests (#4148)

This commit is contained in:
Yusuke Sakurai 2020-02-28 05:12:04 +09:00 committed by GitHub
parent fa5f3aa600
commit c65d0c63e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 187 additions and 191 deletions

View file

@ -1,4 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { bgBlue, red, bold, italic } from "../fmt/colors.ts"; import { bgBlue, red, bold, italic } from "../fmt/colors.ts";
if (import.meta.main) {
console.log(bgBlue(italic(red(bold("Hello world!"))))); console.log(bgBlue(italic(red(bold("Hello world!")))));
}

View file

@ -125,23 +125,12 @@ Deno.test(function emptyDirSyncIfItExist(): void {
} }
}); });
Deno.test(async function emptyDirPermission(): Promise<void> {
interface Scenes { interface Scenes {
read: boolean; // --allow-read read: boolean; // --allow-read
write: boolean; // --allow-write write: boolean; // --allow-write
async: boolean; async: boolean;
output: string; output: string;
} }
const testfolder = path.join(testdataDir, "testfolder");
await Deno.mkdir(testfolder);
await Deno.writeFile(
path.join(testfolder, "child.txt"),
new TextEncoder().encode("hello world")
);
const scenes: Scenes[] = [ const scenes: Scenes[] = [
// 1 // 1
{ {
@ -196,15 +185,24 @@ Deno.test(async function emptyDirPermission(): Promise<void> {
output: "success" output: "success"
} }
]; ];
for (const s of scenes) {
let title = `test ${s.async ? "emptyDir" : "emptyDirSync"}`;
title += `("testdata/testfolder") ${s.read ? "with" : "without"}`;
title += ` --allow-read & ${s.write ? "with" : "without"} --allow-write`;
Deno.test(`[fs] emptyDirPermission ${title}`, async function(): Promise<
void
> {
const testfolder = path.join(testdataDir, "testfolder");
try { try {
for (const s of scenes) { await Deno.mkdir(testfolder);
console.log(
`test ${s.async ? "emptyDir" : "emptyDirSync"}("testdata/testfolder") ${ await Deno.writeFile(
s.read ? "with" : "without" path.join(testfolder, "child.txt"),
} --allow-read & ${s.write ? "with" : "without"} --allow-write` new TextEncoder().encode("hello world")
); );
try {
const args = [Deno.execPath(), "run"]; const args = [Deno.execPath(), "run"];
if (s.read) { if (s.read) {
@ -231,13 +229,15 @@ Deno.test(async function emptyDirPermission(): Promise<void> {
const output = await Deno.readAll(stdout); const output = await Deno.readAll(stdout);
assertStrContains(new TextDecoder().decode(output), s.output); assertStrContains(new TextDecoder().decode(output), s.output);
}
} catch (err) { } catch (err) {
await Deno.remove(testfolder, { recursive: true }); await Deno.remove(testfolder, { recursive: true });
throw err; throw err;
} }
} finally {
// Make the test rerunnable // Make the test rerunnable
// Otherwise would throw error due to mkdir fail. // Otherwise would throw error due to mkdir fail.
await Deno.remove(testfolder, { recursive: true }); await Deno.remove(testfolder, { recursive: true });
// done // done
}
}); });
}

View file

@ -5,7 +5,7 @@ import { exists, existsSync } from "./exists.ts";
const testdataDir = path.resolve("fs", "testdata"); const testdataDir = path.resolve("fs", "testdata");
Deno.test(async function existsFile(): Promise<void> { Deno.test("[fs] existsFile", async function(): Promise<void> {
assertEquals( assertEquals(
await exists(path.join(testdataDir, "not_exist_file.ts")), await exists(path.join(testdataDir, "not_exist_file.ts")),
false false
@ -13,12 +13,12 @@ Deno.test(async function existsFile(): Promise<void> {
assertEquals(await existsSync(path.join(testdataDir, "0.ts")), true); assertEquals(await existsSync(path.join(testdataDir, "0.ts")), true);
}); });
Deno.test(function existsFileSync(): void { Deno.test("[fs] existsFileSync", function(): void {
assertEquals(existsSync(path.join(testdataDir, "not_exist_file.ts")), false); assertEquals(existsSync(path.join(testdataDir, "not_exist_file.ts")), false);
assertEquals(existsSync(path.join(testdataDir, "0.ts")), true); assertEquals(existsSync(path.join(testdataDir, "0.ts")), true);
}); });
Deno.test(async function existsDirectory(): Promise<void> { Deno.test("[fs] existsDirectory", async function(): Promise<void> {
assertEquals( assertEquals(
await exists(path.join(testdataDir, "not_exist_directory")), await exists(path.join(testdataDir, "not_exist_directory")),
false false
@ -26,7 +26,7 @@ Deno.test(async function existsDirectory(): Promise<void> {
assertEquals(existsSync(testdataDir), true); assertEquals(existsSync(testdataDir), true);
}); });
Deno.test(function existsDirectorySync(): void { Deno.test("[fs] existsDirectorySync", function(): void {
assertEquals( assertEquals(
existsSync(path.join(testdataDir, "not_exist_directory")), existsSync(path.join(testdataDir, "not_exist_directory")),
false false
@ -34,19 +34,18 @@ Deno.test(function existsDirectorySync(): void {
assertEquals(existsSync(testdataDir), true); assertEquals(existsSync(testdataDir), true);
}); });
Deno.test(function existsLinkSync(): void { Deno.test("[fs] existsLinkSync", function(): void {
// TODO(axetroy): generate link file use Deno api instead of set a link file // TODO(axetroy): generate link file use Deno api instead of set a link file
// in repository // in repository
assertEquals(existsSync(path.join(testdataDir, "0-link.ts")), true); assertEquals(existsSync(path.join(testdataDir, "0-link.ts")), true);
}); });
Deno.test(async function existsLink(): Promise<void> { Deno.test("[fs] existsLink", async function(): Promise<void> {
// TODO(axetroy): generate link file use Deno api instead of set a link file // TODO(axetroy): generate link file use Deno api instead of set a link file
// in repository // in repository
assertEquals(await exists(path.join(testdataDir, "0-link.ts")), true); assertEquals(await exists(path.join(testdataDir, "0-link.ts")), true);
}); });
Deno.test(async function existsPermission(): Promise<void> {
interface Scenes { interface Scenes {
read: boolean; // --allow-read read: boolean; // --allow-read
async: boolean; async: boolean;
@ -110,12 +109,9 @@ Deno.test(async function existsPermission(): Promise<void> {
]; ];
for (const s of scenes) { for (const s of scenes) {
console.log( let title = `test ${s.async ? "exists" : "existsSync"}("testdata/${s.file}")`;
`test ${s.async ? "exists" : "existsSync"}("testdata/${s.file}") ${ title += ` ${s.read ? "with" : "without"} --allow-read`;
s.read ? "with" : "without" Deno.test(`[fs] existsPermission ${title}`, async function(): Promise<void> {
} --allow-read`
);
const args = [Deno.execPath(), "run"]; const args = [Deno.execPath(), "run"];
if (s.read) { if (s.read) {
@ -134,7 +130,6 @@ Deno.test(async function existsPermission(): Promise<void> {
const output = await Deno.readAll(stdout!); const output = await Deno.readAll(stdout!);
assertStrContains(new TextDecoder().decode(output), s.output); assertStrContains(new TextDecoder().decode(output), s.output);
}
// done
}); });
// done
}

View file

@ -16,7 +16,8 @@ async function startFileServer(): Promise<void> {
".", ".",
"--cors" "--cors"
], ],
stdout: "piped" stdout: "piped",
stderr: "null"
}); });
// Once fileServer is ready it will write to its stdout. // Once fileServer is ready it will write to its stdout.
assert(fileServer.stdout != null); assert(fileServer.stdout != null);

View file

@ -4,7 +4,7 @@ import { assert, assertEquals } from "../testing/asserts.ts";
import * as path from "../path/mod.ts"; import * as path from "../path/mod.ts";
import { copyBytes, tempFile } from "./util.ts"; import { copyBytes, tempFile } from "./util.ts";
test(function testCopyBytes(): void { test("[io/tuil] copyBytes", function(): void {
const dst = new Uint8Array(4); const dst = new Uint8Array(4);
dst.fill(0); dst.fill(0);
@ -38,12 +38,11 @@ test(function testCopyBytes(): void {
assertEquals(dst, Uint8Array.of(3, 4, 0, 0)); assertEquals(dst, Uint8Array.of(3, 4, 0, 0));
}); });
test(async function ioTempfile(): Promise<void> { test("[io/util] tempfile", async function(): Promise<void> {
const f = await tempFile(".", { const f = await tempFile(".", {
prefix: "prefix-", prefix: "prefix-",
postfix: "-postfix" postfix: "-postfix"
}); });
console.log(f.file, f.filepath);
const base = path.basename(f.filepath); const base = path.basename(f.filepath);
assert(!!base.match(/^prefix-.+?-postfix$/)); assert(!!base.match(/^prefix-.+?-postfix$/));
await remove(f.filepath); await remove(f.filepath);

View file

@ -11,6 +11,5 @@ test({
const u = "582cbcff-dad6-4f28-888a-e062ae36bafc"; const u = "582cbcff-dad6-4f28-888a-e062ae36bafc";
assert(isNil(nil)); assert(isNil(nil));
assert(!isNil(u)); assert(!isNil(u));
console.log("");
} }
}); });