1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

test: Fix broken test and remove redundant test file (#4390)

This commit is contained in:
Chris Knight 2020-03-16 11:40:36 +00:00 committed by GitHub
parent 1edb20b399
commit 62942749e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 114 deletions

View file

@ -1,113 +0,0 @@
const { test } = Deno;
import { readFile, readFileSync, readlink, readlinkSync } from "./fs.ts";
import * as path from "../path/mod.ts";
import { assertEquals, assert } from "../testing/asserts.ts";
const testData = path.resolve(path.join("node", "testdata", "hello.txt"));
const testDir = Deno.makeTempDirSync();
const oldname = testDir + "/oldname";
const newname = testDir + "/newname";
// Need to convert to promises, otherwise test() won't report error correctly.
test(async function readFileSuccess() {
const data = await new Promise((res, rej) => {
readFile(testData, (err, data) => {
if (err) {
rej(err);
}
res(data);
});
});
assert(data instanceof Uint8Array);
assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world");
});
test(async function readFileEncodeUtf8Success() {
const data = await new Promise((res, rej) => {
readFile(testData, { encoding: "utf8" }, (err, data) => {
if (err) {
rej(err);
}
res(data);
});
});
assertEquals(typeof data, "string");
assertEquals(data as string, "hello world");
});
test(function readFileSyncSuccess() {
const data = readFileSync(testData);
assert(data instanceof Uint8Array);
assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world");
});
test(function readFileEncodeUtf8Success() {
const data = readFileSync(testData, { encoding: "utf8" });
assertEquals(typeof data, "string");
assertEquals(data as string, "hello world");
});
// Just for now, until we implement symlink for Windows.
const skip = Deno.build.os == "win";
if (!skip) {
Deno.symlinkSync(oldname, newname);
}
test({
skip,
name: "readlinkSuccess",
async fn() {
const data = await new Promise((res, rej) => {
readlink(newname, (err, data) => {
if (err) {
rej(err);
}
res(data);
});
});
assertEquals(typeof data, "string");
assertEquals(data as string, oldname);
}
});
test({
skip,
name: "readlinkEncodeBufferSuccess",
async fn() {
const data = await new Promise((res, rej) => {
readlink(newname, { encoding: "buffer" }, (err, data) => {
if (err) {
rej(err);
}
res(data);
});
});
assert(data instanceof Uint8Array);
assertEquals(new TextDecoder().decode(data as Uint8Array), oldname);
}
});
test({
skip,
name: "readlinkSyncSuccess",
fn() {
const data = readlinkSync(newname);
assertEquals(typeof data, "string");
assertEquals(data as string, oldname);
}
});
test({
skip,
name: "readlinkEncodeBufferSuccess",
fn() {
const data = readlinkSync(newname, { encoding: "buffer" });
assert(data instanceof Uint8Array);
assertEquals(new TextDecoder().decode(data as Uint8Array), oldname);
}
});

View file

@ -31,7 +31,7 @@ test(function requireBuiltin() {
assert("readFileSync" in fs);
const { readFileSync, isNull, extname } = require_("./tests/cjs/cjs_builtin");
assertEquals(
readFileSync("./node/testdata/hello.txt", { encoding: "utf8" }),
readFileSync("./node/_fs/testdata/hello.txt", { encoding: "utf8" }),
"hello world"
);
assert(isNull(null));