summaryrefslogtreecommitdiff
path: root/std/node
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-06-12 20:23:38 +0100
committerGitHub <noreply@github.com>2020-06-12 15:23:38 -0400
commit1fff6f55c3ba98a10018c6d374795e612061e9b6 (patch)
tree12074b6d44736b11513d857e437f9e30a6bf65a4 /std/node
parent26bf56afdaf16634ffbaa23684faf3a44cc10f62 (diff)
refactor: Don't destructure the Deno namespace (#6268)
Diffstat (limited to 'std/node')
-rw-r--r--std/node/_fs/_fs_appendFile_test.ts19
-rw-r--r--std/node/_fs/_fs_chmod_test.ts5
-rw-r--r--std/node/_fs/_fs_chown_test.ts5
-rw-r--r--std/node/_fs/_fs_close_test.ts11
-rw-r--r--std/node/_fs/_fs_copy_test.ts8
-rw-r--r--std/node/_fs/_fs_dir_test.ts17
-rw-r--r--std/node/_fs/_fs_dirent_test.ts11
-rw-r--r--std/node/_fs/_fs_exists_test.ts7
-rw-r--r--std/node/_fs/_fs_link_test.ts8
-rw-r--r--std/node/_fs/_fs_mkdir_test.ts7
-rw-r--r--std/node/_fs/_fs_readFile.ts8
-rw-r--r--std/node/_fs/_fs_readFile_test.ts13
-rw-r--r--std/node/_fs/_fs_readlink.ts6
-rw-r--r--std/node/_fs/_fs_readlink_test.ts9
-rw-r--r--std/node/_fs/_fs_writeFile_test.ts271
-rw-r--r--std/node/_fs/promises/_fs_readFile_test.ts9
-rw-r--r--std/node/_fs/promises/_fs_writeFile_test.ts146
-rw-r--r--std/node/_util/_util_callbackify_test.ts334
-rw-r--r--std/node/_util/_util_promisify_test.ts141
-rw-r--r--std/node/_util/_util_types_test.ts156
-rw-r--r--std/node/events_test.ts61
-rw-r--r--std/node/module_test.ts14
-rw-r--r--std/node/os_test.ts33
-rw-r--r--std/node/process.ts32
-rw-r--r--std/node/process_test.ts19
-rw-r--r--std/node/querystring_test.ts5
-rw-r--r--std/node/util_test.ts33
27 files changed, 705 insertions, 683 deletions
diff --git a/std/node/_fs/_fs_appendFile_test.ts b/std/node/_fs/_fs_appendFile_test.ts
index 402ac1c10..1286ff900 100644
--- a/std/node/_fs/_fs_appendFile_test.ts
+++ b/std/node/_fs/_fs_appendFile_test.ts
@@ -1,12 +1,11 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { test } = Deno;
import { assertEquals, assertThrows, fail } from "../../testing/asserts.ts";
import { appendFile, appendFileSync } from "./_fs_appendFile.ts";
import { fromFileUrl } from "../path.ts";
const decoder = new TextDecoder("utf-8");
-test({
+Deno.test({
name: "No callback Fn results in Error",
fn() {
assertThrows(
@@ -19,7 +18,7 @@ test({
},
});
-test({
+Deno.test({
name: "Unsupported encoding results in error()",
fn() {
assertThrows(
@@ -57,7 +56,7 @@ test({
},
});
-test({
+Deno.test({
name: "Async: Data is written to passed in rid",
async fn() {
const tempFile: string = await Deno.makeTempFile();
@@ -86,7 +85,7 @@ test({
},
});
-test({
+Deno.test({
name: "Async: Data is written to passed in file path",
async fn() {
const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources();
@@ -110,7 +109,7 @@ test({
},
});
-test({
+Deno.test({
name: "Async: Data is written to passed in URL",
async fn() {
const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources();
@@ -135,7 +134,7 @@ test({
},
});
-test({
+Deno.test({
name:
"Async: Callback is made with error if attempting to append data to an existing file with 'ax' flag",
async fn() {
@@ -159,7 +158,7 @@ test({
},
});
-test({
+Deno.test({
name: "Sync: Data is written to passed in rid",
fn() {
const tempFile: string = Deno.makeTempFileSync();
@@ -176,7 +175,7 @@ test({
},
});
-test({
+Deno.test({
name: "Sync: Data is written to passed in file path",
fn() {
const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources();
@@ -188,7 +187,7 @@ test({
},
});
-test({
+Deno.test({
name:
"Sync: error thrown if attempting to append data to an existing file with 'ax' flag",
fn() {
diff --git a/std/node/_fs/_fs_chmod_test.ts b/std/node/_fs/_fs_chmod_test.ts
index e43f09788..de4981a8c 100644
--- a/std/node/_fs/_fs_chmod_test.ts
+++ b/std/node/_fs/_fs_chmod_test.ts
@@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { test } = Deno;
import { fail, assert } from "../../testing/asserts.ts";
import { chmod, chmodSync } from "./_fs_chmod.ts";
-test({
+Deno.test({
name: "ASYNC: Permissions are changed (non-Windows)",
ignore: Deno.build.os === "windows",
async fn() {
@@ -29,7 +28,7 @@ test({
},
});
-test({
+Deno.test({
name: "SYNC: Permissions are changed (non-Windows)",
ignore: Deno.build.os === "windows",
fn() {
diff --git a/std/node/_fs/_fs_chown_test.ts b/std/node/_fs/_fs_chown_test.ts
index 1c1393ac4..de7dd992f 100644
--- a/std/node/_fs/_fs_chown_test.ts
+++ b/std/node/_fs/_fs_chown_test.ts
@@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { test } = Deno;
import { fail, assertEquals } from "../../testing/asserts.ts";
import { chown, chownSync } from "./_fs_chown.ts";
@@ -7,7 +6,7 @@ import { chown, chownSync } from "./_fs_chown.ts";
// id again
const ignore = Deno.build.os == "windows";
-test({
+Deno.test({
ignore,
name: "ASYNC: setting existing uid/gid works as expected (non-Windows)",
async fn() {
@@ -35,7 +34,7 @@ test({
},
});
-test({
+Deno.test({
ignore,
name: "SYNC: setting existing uid/gid works as expected (non-Windows)",
fn() {
diff --git a/std/node/_fs/_fs_close_test.ts b/std/node/_fs/_fs_close_test.ts
index 1ea324cb4..feaf92ab8 100644
--- a/std/node/_fs/_fs_close_test.ts
+++ b/std/node/_fs/_fs_close_test.ts
@@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { test } = Deno;
import { fail, assert, assertThrows } from "../../testing/asserts.ts";
import { close, closeSync } from "./_fs_close.ts";
-test({
+Deno.test({
name: "ASYNC: File is closed",
async fn() {
const tempFile: string = await Deno.makeTempFile();
@@ -28,7 +27,7 @@ test({
},
});
-test({
+Deno.test({
name: "ASYNC: Invalid fd",
async fn() {
await new Promise((resolve, reject) => {
@@ -40,7 +39,7 @@ test({
},
});
-test({
+Deno.test({
name: "close callback should be asynchronous",
async fn() {
const tempFile: string = Deno.makeTempFileSync();
@@ -60,7 +59,7 @@ test({
},
});
-test({
+Deno.test({
name: "SYNC: File is closed",
fn() {
const tempFile: string = Deno.makeTempFileSync();
@@ -73,7 +72,7 @@ test({
},
});
-test({
+Deno.test({
name: "SYNC: Invalid fd",
fn() {
assertThrows(() => closeSync(-1));
diff --git a/std/node/_fs/_fs_copy_test.ts b/std/node/_fs/_fs_copy_test.ts
index f7ce0e279..891e80784 100644
--- a/std/node/_fs/_fs_copy_test.ts
+++ b/std/node/_fs/_fs_copy_test.ts
@@ -1,13 +1,11 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import { assert } from "../../testing/asserts.ts";
import { copyFile, copyFileSync } from "./_fs_copy.ts";
import { existsSync } from "./_fs_exists.ts";
-import { assert } from "../../testing/asserts.ts";
-const { test } = Deno;
-
const destFile = "./destination.txt";
-test({
+Deno.test({
name: "[std/node/fs] copy file",
fn: async () => {
const sourceFile = Deno.makeTempFileSync();
@@ -21,7 +19,7 @@ test({
},
});
-test({
+Deno.test({
name: "[std/node/fs] copy file sync",
fn: () => {
const sourceFile = Deno.makeTempFileSync();
diff --git a/std/node/_fs/_fs_dir_test.ts b/std/node/_fs/_fs_dir_test.ts
index 5b3336201..e89912772 100644
--- a/std/node/_fs/_fs_dir_test.ts
+++ b/std/node/_fs/_fs_dir_test.ts
@@ -1,9 +1,8 @@
-const { test } = Deno;
import { assert, assertEquals, fail } from "../../testing/asserts.ts";
import Dir from "./_fs_dir.ts";
import Dirent from "./_fs_dirent.ts";
-test({
+Deno.test({
name: "Closing current directory with callback is successful",
fn() {
let calledBack = false;
@@ -16,21 +15,21 @@ test({
},
});
-test({
+Deno.test({
name: "Closing current directory without callback returns void Promise",
async fn() {
await new Dir(".").close();
},
});
-test({
+Deno.test({
name: "Closing current directory synchronously works",
fn() {
new Dir(".").closeSync();
},
});
-test({
+Deno.test({
name: "Path is correctly returned",
fn() {
assertEquals(new Dir("std/node").path, "std/node");
@@ -40,7 +39,7 @@ test({
},
});
-test({
+Deno.test({
name: "read returns null for empty directory",
async fn() {
const testDir: string = Deno.makeTempDirSync();
@@ -67,7 +66,7 @@ test({
},
});
-test({
+Deno.test({
name: "Async read returns one file at a time",
async fn() {
const testDir: string = Deno.makeTempDirSync();
@@ -108,7 +107,7 @@ test({
},
});
-test({
+Deno.test({
name: "Sync read returns one file at a time",
fn() {
const testDir: string = Deno.makeTempDirSync();
@@ -139,7 +138,7 @@ test({
},
});
-test({
+Deno.test({
name: "Async iteration over existing directory",
async fn() {
const testDir: string = Deno.makeTempDirSync();
diff --git a/std/node/_fs/_fs_dirent_test.ts b/std/node/_fs/_fs_dirent_test.ts
index 43becedd1..8c4b98214 100644
--- a/std/node/_fs/_fs_dirent_test.ts
+++ b/std/node/_fs/_fs_dirent_test.ts
@@ -1,4 +1,3 @@
-const { test } = Deno;
import { assert, assertEquals, assertThrows } from "../../testing/asserts.ts";
import Dirent from "./_fs_dirent.ts";
@@ -9,7 +8,7 @@ class DirEntryMock implements Deno.DirEntry {
isSymlink = false;
}
-test({
+Deno.test({
name: "Directories are correctly identified",
fn() {
const entry: DirEntryMock = new DirEntryMock();
@@ -22,7 +21,7 @@ test({
},
});
-test({
+Deno.test({
name: "Files are correctly identified",
fn() {
const entry: DirEntryMock = new DirEntryMock();
@@ -35,7 +34,7 @@ test({
},
});
-test({
+Deno.test({
name: "Symlinks are correctly identified",
fn() {
const entry: DirEntryMock = new DirEntryMock();
@@ -48,7 +47,7 @@ test({
},
});
-test({
+Deno.test({
name: "File name is correct",
fn() {
const entry: DirEntryMock = new DirEntryMock();
@@ -57,7 +56,7 @@ test({
},
});
-test({
+Deno.test({
name: "Socket and FIFO pipes aren't yet available",
fn() {
const entry: DirEntryMock = new DirEntryMock();
diff --git a/std/node/_fs/_fs_exists_test.ts b/std/node/_fs/_fs_exists_test.ts
index b4885c87f..d7d2f7f29 100644
--- a/std/node/_fs/_fs_exists_test.ts
+++ b/std/node/_fs/_fs_exists_test.ts
@@ -1,11 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
import { assertEquals } from "../../testing/asserts.ts";
import { exists, existsSync } from "./_fs_exists.ts";
-const { test } = Deno;
-
-test("existsFile", async function () {
+Deno.test("existsFile", async function () {
const availableFile = await new Promise((resolve) => {
const tmpFilePath = Deno.makeTempFileSync();
exists(tmpFilePath, (exists: boolean) => {
@@ -20,7 +17,7 @@ test("existsFile", async function () {
assertEquals(notAvailableFile, false);
});
-test("existsSyncFile", function () {
+Deno.test("existsSyncFile", function () {
const tmpFilePath = Deno.makeTempFileSync();
assertEquals(existsSync(tmpFilePath), true);
Deno.removeSync(tmpFilePath);
diff --git a/std/node/_fs/_fs_link_test.ts b/std/node/_fs/_fs_link_test.ts
index e59984c8c..0251e55fb 100644
--- a/std/node/_fs/_fs_link_test.ts
+++ b/std/node/_fs/_fs_link_test.ts
@@ -1,11 +1,11 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { test } = Deno;
import { fail, assertEquals } from "../../testing/asserts.ts";
import { link, linkSync } from "./_fs_link.ts";
import { assert } from "https://deno.land/std@v0.50.0/testing/asserts.ts";
+
const isWindows = Deno.build.os === "windows";
-test({
+Deno.test({
ignore: isWindows,
name: "ASYNC: hard linking files works as expected",
async fn() {
@@ -30,7 +30,7 @@ test({
},
});
-test({
+Deno.test({
ignore: isWindows,
name: "ASYNC: hard linking files passes error to callback",
async fn() {
@@ -52,7 +52,7 @@ test({
},
});
-test({
+Deno.test({
ignore: isWindows,
name: "SYNC: hard linking files works as expected",
fn() {
diff --git a/std/node/_fs/_fs_mkdir_test.ts b/std/node/_fs/_fs_mkdir_test.ts
index 7e9d4859f..8909d85de 100644
--- a/std/node/_fs/_fs_mkdir_test.ts
+++ b/std/node/_fs/_fs_mkdir_test.ts
@@ -1,14 +1,11 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
import { assert } from "../../testing/asserts.ts";
import { mkdir, mkdirSync } from "./_fs_mkdir.ts";
import { existsSync } from "./_fs_exists.ts";
-const { test } = Deno;
-
const tmpDir = "./tmpdir";
-test({
+Deno.test({
name: "[node/fs] mkdir",
fn: async () => {
const result = await new Promise((resolve) => {
@@ -22,7 +19,7 @@ test({
},
});
-test({
+Deno.test({
name: "[node/fs] mkdirSync",
fn: () => {
mkdirSync(tmpDir);
diff --git a/std/node/_fs/_fs_readFile.ts b/std/node/_fs/_fs_readFile.ts
index 448045fd2..d4093ff7f 100644
--- a/std/node/_fs/_fs_readFile.ts
+++ b/std/node/_fs/_fs_readFile.ts
@@ -1,13 +1,9 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
import { intoCallbackAPIWithIntercept, MaybeEmpty } from "../_utils.ts";
-
import { getEncoding, FileOptions } from "./_fs_common.ts";
import { Buffer } from "../buffer.ts";
import { fromFileUrl } from "../path.ts";
-const { readFile: denoReadFile, readFileSync: denoReadFileSync } = Deno;
-
type ReadFileCallback = (
err: MaybeEmpty<Error>,
data: MaybeEmpty<string | Buffer>
@@ -38,7 +34,7 @@ export function readFile(
const encoding = getEncoding(optOrCallback);
intoCallbackAPIWithIntercept<Uint8Array, string | Buffer>(
- denoReadFile,
+ Deno.readFile,
(data: Uint8Array): string | Buffer => maybeDecode(data, encoding),
cb,
path
@@ -50,5 +46,5 @@ export function readFileSync(
opt?: FileOptions | string
): string | Buffer {
path = path instanceof URL ? fromFileUrl(path) : path;
- return maybeDecode(denoReadFileSync(path), getEncoding(opt));
+ return maybeDecode(Deno.readFileSync(path), getEncoding(opt));
}
diff --git a/std/node/_fs/_fs_readFile_test.ts b/std/node/_fs/_fs_readFile_test.ts
index 1a850c91a..02e4c3745 100644
--- a/std/node/_fs/_fs_readFile_test.ts
+++ b/std/node/_fs/_fs_readFile_test.ts
@@ -1,4 +1,3 @@
-const { test } = Deno;
import { readFile, readFileSync } from "./_fs_readFile.ts";
import * as path from "../../path/mod.ts";
import { assertEquals, assert } from "../../testing/asserts.ts";
@@ -7,7 +6,7 @@ const testData = path.resolve(
path.join("node", "_fs", "testdata", "hello.txt")
);
-test("readFileSuccess", async function () {
+Deno.test("readFileSuccess", async function () {
const data = await new Promise((res, rej) => {
readFile(testData, (err, data) => {
if (err) {
@@ -21,7 +20,7 @@ test("readFileSuccess", async function () {
assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world");
});
-test("readFileEncodeUtf8Success", async function () {
+Deno.test("readFileEncodeUtf8Success", async function () {
const data = await new Promise((res, rej) => {
readFile(testData, { encoding: "utf8" }, (err, data) => {
if (err) {
@@ -35,7 +34,7 @@ test("readFileEncodeUtf8Success", async function () {
assertEquals(data as string, "hello world");
});
-test("readFileEncodingAsString", async function () {
+Deno.test("readFileEncodingAsString", async function () {
const data = await new Promise((res, rej) => {
readFile(testData, "utf8", (err, data) => {
if (err) {
@@ -49,19 +48,19 @@ test("readFileEncodingAsString", async function () {
assertEquals(data as string, "hello world");
});
-test("readFileSyncSuccess", function () {
+Deno.test("readFileSyncSuccess", function () {
const data = readFileSync(testData);
assert(data instanceof Uint8Array);
assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world");
});
-test("readFileEncodeUtf8Success", function () {
+Deno.test("readFileEncodeUtf8Success", function () {
const data = readFileSync(testData, { encoding: "utf8" });
assertEquals(typeof data, "string");
assertEquals(data as string, "hello world");
});
-test("readFileEncodeAsString", function () {
+Deno.test("readFileEncodeAsString", function () {
const data = readFileSync(testData, "utf8");
assertEquals(typeof data, "string");
assertEquals(data as string, "hello world");
diff --git a/std/node/_fs/_fs_readlink.ts b/std/node/_fs/_fs_readlink.ts
index d461cf390..11ce43f55 100644
--- a/std/node/_fs/_fs_readlink.ts
+++ b/std/node/_fs/_fs_readlink.ts
@@ -6,8 +6,6 @@ import {
} from "../_utils.ts";
import { fromFileUrl } from "../path.ts";
-const { readLink: denoReadlink, readLinkSync: denoReadlinkSync } = Deno;
-
type ReadlinkCallback = (
err: MaybeEmpty<Error>,
linkString: MaybeEmpty<string | Uint8Array>
@@ -66,7 +64,7 @@ export function readlink(
const encoding = getEncoding(optOrCallback);
intoCallbackAPIWithIntercept<string, Uint8Array | string>(
- denoReadlink,
+ Deno.readLink,
(data: string): string | Uint8Array => maybeEncode(data, encoding),
cb,
path
@@ -79,5 +77,5 @@ export function readlinkSync(
): string | Uint8Array {
path = path instanceof URL ? fromFileUrl(path) : path;
- return maybeEncode(denoReadlinkSync(path), getEncoding(opt));
+ return maybeEncode(Deno.readLinkSync(path), getEncoding(opt));
}
diff --git a/std/node/_fs/_fs_readlink_test.ts b/std/node/_fs/_fs_readlink_test.ts
index 77ce60a3f..437873494 100644
--- a/std/node/_fs/_fs_readlink_test.ts
+++ b/std/node/_fs/_fs_readlink_test.ts
@@ -1,4 +1,3 @@
-const { test } = Deno;
import { readlink, readlinkSync } from "./_fs_readlink.ts";
import { assertEquals, assert } from "../../testing/asserts.ts";
import * as path from "../path.ts";
@@ -13,7 +12,7 @@ if (Deno.build.os === "windows") {
Deno.symlinkSync(oldname, newname);
}
-test({
+Deno.test({
name: "readlinkSuccess",
async fn() {
const data = await new Promise((res, rej) => {
@@ -30,7 +29,7 @@ test({
},
});
-test({
+Deno.test({
name: "readlinkEncodeBufferSuccess",
async fn() {
const data = await new Promise((res, rej) => {
@@ -47,7 +46,7 @@ test({
},
});
-test({
+Deno.test({
name: "readlinkSyncSuccess",
fn() {
const data = readlinkSync(newname);
@@ -56,7 +55,7 @@ test({
},
});
-test({
+Deno.test({
name: "readlinkEncodeBufferSuccess",
fn() {
const data = readlinkSync(newname, { encoding: "buffer" });
diff --git a/std/node/_fs/_fs_writeFile_test.ts b/std/node/_fs/_fs_writeFile_test.ts
index 486c55fa1..81913d0b0 100644
--- a/std/node/_fs/_fs_writeFile_test.ts
+++ b/std/node/_fs/_fs_writeFile_test.ts
@@ -1,6 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { test } = Deno;
-
import {
assert,
assertEquals,
@@ -13,7 +11,7 @@ import * as path from "../../path/mod.ts";
const testDataDir = path.resolve(path.join("node", "_fs", "testdata"));
const decoder = new TextDecoder("utf-8");
-test("Callback must be a function error", function fn() {
+Deno.test("Callback must be a function error", function fn() {
assertThrows(
() => {
writeFile("some/path", "some data", "utf8");
@@ -23,7 +21,7 @@ test("Callback must be a function error", function fn() {
);
});
-test("Invalid encoding results in error()", function testEncodingErrors() {
+Deno.test("Invalid encoding results in error()", function testEncodingErrors() {
assertThrows(
() => {
writeFile("some/path", "some data", "made-up-encoding", () => {});
@@ -66,82 +64,91 @@ test("Invalid encoding results in error()", function testEncodingErrors() {
);
});
-test("Unsupported encoding results in error()", function testUnsupportedEncoding() {
- assertThrows(
- () => {
- writeFile("some/path", "some data", "hex", () => {});
- },
- Error,
- `Not implemented: "hex" encoding`
- );
-
- assertThrows(
- () => {
- writeFileSync("some/path", "some data", "hex");
- },
- Error,
- `Not implemented: "hex" encoding`
- );
-
- assertThrows(
- () => {
- writeFile(
- "some/path",
- "some data",
- {
+Deno.test(
+ "Unsupported encoding results in error()",
+ function testUnsupportedEncoding() {
+ assertThrows(
+ () => {
+ writeFile("some/path", "some data", "hex", () => {});
+ },
+ Error,
+ `Not implemented: "hex" encoding`
+ );
+
+ assertThrows(
+ () => {
+ writeFileSync("some/path", "some data", "hex");
+ },
+ Error,
+ `Not implemented: "hex" encoding`
+ );
+
+ assertThrows(
+ () => {
+ writeFile(
+ "some/path",
+ "some data",
+ {
+ encoding: "base64",
+ },
+ () => {}
+ );
+ },
+ Error,
+ `Not implemented: "base64" encoding`
+ );
+
+ assertThrows(
+ () => {
+ writeFileSync("some/path", "some data", {
encoding: "base64",
- },
- () => {}
- );
- },
- Error,
- `Not implemented: "base64" encoding`
- );
+ });
+ },
+ Error,
+ `Not implemented: "base64" encoding`
+ );
+ }
+);
+
+Deno.test(
+ "Data is written to correct rid",
+ async function testCorrectWriteUsingRid() {
+ const tempFile: string = await Deno.makeTempFile();
+ const file: Deno.File = await Deno.open(tempFile, {
+ create: true,
+ write: true,
+ read: true,
+ });
- assertThrows(
- () => {
- writeFileSync("some/path", "some data", {
- encoding: "base64",
+ await new Promise((resolve, reject) => {
+ writeFile(file.rid, "hello world", (err) => {
+ if (err) return reject(err);
+ resolve();
});
- },
- Error,
- `Not implemented: "base64" encoding`
- );
-});
-
-test("Data is written to correct rid", async function testCorrectWriteUsingRid() {
- const tempFile: string = await Deno.makeTempFile();
- const file: Deno.File = await Deno.open(tempFile, {
- create: true,
- write: true,
- read: true,
- });
-
- await new Promise((resolve, reject) => {
- writeFile(file.rid, "hello world", (err) => {
- if (err) return reject(err);
- resolve();
});
- });
- Deno.close(file.rid);
-
- const data = await Deno.readFile(tempFile);
- await Deno.remove(tempFile);
- assertEquals(decoder.decode(data), "hello world");
-});
-
-test("Data is written to correct file", async function testCorrectWriteUsingPath() {
- const res = await new Promise((resolve) => {
- writeFile("_fs_writeFile_test_file.txt", "hello world", resolve);
- });
+ Deno.close(file.rid);
+
+ const data = await Deno.readFile(tempFile);
+ await Deno.remove(tempFile);
+ assertEquals(decoder.decode(data), "hello world");
+ }
+);
+
+Deno.test(
+ "Data is written to correct file",
+ async function testCorrectWriteUsingPath() {
+ const res = await new Promise((resolve) => {
+ writeFile("_fs_writeFile_test_file.txt", "hello world", resolve);
+ });
- const data = await Deno.readFile("_fs_writeFile_test_file.txt");
- await Deno.remove("_fs_writeFile_test_file.txt");
- assertEquals(res, null);
- assertEquals(decoder.decode(data), "hello world");
-});
+ const data = await Deno.readFile("_fs_writeFile_test_file.txt");
+ await Deno.remove("_fs_writeFile_test_file.txt");
+ assertEquals(res, null);
+ assertEquals(decoder.decode(data), "hello world");
+ }
+);
-test("Path can be an URL", async function testCorrectWriteUsingURL() {
+Deno.test("Path can be an URL", async function testCorrectWriteUsingURL() {
const url = new URL(
Deno.build.os === "windows"
? "file:///" +
@@ -162,7 +169,7 @@ test("Path can be an URL", async function testCorrectWriteUsingURL() {
assertEquals(decoder.decode(data), "hello world");
});
-test("Mode is correctly set", async function testCorrectFileMode() {
+Deno.test("Mode is correctly set", async function testCorrectFileMode() {
if (Deno.build.os === "windows") return;
const filename = "_fs_writeFile_test_file.txt";
@@ -177,57 +184,66 @@ test("Mode is correctly set", async function testCorrectFileMode() {
assertEquals(fileInfo.mode & 0o777, 0o777);
});
-test("Mode is not set when rid is passed", async function testCorrectFileModeRid() {
- if (Deno.build.os === "windows") return;
-
- const filename: string = await Deno.makeTempFile();
- const file: Deno.File = await Deno.open(filename, {
- create: true,
- write: true,
- read: true,
- });
+Deno.test(
+ "Mode is not set when rid is passed",
+ async function testCorrectFileModeRid() {
+ if (Deno.build.os === "windows") return;
- await new Promise((resolve, reject) => {
- writeFile(file.rid, "hello world", { mode: 0o777 }, (err) => {
- if (err) return reject(err);
- resolve();
+ const filename: string = await Deno.makeTempFile();
+ const file: Deno.File = await Deno.open(filename, {
+ create: true,
+ write: true,
+ read: true,
});
- });
- Deno.close(file.rid);
- const fileInfo = await Deno.stat(filename);
- await Deno.remove(filename);
- assert(fileInfo.mode);
- assertNotEquals(fileInfo.mode & 0o777, 0o777);
-});
-
-test("Data is written synchronously to correct rid", function testCorrectWriteSyncUsingRid() {
- const tempFile: string = Deno.makeTempFileSync();
- const file: Deno.File = Deno.openSync(tempFile, {
- create: true,
- write: true,
- read: true,
- });
+ await new Promise((resolve, reject) => {
+ writeFile(file.rid, "hello world", { mode: 0o777 }, (err) => {
+ if (err) return reject(err);
+ resolve();
+ });
+ });
+ Deno.close(file.rid);
+
+ const fileInfo = await Deno.stat(filename);
+ await Deno.remove(filename);
+ assert(fileInfo.mode);
+ assertNotEquals(fileInfo.mode & 0o777, 0o777);
+ }
+);
+
+Deno.test(
+ "Data is written synchronously to correct rid",
+ function testCorrectWriteSyncUsingRid() {
+ const tempFile: string = Deno.makeTempFileSync();
+ const file: Deno.File = Deno.openSync(tempFile, {
+ create: true,
+ write: true,
+ read: true,
+ });
- writeFileSync(file.rid, "hello world");
- Deno.close(file.rid);
+ writeFileSync(file.rid, "hello world");
+ Deno.close(file.rid);
- const data = Deno.readFileSync(tempFile);
- Deno.removeSync(tempFile);
- assertEquals(decoder.decode(data), "hello world");
-});
+ const data = Deno.readFileSync(tempFile);
+ Deno.removeSync(tempFile);
+ assertEquals(decoder.decode(data), "hello world");
+ }
+);
-test("Data is written synchronously to correct file", function testCorrectWriteSyncUsingPath() {
- const file = "_fs_writeFileSync_test_file";
+Deno.test(
+ "Data is written synchronously to correct file",
+ function testCorrectWriteSyncUsingPath() {
+ const file = "_fs_writeFileSync_test_file";
- writeFileSync(file, "hello world");
+ writeFileSync(file, "hello world");
- const data = Deno.readFileSync(file);
- Deno.removeSync(file);
- assertEquals(decoder.decode(data), "hello world");
-});
+ const data = Deno.readFileSync(file);
+ Deno.removeSync(file);
+ assertEquals(decoder.decode(data), "hello world");
+ }
+);
-test("sync: Path can be an URL", function testCorrectWriteSyncUsingURL() {
+Deno.test("sync: Path can be an URL", function testCorrectWriteSyncUsingURL() {
const filePath = path.join(
testDataDir,
"_fs_writeFileSync_test_file_url.txt"
@@ -244,14 +260,17 @@ test("sync: Path can be an URL", function testCorrectWriteSyncUsingURL() {
assertEquals(decoder.decode(data), "hello world");
});
-test("Mode is correctly set when writing synchronously", function testCorrectFileModeSync() {
- if (Deno.build.os === "windows") return;
- const filename = "_fs_writeFileSync_test_file.txt";
+Deno.test(
+ "Mode is correctly set when writing synchronously",
+ function testCorrectFileModeSync() {
+ if (Deno.build.os === "windows") return;
+ const filename = "_fs_writeFileSync_test_file.txt";
- writeFileSync(filename, "hello world", { mode: 0o777 });
+ writeFileSync(filename, "hello world", { mode: 0o777 });
- const fileInfo = Deno.statSync(filename);
- Deno.removeSync(filename);
- assert(fileInfo && fileInfo.mode);
- assertEquals(fileInfo.mode & 0o777, 0o777);
-});
+ const fileInfo = Deno.statSync(filename);
+ Deno.removeSync(filename);
+ assert(fileInfo && fileInfo.mode);
+ assertEquals(fileInfo.mode & 0o777, 0o777);
+ }
+);
diff --git a/std/node/_fs/promises/_fs_readFile_test.ts b/std/node/_fs/promises/_fs_readFile_test.ts
index ac3c8fdda..c92907fec 100644
--- a/std/node/_fs/promises/_fs_readFile_test.ts
+++ b/std/node/_fs/promises/_fs_readFile_test.ts
@@ -1,4 +1,3 @@
-const { test } = Deno;
import { readFile } from "./_fs_readFile.ts";
import * as path from "../../../path/mod.ts";
import { assertEquals, assert } from "../../../testing/asserts.ts";
@@ -7,28 +6,28 @@ const testData = path.resolve(
path.join("node", "_fs", "testdata", "hello.txt")
);
-test("readFileSuccess", async function () {
+Deno.test("readFileSuccess", async function () {
const data = await readFile(testData);
assert(data instanceof Uint8Array);
assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world");
});
-test("readFileEncodeUtf8Success", async function () {
+Deno.test("readFileEncodeUtf8Success", async function () {
const data = await readFile(testData, { encoding: "utf8" });
assertEquals(typeof data, "string");
assertEquals(data as string, "hello world");
});
-test("readFileEncodingAsString", async function () {
+Deno.test("readFileEncodingAsString", async function () {
const data = await readFile(testData, "utf8");
assertEquals(typeof data, "string");
assertEquals(data as string, "hello world");
});
-test("readFileError", async function () {
+Deno.test("readFileError", async function () {
try {
await readFile("invalid-file", "utf8");
} catch (e) {
diff --git a/std/node/_fs/promises/_fs_writeFile_test.ts b/std/node/_fs/promises/_fs_writeFile_test.ts
index 171dbeb2c..574bbfc35 100644
--- a/std/node/_fs/promises/_fs_writeFile_test.ts
+++ b/std/node/_fs/promises/_fs_writeFile_test.ts
@@ -1,6 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { test } = Deno;
-
import {
assert,
assertEquals,
@@ -11,7 +9,7 @@ import { writeFile } from "./_fs_writeFile.ts";
const decoder = new TextDecoder("utf-8");
-test("Invalid encoding results in error()", function testEncodingErrors() {
+Deno.test("Invalid encoding results in error()", function testEncodingErrors() {
assertThrowsAsync(
async () => {
await writeFile("some/path", "some data", "made-up-encoding");
@@ -30,53 +28,62 @@ test("Invalid encoding results in error()", function testEncodingErrors() {
);
});
-test("Unsupported encoding results in error()", function testUnsupportedEncoding() {
- assertThrowsAsync(
- async () => {
- await writeFile("some/path", "some data", "hex");
- },
- Error,
- `Not implemented: "hex" encoding`
- );
- assertThrowsAsync(
- async () => {
- await writeFile("some/path", "some data", {
- encoding: "base64",
- });
- },
- Error,
- `Not implemented: "base64" encoding`
- );
-});
-
-test("Data is written to correct rid", async function testCorrectWriteUsingRid() {
- const tempFile: string = await Deno.makeTempFile();
- const file: Deno.File = await Deno.open(tempFile, {
- create: true,
- write: true,
- read: true,
- });
-
- await writeFile(file.rid, "hello world");
- Deno.close(file.rid);
-
- const data = await Deno.readFile(tempFile);
- await Deno.remove(tempFile);
- assertEquals(decoder.decode(data), "hello world");
-});
-
-test("Data is written to correct file", async function testCorrectWriteUsingPath() {
- const openResourcesBeforeWrite: Deno.ResourceMap = Deno.resources();
-
- await writeFile("_fs_writeFile_test_file.txt", "hello world");
-
- assertEquals(Deno.resources(), openResourcesBeforeWrite);
- const data = await Deno.readFile("_fs_writeFile_test_file.txt");
- await Deno.remove("_fs_writeFile_test_file.txt");
- assertEquals(decoder.decode(data), "hello world");
-});
-
-test("Mode is correctly set", async function testCorrectFileMode() {
+Deno.test(
+ "Unsupported encoding results in error()",
+ function testUnsupportedEncoding() {
+ assertThrowsAsync(
+ async () => {
+ await writeFile("some/path", "some data", "hex");
+ },
+ Error,
+ `Not implemented: "hex" encoding`
+ );
+ assertThrowsAsync(
+ async () => {
+ await writeFile("some/path", "some data", {
+ encoding: "base64",
+ });
+ },
+ Error,
+ `Not implemented: "base64" encoding`
+ );
+ }
+);
+
+Deno.test(
+ "Data is written to correct rid",
+ async function testCorrectWriteUsingRid() {
+ const tempFile: string = await Deno.makeTempFile();
+ const file: Deno.File = await Deno.open(tempFile, {
+ create: true,
+ write: true,
+ read: true,
+ });
+
+ await writeFile(file.rid, "hello world");
+ Deno.close(file.rid);
+
+ const data = await Deno.readFile(tempFile);
+ await Deno.remove(tempFile);
+ assertEquals(decoder.decode(data), "hello world");
+ }
+);
+
+Deno.test(
+ "Data is written to correct file",
+ async function testCorrectWriteUsingPath() {
+ const openResourcesBeforeWrite: Deno.ResourceMap = Deno.resources();
+
+ await writeFile("_fs_writeFile_test_file.txt", "hello world");
+
+ assertEquals(Deno.resources(), openResourcesBeforeWrite);
+ const data = await Deno.readFile("_fs_writeFile_test_file.txt");
+ await Deno.remove("_fs_writeFile_test_file.txt");
+ assertEquals(decoder.decode(data), "hello world");
+ }
+);
+
+Deno.test("Mode is correctly set", async function testCorrectFileMode() {
if (Deno.build.os === "windows") return;
const filename = "_fs_writeFile_test_file.txt";
await writeFile(filename, "hello world", { mode: 0o777 });
@@ -87,21 +94,24 @@ test("Mode is correctly set", async function testCorrectFileMode() {
assertEquals(fileInfo.mode & 0o777, 0o777);
});
-test("Mode is not set when rid is passed", async function testCorrectFileModeRid() {
- if (Deno.build.os === "windows") return;
-
- const filename: string = await Deno.makeTempFile();
- const file: Deno.File = await Deno.open(filename, {
- create: true,
- write: true,
- read: true,
- });
-
- await writeFile(file.rid, "hello world", { mode: 0o777 });
- Deno.close(file.rid);
-
- const fileInfo = await Deno.stat(filename);
- await Deno.remove(filename);
- assert(fileInfo.mode);
- assertNotEquals(fileInfo.mode & 0o777, 0o777);
-});
+Deno.test(
+ "Mode is not set when rid is passed",
+ async function testCorrectFileModeRid() {
+ if (Deno.build.os === "windows") return;
+
+ const filename: string = await Deno.makeTempFile();
+ const file: Deno.File = await Deno.open(filename, {
+ create: true,
+ write: true,
+ read: true,
+ });
+
+ await writeFile(file.rid, "hello world", { mode: 0o777 });
+ Deno.close(file.rid);
+
+ const fileInfo = await Deno.stat(filename);
+ await Deno.remove(filename);
+ assert(fileInfo.mode);
+ assertNotEquals(fileInfo.mode & 0o777, 0o777);
+ }
+);
diff --git a/std/node/_util/_util_callbackify_test.ts b/std/node/_util/_util_callbackify_test.ts
index 630e4d0e7..d6a5d8664 100644
--- a/std/node/_util/_util_callbackify_test.ts
+++ b/std/node/_util/_util_callbackify_test.ts
@@ -20,8 +20,6 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-const { test } = Deno;
import { assert, assertStrictEquals } from "../../testing/asserts.ts";
import { callbackify } from "./_util_callbackify.ts";
@@ -76,159 +74,174 @@ class TestQueue {
}
}
-test("callbackify passes the resolution value as the second argument to the callback", async () => {
- const testQueue = new TestQueue();
+Deno.test(
+ "callbackify passes the resolution value as the second argument to the callback",
+ async () => {
+ const testQueue = new TestQueue();
- for (const value of values) {
- // eslint-disable-next-line require-await
- async function asyncFn(): Promise<typeof value> {
- return value;
- }
- const cbAsyncFn = callbackify(asyncFn);
- testQueue.enqueue((done) => {
- cbAsyncFn((err: unknown, ret: unknown) => {
- assertStrictEquals(err, null);
- assertStrictEquals(ret, value);
- done();
+ for (const value of values) {
+ // eslint-disable-next-line require-await
+ async function asyncFn(): Promise<typeof value> {
+ return value;
+ }
+ const cbAsyncFn = callbackify(asyncFn);
+ testQueue.enqueue((done) => {
+ cbAsyncFn((err: unknown, ret: unknown) => {
+ assertStrictEquals(err, null);
+ assertStrictEquals(ret, value);
+ done();
+ });
});
- });
- function promiseFn(): Promise<typeof value> {
- return Promise.resolve(value);
- }
- const cbPromiseFn = callbackify(promiseFn);
- testQueue.enqueue((done) => {
- cbPromiseFn((err: unknown, ret: unknown) => {
- assertStrictEquals(err, null);
- assertStrictEquals(ret, value);
- done();
+ function promiseFn(): Promise<typeof value> {
+ return Promise.resolve(value);
+ }
+ const cbPromiseFn = callbackify(promiseFn);
+ testQueue.enqueue((done) => {
+ cbPromiseFn((err: unknown, ret: unknown) => {
+ assertStrictEquals(err, null);
+ assertStrictEquals(ret, value);
+ done();
+ });
});
- });
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- function thenableFn(): PromiseLike<any> {
- return {
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- then(onfulfilled): PromiseLike<any> {
- assert(onfulfilled);
- onfulfilled(value);
- return this;
- },
- };
- }
- const cbThenableFn = callbackify(thenableFn);
- testQueue.enqueue((done) => {
- cbThenableFn((err: unknown, ret: unknown) => {
- assertStrictEquals(err, null);
- assertStrictEquals(ret, value);
- done();
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ function thenableFn(): PromiseLike<any> {
+ return {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ then(onfulfilled): PromiseLike<any> {
+ assert(onfulfilled);
+ onfulfilled(value);
+ return this;
+ },
+ };
+ }
+ const cbThenableFn = callbackify(thenableFn);
+ testQueue.enqueue((done) => {
+ cbThenableFn((err: unknown, ret: unknown) => {
+ assertStrictEquals(err, null);
+ assertStrictEquals(ret, value);
+ done();
+ });
});
- });
- }
+ }
- await testQueue.waitForCompletion();
-});
+ await testQueue.waitForCompletion();
+ }
+);
-test("callbackify passes the rejection value as the first argument to the callback", async () => {
- const testQueue = new TestQueue();
+Deno.test(
+ "callbackify passes the rejection value as the first argument to the callback",
+ async () => {
+ const testQueue = new TestQueue();
- for (const value of values) {
- // eslint-disable-next-line require-await
- async function asyncFn(): Promise<never> {
- return Promise.reject(value);
- }
- const cbAsyncFn = callbackify(asyncFn);
- assertStrictEquals(cbAsyncFn.length, 1);
- assertStrictEquals(cbAsyncFn.name, "asyncFnCallbackified");
- testQueue.enqueue((done) => {
- cbAsyncFn((err: unknown, ret: unknown) => {
- assertStrictEquals(ret, undefined);
- if (err instanceof Error) {
- if ("reason" in err) {
- assert(!value);
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION");
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- assertStrictEquals((err as any).reason, value);
+ for (const value of values) {
+ // eslint-disable-next-line require-await
+ async function asyncFn(): Promise<never> {
+ return Promise.reject(value);
+ }
+ const cbAsyncFn = callbackify(asyncFn);
+ assertStrictEquals(cbAsyncFn.length, 1);
+ assertStrictEquals(cbAsyncFn.name, "asyncFnCallbackified");
+ testQueue.enqueue((done) => {
+ cbAsyncFn((err: unknown, ret: unknown) => {
+ assertStrictEquals(ret, undefined);
+ if (err instanceof Error) {
+ if ("reason" in err) {
+ assert(!value);
+ assertStrictEquals(
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (err as any).code,
+ "ERR_FALSY_VALUE_REJECTION"
+ );
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ assertStrictEquals((err as any).reason, value);
+ } else {
+ assertStrictEquals(String(value).endsWith(err.message), true);
+ }
} else {
- assertStrictEquals(String(value).endsWith(err.message), true);
+ assertStrictEquals(err, value);
}
- } else {
- assertStrictEquals(err, value);
- }
- done();
+ done();
+ });
});
- });
- function promiseFn(): Promise<never> {
- return Promise.reject(value);
- }
- const obj = {};
- Object.defineProperty(promiseFn, "name", {
- value: obj,
- writable: false,
- enumerable: false,
- configurable: true,
- });
+ function promiseFn(): Promise<never> {
+ return Promise.reject(value);
+ }
+ const obj = {};
+ Object.defineProperty(promiseFn, "name", {
+ value: obj,
+ writable: false,
+ enumerable: false,
+ configurable: true,
+ });
- const cbPromiseFn = callbackify(promiseFn);
- assertStrictEquals(promiseFn.name, obj);
- testQueue.enqueue((done) => {
- cbPromiseFn((err: unknown, ret: unknown) => {
- assertStrictEquals(ret, undefined);
- if (err instanceof Error) {
- if ("reason" in err) {
- assert(!value);
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION");
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- assertStrictEquals((err as any).reason, value);
+ const cbPromiseFn = callbackify(promiseFn);
+ assertStrictEquals(promiseFn.name, obj);
+ testQueue.enqueue((done) => {
+ cbPromiseFn((err: unknown, ret: unknown) => {
+ assertStrictEquals(ret, undefined);
+ if (err instanceof Error) {
+ if ("reason" in err) {
+ assert(!value);
+ assertStrictEquals(
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (err as any).code,
+ "ERR_FALSY_VALUE_REJECTION"
+ );
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ assertStrictEquals((err as any).reason, value);
+ } else {
+ assertStrictEquals(String(value).endsWith(err.message), true);
+ }
} else {
- assertStrictEquals(String(value).endsWith(err.message), true);
+ assertStrictEquals(err, value);
}
- } else {
- assertStrictEquals(err, value);
- }
- done();
+ done();
+ });
});
- });
-
- function thenableFn(): PromiseLike<never> {
- return {
- then(onfulfilled, onrejected): PromiseLike<never> {
- assert(onrejected);
- onrejected(value);
- return this;
- },
- };
- }
- const cbThenableFn = callbackify(thenableFn);
- testQueue.enqueue((done) => {
- cbThenableFn((err: unknown, ret: unknown) => {
- assertStrictEquals(ret, undefined);
- if (err instanceof Error) {
- if ("reason" in err) {
- assert(!value);
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION");
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- assertStrictEquals((err as any).reason, value);
+ function thenableFn(): PromiseLike<never> {
+ return {
+ then(onfulfilled, onrejected): PromiseLike<never> {
+ assert(onrejected);
+ onrejected(value);
+ return this;
+ },
+ };
+ }
+
+ const cbThenableFn = callbackify(thenableFn);
+ testQueue.enqueue((done) => {
+ cbThenableFn((err: unknown, ret: unknown) => {
+ assertStrictEquals(ret, undefined);
+ if (err instanceof Error) {
+ if ("reason" in err) {
+ assert(!value);
+ assertStrictEquals(
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (err as any).code,
+ "ERR_FALSY_VALUE_REJECTION"
+ );
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ assertStrictEquals((err as any).reason, value);
+ } else {
+ assertStrictEquals(String(value).endsWith(err.message), true);
+ }
} else {
- assertStrictEquals(String(value).endsWith(err.message), true);
+ assertStrictEquals(err, value);
}
- } else {
- assertStrictEquals(err, value);
- }
- done();
+ done();
+ });
});
- });
- }
+ }
- await testQueue.waitForCompletion();
-});
+ await testQueue.waitForCompletion();
+ }
+);
-test("callbackify passes arguments to the original", async () => {
+Deno.test("callbackify passes arguments to the original", async () => {
const testQueue = new TestQueue();
for (const value of values) {
@@ -276,7 +289,7 @@ test("callbackify passes arguments to the original", async () => {
await testQueue.waitForCompletion();
});
-test("callbackify preserves the `this` binding", async () => {
+Deno.test("callbackify preserves the `this` binding", async () => {
const testQueue = new TestQueue();
for (const value of values) {
@@ -325,7 +338,7 @@ test("callbackify preserves the `this` binding", async () => {
await testQueue.waitForCompletion();
});
-test("callbackify throws with non-function inputs", () => {
+Deno.test("callbackify throws with non-function inputs", () => {
["foo", null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -344,31 +357,34 @@ test("callbackify throws with non-function inputs", () => {
});
});
-test("callbackify returns a function that throws if the last argument is not a function", () => {
- // eslint-disable-next-line require-await
- async function asyncFn(): Promise<number> {
- return 42;
- }
+Deno.test(
+ "callbackify returns a function that throws if the last argument is not a function",
+ () => {
+ // eslint-disable-next-line require-await
+ async function asyncFn(): Promise<number> {
+ return 42;
+ }
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- const cb = callbackify(asyncFn) as any;
- const args: unknown[] = [];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const cb = callbackify(asyncFn) as any;
+ const args: unknown[] = [];
- ["foo", null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
- args.push(value);
+ ["foo", null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
+ args.push(value);
- try {
- cb(...args);
- throw Error("We should never reach this error");
- } catch (err) {
- assert(err instanceof TypeError);
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- assertStrictEquals((err as any).code, "ERR_INVALID_ARG_TYPE");
- assertStrictEquals(err.name, "TypeError");
- assertStrictEquals(
- err.message,
- "The last argument must be of type function."
- );
- }
- });
-});
+ try {
+ cb(...args);
+ throw Error("We should never reach this error");
+ } catch (err) {
+ assert(err instanceof TypeError);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ assertStrictEquals((err as any).code, "ERR_INVALID_ARG_TYPE");
+ assertStrictEquals(err.name, "TypeError");
+ assertStrictEquals(
+ err.message,
+ "The last argument must be of type function."
+ );
+ }
+ });
+ }
+);
diff --git a/std/node/_util/_util_promisify_test.ts b/std/node/_util/_util_promisify_test.ts
index a583d8cfe..c6dbbd45a 100644
--- a/std/node/_util/_util_promisify_test.ts
+++ b/std/node/_util/_util_promisify_test.ts
@@ -20,27 +20,26 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
import {
assert,
assertEquals,
assertStrictEquals,
assertThrowsAsync,
} from "../../testing/asserts.ts";
-
import { promisify } from "./_util_promisify.ts";
import * as fs from "../fs.ts";
-const { test } = Deno;
-
const readFile = promisify(fs.readFile);
const customPromisifyArgs = Symbol.for("deno.nodejs.util.promisify.customArgs");
-test("Errors should reject the promise", async function testPromiseRejection() {
- await assertThrowsAsync(() => readFile("/dontexist"), Deno.errors.NotFound);
-});
+Deno.test(
+ "Errors should reject the promise",
+ async function testPromiseRejection() {
+ await assertThrowsAsync(() => readFile("/dontexist"), Deno.errors.NotFound);
+ }
+);
-test("Promisify.custom", async function testPromisifyCustom() {
+Deno.test("Promisify.custom", async function testPromisifyCustom() {
function fn(): void {}
function promisifedFn(): void {}
@@ -56,7 +55,7 @@ test("Promisify.custom", async function testPromisifyCustom() {
await promisifiedFnB;
});
-test("promiisfy.custom symbol", function testPromisifyCustomSymbol() {
+Deno.test("promiisfy.custom symbol", function testPromisifyCustomSymbol() {
function fn(): void {}
function promisifiedFn(): void {}
@@ -72,7 +71,7 @@ test("promiisfy.custom symbol", function testPromisifyCustomSymbol() {
assertStrictEquals(promisify(promisify(fn)), promisifiedFn);
});
-test("Invalid argument should throw", function testThrowInvalidArgument() {
+Deno.test("Invalid argument should throw", function testThrowInvalidArgument() {
function fn(): void {}
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
fn[promisify.custom] = 42;
@@ -84,7 +83,7 @@ test("Invalid argument should throw", function testThrowInvalidArgument() {
}
});
-test("Custom promisify args", async function testPromisifyCustomArgs() {
+Deno.test("Custom promisify args", async function testPromisifyCustomArgs() {
const firstValue = 5;
const secondValue = 17;
@@ -99,50 +98,65 @@ test("Custom promisify args", async function testPromisifyCustomArgs() {
assertEquals(obj, { first: firstValue, second: secondValue });
});
-test("Multiple callback args without custom promisify args", async function testPromisifyWithoutCustomArgs() {
- function fn(callback: Function): void {
- callback(null, "foo", "bar");
+Deno.test(
+ "Multiple callback args without custom promisify args",
+ async function testPromisifyWithoutCustomArgs() {
+ function fn(callback: Function): void {
+ callback(null, "foo", "bar");
+ }
+ const value = await promisify(fn)();
+ assertStrictEquals(value, "foo");
}
- const value = await promisify(fn)();
- assertStrictEquals(value, "foo");
-});
+);
-test("Undefined resolved value", async function testPromisifyWithUndefinedResolvedValue() {
- function fn(callback: Function): void {
- callback(null);
+Deno.test(
+ "Undefined resolved value",
+ async function testPromisifyWithUndefinedResolvedValue() {
+ function fn(callback: Function): void {
+ callback(null);
+ }
+ const value = await promisify(fn)();
+ assertStrictEquals(value, undefined);
}
- const value = await promisify(fn)();
- assertStrictEquals(value, undefined);
-});
+);
-test("Undefined resolved value II", async function testPromisifyWithUndefinedResolvedValueII() {
- function fn(callback: Function): void {
- callback();
+Deno.test(
+ "Undefined resolved value II",
+ async function testPromisifyWithUndefinedResolvedValueII() {
+ function fn(callback: Function): void {
+ callback();
+ }
+ const value = await promisify(fn)();
+ assertStrictEquals(value, undefined);
}
- const value = await promisify(fn)();
- assertStrictEquals(value, undefined);
-});
+);
-test("Resolved value: number", async function testPromisifyWithNumberResolvedValue() {
- function fn(err: Error | null, val: number, callback: Function): void {
- callback(err, val);
+Deno.test(
+ "Resolved value: number",
+ async function testPromisifyWithNumberResolvedValue() {
+ function fn(err: Error | null, val: number, callback: Function): void {
+ callback(err, val);
+ }
+ const value = await promisify(fn)(null, 42);
+ assertStrictEquals(value, 42);
}
- const value = await promisify(fn)(null, 42);
- assertStrictEquals(value, 42);
-});
+);
-test("Rejected value", async function testPromisifyWithNumberRejectedValue() {
- function fn(err: Error | null, val: null, callback: Function): void {
- callback(err, val);
+Deno.test(
+ "Rejected value",
+ async function testPromisifyWithNumberRejectedValue() {
+ function fn(err: Error | null, val: null, callback: Function): void {
+ callback(err, val);
+ }
+ await assertThrowsAsync(
+ () => promisify(fn)(new Error("oops"), null),
+ Error,
+ "oops"
+ );
}
- await assertThrowsAsync(
- () => promisify(fn)(new Error("oops"), null),
- Error,
- "oops"
- );
-});
+);
-test("Rejected value", async function testPromisifyWithAsObjectMethod() {
+Deno.test("Rejected value", async function testPromisifyWithAsObjectMethod() {
const o: { fn?: Function } = {};
const fn = promisify(function (cb: Function): void {
// @ts-ignore TypeScript
@@ -155,21 +169,26 @@ test("Rejected value", async function testPromisifyWithAsObjectMethod() {
assert(val);
});
-test("Multiple callback", async function testPromisifyWithMultipleCallback() {
- const err = new Error("Should not have called the callback with the error.");
- const stack = err.stack;
-
- const fn = promisify(function (cb: Function): void {
- cb(null);
- cb(err);
- });
-
- await fn();
- await Promise.resolve();
- return assertStrictEquals(stack, err.stack);
-});
+Deno.test(
+ "Multiple callback",
+ async function testPromisifyWithMultipleCallback() {
+ const err = new Error(
+ "Should not have called the callback with the error."
+ );
+ const stack = err.stack;
+
+ const fn = promisify(function (cb: Function): void {
+ cb(null);
+ cb(err);
+ });
+
+ await fn();
+ await Promise.resolve();
+ return assertStrictEquals(stack, err.stack);
+ }
+);
-test("Promisify a promise", function testPromisifyPromise() {
+Deno.test("Promisify a promise", function testPromisifyPromise() {
function c(): void {}
const a = promisify(function (): void {});
const b = promisify(a);
@@ -177,7 +196,7 @@ test("Promisify a promise", function testPromisifyPromise() {
assertStrictEquals(a, b);
});
-test("Test error", async function testInvalidArguments() {
+Deno.test("Test error", async function testInvalidArguments() {
let errToThrow;
const thrower = promisify(function (
@@ -198,7 +217,7 @@ test("Test error", async function testInvalidArguments() {
}
});
-test("Test invalid arguments", function testInvalidArguments() {
+Deno.test("Test invalid arguments", function testInvalidArguments() {
[undefined, null, true, 0, "str", {}, [], Symbol()].forEach((input) => {
try {
// @ts-ignore TypeScript
diff --git a/std/node/_util/_util_types_test.ts b/std/node/_util/_util_types_test.ts
index 2d4307e77..f6dfcfe89 100644
--- a/std/node/_util/_util_types_test.ts
+++ b/std/node/_util/_util_types_test.ts
@@ -20,8 +20,6 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-const { test } = Deno;
import { assertStrictEquals } from "../../testing/asserts.ts";
import {
isDate,
@@ -68,19 +66,19 @@ import {
import * as testModuleNamespaceOpbject from "./_util_types.ts";
// isAnyArrayBuffer
-test("Should return true for valid ArrayBuffer types", () => {
+Deno.test("Should return true for valid ArrayBuffer types", () => {
assertStrictEquals(isAnyArrayBuffer(new ArrayBuffer(0)), true);
assertStrictEquals(isAnyArrayBuffer(new SharedArrayBuffer(0)), true);
});
-test("Should return false for invalid ArrayBuffer types", () => {
+Deno.test("Should return false for invalid ArrayBuffer types", () => {
assertStrictEquals(isAnyArrayBuffer({}), false);
assertStrictEquals(isAnyArrayBuffer([]), false);
assertStrictEquals(isAnyArrayBuffer(new Error()), false);
});
// isArrayBufferView
-test("Should return true for valid ArrayBufferView types", () => {
+Deno.test("Should return true for valid ArrayBufferView types", () => {
assertStrictEquals(isArrayBufferView(new Int8Array(0)), true);
assertStrictEquals(isArrayBufferView(new Uint8Array(0)), true);
assertStrictEquals(isArrayBufferView(new Uint8ClampedArray(0)), true);
@@ -93,7 +91,7 @@ test("Should return true for valid ArrayBufferView types", () => {
assertStrictEquals(isArrayBufferView(new DataView(new ArrayBuffer(0))), true);
});
-test("Should return false for invalid ArrayBufferView types", () => {
+Deno.test("Should return false for invalid ArrayBufferView types", () => {
assertStrictEquals(isArrayBufferView({}), false);
assertStrictEquals(isArrayBufferView([]), false);
assertStrictEquals(isArrayBufferView(new Error()), false);
@@ -103,18 +101,18 @@ test("Should return false for invalid ArrayBufferView types", () => {
// isArgumentsObject
// Note: not testable in TS
-test("Should return false for invalid Argument types", () => {
+Deno.test("Should return false for invalid Argument types", () => {
assertStrictEquals(isArgumentsObject({}), false);
assertStrictEquals(isArgumentsObject([]), false);
assertStrictEquals(isArgumentsObject(new Error()), false);
});
// isArrayBuffer
-test("Should return true for valid ArrayBuffer types", () => {
+Deno.test("Should return true for valid ArrayBuffer types", () => {
assertStrictEquals(isArrayBuffer(new ArrayBuffer(0)), true);
});
-test("Should return false for invalid ArrayBuffer types", () => {
+Deno.test("Should return false for invalid ArrayBuffer types", () => {
assertStrictEquals(isArrayBuffer(new SharedArrayBuffer(0)), false);
assertStrictEquals(isArrayBuffer({}), false);
assertStrictEquals(isArrayBuffer([]), false);
@@ -122,12 +120,12 @@ test("Should return false for invalid ArrayBuffer types", () => {
});
// isAsyncFunction
-test("Should return true for valid async function types", () => {
+Deno.test("Should return true for valid async function types", () => {
const asyncFunction = async (): Promise<void> => {};
assertStrictEquals(isAsyncFunction(asyncFunction), true);
});
-test("Should return false for invalid async function types", () => {
+Deno.test("Should return false for invalid async function types", () => {
const syncFunction = (): void => {};
assertStrictEquals(isAsyncFunction(syncFunction), false);
assertStrictEquals(isAsyncFunction({}), false);
@@ -136,34 +134,34 @@ test("Should return false for invalid async function types", () => {
});
// isBigInt64Array
-test("Should return true for valid BigInt64Array types", () => {
+Deno.test("Should return true for valid BigInt64Array types", () => {
assertStrictEquals(isBigInt64Array(new BigInt64Array()), true);
});
-test("Should return false for invalid BigInt64Array types", () => {
+Deno.test("Should return false for invalid BigInt64Array types", () => {
assertStrictEquals(isBigInt64Array(new BigUint64Array()), false);
assertStrictEquals(isBigInt64Array(new Float32Array()), false);
assertStrictEquals(isBigInt64Array(new Int32Array()), false);
});
// isBigUint64Array
-test("Should return true for valid isBigUint64Array types", () => {
+Deno.test("Should return true for valid isBigUint64Array types", () => {
assertStrictEquals(isBigUint64Array(new BigUint64Array()), true);
});
-test("Should return false for invalid isBigUint64Array types", () => {
+Deno.test("Should return false for invalid isBigUint64Array types", () => {
assertStrictEquals(isBigUint64Array(new BigInt64Array()), false);
assertStrictEquals(isBigUint64Array(new Float32Array()), false);
assertStrictEquals(isBigUint64Array(new Int32Array()), false);
});
// isBooleanObject
-test("Should return true for valid Boolean object types", () => {
+Deno.test("Should return true for valid Boolean object types", () => {
assertStrictEquals(isBooleanObject(new Boolean(false)), true);
assertStrictEquals(isBooleanObject(new Boolean(true)), true);
});
-test("Should return false for invalid isBigUint64Array types", () => {
+Deno.test("Should return false for invalid isBigUint64Array types", () => {
assertStrictEquals(isBooleanObject(false), false);
assertStrictEquals(isBooleanObject(true), false);
assertStrictEquals(isBooleanObject(Boolean(false)), false);
@@ -171,35 +169,35 @@ test("Should return false for invalid isBigUint64Array types", () => {
});
// isBoxedPrimitive
-test("Should return true for valid boxed primitive values", () => {
+Deno.test("Should return true for valid boxed primitive values", () => {
assertStrictEquals(isBoxedPrimitive(new Boolean(false)), true);
assertStrictEquals(isBoxedPrimitive(Object(Symbol("foo"))), true);
assertStrictEquals(isBoxedPrimitive(Object(BigInt(5))), true);
assertStrictEquals(isBoxedPrimitive(new String("foo")), true);
});
-test("Should return false for invalid boxed primitive values", () => {
+Deno.test("Should return false for invalid boxed primitive values", () => {
assertStrictEquals(isBoxedPrimitive(false), false);
assertStrictEquals(isBoxedPrimitive(Symbol("foo")), false);
});
// isDateView
-test("Should return true for valid DataView types", () => {
+Deno.test("Should return true for valid DataView types", () => {
assertStrictEquals(isDataView(new DataView(new ArrayBuffer(0))), true);
});
-test("Should return false for invalid DataView types", () => {
+Deno.test("Should return false for invalid DataView types", () => {
assertStrictEquals(isDataView(new Float64Array(0)), false);
});
// isDate
-test("Should return true for valid date types", () => {
+Deno.test("Should return true for valid date types", () => {
assertStrictEquals(isDate(new Date()), true);
assertStrictEquals(isDate(new Date(0)), true);
assertStrictEquals(isDate(new (eval("Date"))()), true);
});
-test("Should return false for invalid date types", () => {
+Deno.test("Should return false for invalid date types", () => {
assertStrictEquals(isDate(Date()), false);
assertStrictEquals(isDate({}), false);
assertStrictEquals(isDate([]), false);
@@ -208,34 +206,34 @@ test("Should return false for invalid date types", () => {
});
// isFloat32Array
-test("Should return true for valid Float32Array types", () => {
+Deno.test("Should return true for valid Float32Array types", () => {
assertStrictEquals(isFloat32Array(new Float32Array(0)), true);
});
-test("Should return false for invalid Float32Array types", () => {
+Deno.test("Should return false for invalid Float32Array types", () => {
assertStrictEquals(isFloat32Array(new ArrayBuffer(0)), false);
assertStrictEquals(isFloat32Array(new Float64Array(0)), false);
});
// isFloat64Array
-test("Should return true for valid Float64Array types", () => {
+Deno.test("Should return true for valid Float64Array types", () => {
assertStrictEquals(isFloat64Array(new Float64Array(0)), true);
});
-test("Should return false for invalid Float64Array types", () => {
+Deno.test("Should return false for invalid Float64Array types", () => {
assertStrictEquals(isFloat64Array(new ArrayBuffer(0)), false);
assertStrictEquals(isFloat64Array(new Uint8Array(0)), false);
});
// isGeneratorFunction
-test("Should return true for valid generator functions", () => {
+Deno.test("Should return true for valid generator functions", () => {
assertStrictEquals(
isGeneratorFunction(function* foo() {}),
true
);
});
-test("Should return false for invalid generator functions", () => {
+Deno.test("Should return false for invalid generator functions", () => {
assertStrictEquals(
isGeneratorFunction(function foo() {}),
false
@@ -243,12 +241,12 @@ test("Should return false for invalid generator functions", () => {
});
// isGeneratorObject
-test("Should return true for valid generator object types", () => {
+Deno.test("Should return true for valid generator object types", () => {
function* foo(): Iterator<void> {}
assertStrictEquals(isGeneratorObject(foo()), true);
});
-test("Should return false for invalid generation object types", () => {
+Deno.test("Should return false for invalid generation object types", () => {
assertStrictEquals(
isGeneratorObject(function* foo() {}),
false
@@ -256,52 +254,52 @@ test("Should return false for invalid generation object types", () => {
});
// isInt8Array
-test("Should return true for valid Int8Array types", () => {
+Deno.test("Should return true for valid Int8Array types", () => {
assertStrictEquals(isInt8Array(new Int8Array(0)), true);
});
-test("Should return false for invalid Int8Array types", () => {
+Deno.test("Should return false for invalid Int8Array types", () => {
assertStrictEquals(isInt8Array(new ArrayBuffer(0)), false);
assertStrictEquals(isInt8Array(new Float64Array(0)), false);
});
// isInt16Array
-test("Should return true for valid Int16Array types", () => {
+Deno.test("Should return true for valid Int16Array types", () => {
assertStrictEquals(isInt16Array(new Int16Array(0)), true);
});
-test("Should return false for invalid Int16Array type", () => {
+Deno.test("Should return false for invalid Int16Array type", () => {
assertStrictEquals(isInt16Array(new ArrayBuffer(0)), false);
assertStrictEquals(isInt16Array(new Float64Array(0)), false);
});
// isInt32Array
-test("Should return true for valid isInt32Array types", () => {
+Deno.test("Should return true for valid isInt32Array types", () => {
assertStrictEquals(isInt32Array(new Int32Array(0)), true);
});
-test("Should return false for invalid isInt32Array type", () => {
+Deno.test("Should return false for invalid isInt32Array type", () => {
assertStrictEquals(isInt32Array(new ArrayBuffer(0)), false);
assertStrictEquals(isInt32Array(new Float64Array(0)), false);
});
// isStringObject
-test("Should return true for valid String types", () => {
+Deno.test("Should return true for valid String types", () => {
assertStrictEquals(isStringObject(new String("")), true);
assertStrictEquals(isStringObject(new String("Foo")), true);
});
-test("Should return false for invalid String types", () => {
+Deno.test("Should return false for invalid String types", () => {
assertStrictEquals(isStringObject(""), false);
assertStrictEquals(isStringObject("Foo"), false);
});
// isMap
-test("Should return true for valid Map types", () => {
+Deno.test("Should return true for valid Map types", () => {
assertStrictEquals(isMap(new Map()), true);
});
-test("Should return false for invalid Map types", () => {
+Deno.test("Should return false for invalid Map types", () => {
assertStrictEquals(isMap({}), false);
assertStrictEquals(isMap([]), false);
assertStrictEquals(isMap(new Date()), false);
@@ -309,7 +307,7 @@ test("Should return false for invalid Map types", () => {
});
// isMapIterator
-test("Should return true for valid Map Iterator types", () => {
+Deno.test("Should return true for valid Map Iterator types", () => {
const map = new Map();
assertStrictEquals(isMapIterator(map.keys()), true);
assertStrictEquals(isMapIterator(map.values()), true);
@@ -317,7 +315,7 @@ test("Should return true for valid Map Iterator types", () => {
assertStrictEquals(isMapIterator(map[Symbol.iterator]()), true);
});
-test("Should return false for invalid Map iterator types", () => {
+Deno.test("Should return false for invalid Map iterator types", () => {
assertStrictEquals(isMapIterator(new Map()), false);
assertStrictEquals(isMapIterator([]), false);
assertStrictEquals(isMapIterator(new Date()), false);
@@ -325,70 +323,70 @@ test("Should return false for invalid Map iterator types", () => {
});
// isModuleNamespaceObject
-test("Should return true for valid module namespace objects", () => {
+Deno.test("Should return true for valid module namespace objects", () => {
assertStrictEquals(isModuleNamespaceObject(testModuleNamespaceOpbject), true);
});
-test("Should return false for invalid module namespace objects", () => {
+Deno.test("Should return false for invalid module namespace objects", () => {
assertStrictEquals(isModuleNamespaceObject(assertStrictEquals), false);
});
// isNativeError
-test("Should return true for valid Error types", () => {
+Deno.test("Should return true for valid Error types", () => {
assertStrictEquals(isNativeError(new Error()), true);
assertStrictEquals(isNativeError(new TypeError()), true);
assertStrictEquals(isNativeError(new RangeError()), true);
});
-test("Should return false for invalid Error types", () => {
+Deno.test("Should return false for invalid Error types", () => {
assertStrictEquals(isNativeError(null), false);
assertStrictEquals(isNativeError(NaN), false);
});
// isNumberObject
-test("Should return true for valid number objects", () => {
+Deno.test("Should return true for valid number objects", () => {
assertStrictEquals(isNumberObject(new Number(0)), true);
});
-test("Should return false for invalid number types", () => {
+Deno.test("Should return false for invalid number types", () => {
assertStrictEquals(isNumberObject(0), false);
});
// isBigIntObject
-test("Should return true for valid number objects", () => {
+Deno.test("Should return true for valid number objects", () => {
assertStrictEquals(isBigIntObject(new Object(BigInt(42))), true);
});
-test("Should return false for invalid number types", () => {
+Deno.test("Should return false for invalid number types", () => {
assertStrictEquals(isBigIntObject(BigInt(42)), false);
});
// isPromise
-test("Should return true for valid Promise types", () => {
+Deno.test("Should return true for valid Promise types", () => {
assertStrictEquals(isPromise(Promise.resolve(42)), true);
});
-test("Should return false for invalid Promise types", () => {
+Deno.test("Should return false for invalid Promise types", () => {
assertStrictEquals(isPromise(new Object()), false);
});
// isRegExp
-test("Should return true for valid RegExp", () => {
+Deno.test("Should return true for valid RegExp", () => {
assertStrictEquals(isRegExp(/abc/), true);
assertStrictEquals(isRegExp(new RegExp("abc")), true);
});
-test("Should return false for invalid RegExp types", () => {
+Deno.test("Should return false for invalid RegExp types", () => {
assertStrictEquals(isRegExp({}), false);
assertStrictEquals(isRegExp("/abc/"), false);
});
// isSet
-test("Should return true for valid Set types", () => {
+Deno.test("Should return true for valid Set types", () => {
assertStrictEquals(isSet(new Set()), true);
});
-test("Should return false for invalid Set types", () => {
+Deno.test("Should return false for invalid Set types", () => {
assertStrictEquals(isSet({}), false);
assertStrictEquals(isSet([]), false);
assertStrictEquals(isSet(new Map()), false);
@@ -396,7 +394,7 @@ test("Should return false for invalid Set types", () => {
});
// isSetIterator
-test("Should return true for valid Set Iterator types", () => {
+Deno.test("Should return true for valid Set Iterator types", () => {
const set = new Set();
assertStrictEquals(isSetIterator(set.keys()), true);
assertStrictEquals(isSetIterator(set.values()), true);
@@ -404,7 +402,7 @@ test("Should return true for valid Set Iterator types", () => {
assertStrictEquals(isSetIterator(set[Symbol.iterator]()), true);
});
-test("Should return false for invalid Set Iterator types", () => {
+Deno.test("Should return false for invalid Set Iterator types", () => {
assertStrictEquals(isSetIterator(new Set()), false);
assertStrictEquals(isSetIterator([]), false);
assertStrictEquals(isSetIterator(new Map()), false);
@@ -412,100 +410,100 @@ test("Should return false for invalid Set Iterator types", () => {
});
// isSharedArrayBuffer
-test("Should return true for valid SharedArrayBuffer types", () => {
+Deno.test("Should return true for valid SharedArrayBuffer types", () => {
assertStrictEquals(isSharedArrayBuffer(new SharedArrayBuffer(0)), true);
});
-test("Should return false for invalid SharedArrayBuffer types", () => {
+Deno.test("Should return false for invalid SharedArrayBuffer types", () => {
assertStrictEquals(isSharedArrayBuffer(new ArrayBuffer(0)), false);
});
// isStringObject
-test("Should return true for valid String Object types", () => {
+Deno.test("Should return true for valid String Object types", () => {
assertStrictEquals(isStringObject(new String("")), true);
assertStrictEquals(isStringObject(new String("Foo")), true);
});
-test("Should return false for invalid String Object types", () => {
+Deno.test("Should return false for invalid String Object types", () => {
assertStrictEquals(isStringObject(""), false);
assertStrictEquals(isStringObject("Foo"), false);
});
// isSymbolObject
-test("Should return true for valid Symbol types", () => {
+Deno.test("Should return true for valid Symbol types", () => {
assertStrictEquals(isSymbolObject(Object(Symbol("foo"))), true);
});
-test("Should return false for invalid Symbol types", () => {
+Deno.test("Should return false for invalid Symbol types", () => {
assertStrictEquals(isSymbolObject(Symbol("foo")), false);
});
// isTypedArray
-test("Should return true for valid TypedArray types", () => {
+Deno.test("Should return true for valid TypedArray types", () => {
assertStrictEquals(isTypedArray(new Uint8Array(0)), true);
assertStrictEquals(isTypedArray(new Float64Array(0)), true);
});
-test("Should return false for invalid TypedArray types", () => {
+Deno.test("Should return false for invalid TypedArray types", () => {
assertStrictEquals(isTypedArray(new ArrayBuffer(0)), false);
});
// isUint8Array
-test("Should return true for valid Uint8Array types", () => {
+Deno.test("Should return true for valid Uint8Array types", () => {
assertStrictEquals(isUint8Array(new Uint8Array(0)), true);
});
-test("Should return false for invalid Uint8Array types", () => {
+Deno.test("Should return false for invalid Uint8Array types", () => {
assertStrictEquals(isUint8Array(new ArrayBuffer(0)), false);
assertStrictEquals(isUint8Array(new Float64Array(0)), false);
});
// isUint8ClampedArray
-test("Should return true for valid Uint8ClampedArray types", () => {
+Deno.test("Should return true for valid Uint8ClampedArray types", () => {
assertStrictEquals(isUint8ClampedArray(new Uint8ClampedArray(0)), true);
});
-test("Should return false for invalid Uint8Array types", () => {
+Deno.test("Should return false for invalid Uint8Array types", () => {
assertStrictEquals(isUint8ClampedArray(new ArrayBuffer(0)), false);
assertStrictEquals(isUint8ClampedArray(new Float64Array(0)), false);
});
// isUint16Array
-test("Should return true for valid isUint16Array types", () => {
+Deno.test("Should return true for valid isUint16Array types", () => {
assertStrictEquals(isUint16Array(new Uint16Array(0)), true);
});
-test("Should return false for invalid Uint16Array types", () => {
+Deno.test("Should return false for invalid Uint16Array types", () => {
assertStrictEquals(isUint16Array(new ArrayBuffer(0)), false);
assertStrictEquals(isUint16Array(new Float64Array(0)), false);
});
// isUint32Array
-test("Should return true for valid Uint32Array types", () => {
+Deno.test("Should return true for valid Uint32Array types", () => {
assertStrictEquals(isUint32Array(new Uint32Array(0)), true);
});
-test("Should return false for invalid isUint16Array types", () => {
+Deno.test("Should return false for invalid isUint16Array types", () => {
assertStrictEquals(isUint32Array(new ArrayBuffer(0)), false);
assertStrictEquals(isUint32Array(new Float64Array(0)), false);
});
// isWeakMap
-test("Should return true for valid WeakMap types", () => {
+Deno.test("Should return true for valid WeakMap types", () => {
assertStrictEquals(isWeakMap(new WeakMap()), true);
});
-test("Should return false for invalid WeakMap types", () => {
+Deno.test("Should return false for invalid WeakMap types", () => {
assertStrictEquals(isWeakMap(new Set()), false);
assertStrictEquals(isWeakMap(new Map()), false);
});
// isWeakSet
-test("Should return true for valid WeakSet types", () => {
+Deno.test("Should return true for valid WeakSet types", () => {
assertStrictEquals(isWeakSet(new WeakSet()), true);
});
-test("Should return false for invalid WeakSet types", () => {
+Deno.test("Should return false for invalid WeakSet types", () => {
assertStrictEquals(isWeakSet(new Set()), false);
assertStrictEquals(isWeakSet(new Map()), false);
});
diff --git a/std/node/events_test.ts b/std/node/events_test.ts
index 4b47686f4..58025ce84 100644
--- a/std/node/events_test.ts
+++ b/std/node/events_test.ts
@@ -1,4 +1,3 @@
-const { test } = Deno;
import {
assert,
assertEquals,
@@ -11,7 +10,7 @@ const shouldNeverBeEmitted: Function = () => {
fail("Should never be called");
};
-test({
+Deno.test({
name:
'When adding a new event, "eventListener" event is fired before adding the listener',
fn() {
@@ -32,7 +31,7 @@ test({
},
});
-test({
+Deno.test({
name:
'When removing a listenert, "removeListener" event is fired after removal',
fn() {
@@ -52,7 +51,7 @@ test({
},
});
-test({
+Deno.test({
name:
"Default max listeners is 10, but can be changed by direct assignment only",
fn() {
@@ -65,7 +64,7 @@ test({
},
});
-test({
+Deno.test({
name: "addListener adds a listener, and listener count is correct",
fn() {
const testEmitter = new EventEmitter();
@@ -76,7 +75,7 @@ test({
},
});
-test({
+Deno.test({
name: "Emitted events are called synchronously in the order they were added",
fn() {
const testEmitter = new EventEmitter();
@@ -103,7 +102,7 @@ test({
},
});
-test({
+Deno.test({
name: "Registered event names are returned as strings or Sybols",
fn() {
const testEmitter = new EventEmitter();
@@ -115,7 +114,7 @@ test({
},
});
-test({
+Deno.test({
name: "You can set and get max listeners",
fn() {
const testEmitter = new EventEmitter();
@@ -125,7 +124,7 @@ test({
},
});
-test({
+Deno.test({
name: "You can retrieve registered functions for an event",
fn() {
const testEmitter = new EventEmitter();
@@ -140,7 +139,7 @@ test({
},
});
-test({
+Deno.test({
name: "Off is alias for removeListener",
fn() {
const testEmitter = new EventEmitter();
@@ -151,7 +150,7 @@ test({
},
});
-test({
+Deno.test({
name: "Event registration can be chained",
fn() {
const testEmitter = new EventEmitter();
@@ -162,7 +161,7 @@ test({
},
});
-test({
+Deno.test({
name: "Events can be registered to only fire once",
fn() {
let eventsFired: string[] = [];
@@ -186,7 +185,7 @@ test({
},
});
-test({
+Deno.test({
name:
"You can inject a listener into the start of the stack, rather than at the end",
fn() {
@@ -206,7 +205,7 @@ test({
},
});
-test({
+Deno.test({
name: 'You can prepend a "once" listener',
fn() {
const eventsFired: string[] = [];
@@ -226,7 +225,7 @@ test({
},
});
-test({
+Deno.test({
name: "Remove all listeners, which can also be chained",
fn() {
const testEmitter = new EventEmitter();
@@ -245,7 +244,7 @@ test({
},
});
-test({
+Deno.test({
name: "Provide a non-existent event to removeAllListeners will do nothing",
fn() {
const testEmitter = new EventEmitter();
@@ -264,7 +263,7 @@ test({
},
});
-test({
+Deno.test({
name: "Remove individual listeners, which can also be chained",
fn() {
const testEmitter = new EventEmitter();
@@ -287,7 +286,7 @@ test({
},
});
-test({
+Deno.test({
name: "It is OK to try to remove non-existent listener",
fn() {
const testEmitter = new EventEmitter();
@@ -306,7 +305,7 @@ test({
},
});
-test({
+Deno.test({
name: "all listeners complete execution even if removed before execution",
fn() {
const testEmitter = new EventEmitter();
@@ -329,7 +328,7 @@ test({
},
});
-test({
+Deno.test({
name: 'Raw listener will return event listener or wrapped "once" function',
fn() {
const testEmitter = new EventEmitter();
@@ -352,7 +351,7 @@ test({
},
});
-test({
+Deno.test({
name:
"Once wrapped raw listeners may be executed multiple times, until the wrapper is executed",
fn() {
@@ -375,7 +374,7 @@ test({
},
});
-test({
+Deno.test({
name: "Can add once event listener to EventEmitter via standalone function",
async fn() {
const ee = new EventEmitter();
@@ -388,7 +387,7 @@ test({
},
});
-test({
+Deno.test({
name: "Can add once event listener to EventTarget via standalone function",
async fn() {
const et: EventTarget = new EventTarget();
@@ -402,7 +401,7 @@ test({
},
});
-test({
+Deno.test({
name: "Only valid integers are allowed for max listeners",
fn() {
const ee = new EventEmitter();
@@ -424,7 +423,7 @@ test({
},
});
-test({
+Deno.test({
name: "ErrorMonitor can spy on error events without consuming them",
fn() {
const ee = new EventEmitter();
@@ -462,7 +461,7 @@ test({
},
});
-test({
+Deno.test({
name: "asynchronous iteration of events are handled as expected",
async fn() {
const ee = new EventEmitter();
@@ -490,7 +489,7 @@ test({
},
});
-test({
+Deno.test({
name: "asynchronous error handling of emitted events works as expected",
async fn() {
const ee = new EventEmitter();
@@ -515,7 +514,7 @@ test({
},
});
-test({
+Deno.test({
name: "error thrown during asynchronous processing of events is handled",
async fn() {
const ee = new EventEmitter();
@@ -544,7 +543,7 @@ test({
},
});
-test({
+Deno.test({
name:
"error thrown in processing loop of asynchronous event prevents processing of additional events",
async fn() {
@@ -570,7 +569,7 @@ test({
},
});
-test({
+Deno.test({
name: "asynchronous iterator next() works as expected",
async fn() {
const ee = new EventEmitter();
@@ -610,7 +609,7 @@ test({
},
});
-test({
+Deno.test({
name: "async iterable throw handles various scenarios",
async fn() {
const ee = new EventEmitter();
diff --git a/std/node/module_test.ts b/std/node/module_test.ts
index b1a22c0f6..30441a58d 100644
--- a/std/node/module_test.ts
+++ b/std/node/module_test.ts
@@ -1,6 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
-
-const { test } = Deno;
import {
assertEquals,
assert,
@@ -10,7 +8,7 @@ import { createRequire } from "./module.ts";
const require = createRequire(import.meta.url);
-test("requireSuccess", function () {
+Deno.test("requireSuccess", function () {
// Relative to import.meta.url
const result = require("./tests/cjs/cjs_a.js");
assert("helloA" in result);
@@ -23,14 +21,14 @@ test("requireSuccess", function () {
assertEquals(result.leftPad("pad", 4), " pad");
});
-test("requireCycle", function () {
+Deno.test("requireCycle", function () {
const resultA = require("./tests/cjs/cjs_cycle_a");
const resultB = require("./tests/cjs/cjs_cycle_b");
assert(resultA);
assert(resultB);
});
-test("requireBuiltin", function () {
+Deno.test("requireBuiltin", function () {
const fs = require("fs");
assert("readFileSync" in fs);
const { readFileSync, isNull, extname } = require("./tests/cjs/cjs_builtin");
@@ -42,18 +40,18 @@ test("requireBuiltin", function () {
assertEquals(extname("index.html"), ".html");
});
-test("requireIndexJS", function () {
+Deno.test("requireIndexJS", function () {
const { isIndex } = require("./tests/cjs");
assert(isIndex);
});
-test("requireNodeOs", function () {
+Deno.test("requireNodeOs", function () {
const os = require("os");
assert(os.arch);
assert(typeof os.arch() == "string");
});
-test("requireStack", function () {
+Deno.test("requireStack", function () {
const { hello } = require("./tests/cjs/cjs_throw");
try {
hello();
diff --git a/std/node/os_test.ts b/std/node/os_test.ts
index f0b9ca79d..11de777a9 100644
--- a/std/node/os_test.ts
+++ b/std/node/os_test.ts
@@ -1,50 +1,49 @@
-const { test } = Deno;
import { assert, assertThrows, assertEquals } from "../testing/asserts.ts";
import * as os from "./os.ts";
-test({
+Deno.test({
name: "build architecture is a string",
fn() {
assertEquals(typeof os.arch(), "string");
},
});
-test({
+Deno.test({
name: "home directory is a string",
fn() {
assertEquals(typeof os.homedir(), "string");
},
});
-test({
+Deno.test({
name: "tmp directory is a string",
fn() {
assertEquals(typeof os.tmpdir(), "string");
},
});
-test({
+Deno.test({
name: "hostname is a string",
fn() {
assertEquals(typeof os.hostname(), "string");
},
});
-test({
+Deno.test({
name: "platform is a string",
fn() {
assertEquals(typeof os.platform(), "string");
},
});
-test({
+Deno.test({
name: "release is a string",
fn() {
assertEquals(typeof os.release(), "string");
},
});
-test({
+Deno.test({
name: "getPriority(): PID must be a 32 bit integer",
fn() {
assertThrows(
@@ -64,7 +63,7 @@ test({
},
});
-test({
+Deno.test({
name: "setPriority(): PID must be a 32 bit integer",
fn() {
assertThrows(
@@ -84,7 +83,7 @@ test({
},
});
-test({
+Deno.test({
name: "setPriority(): priority must be an integer between -20 and 19",
fn() {
assertThrows(
@@ -118,7 +117,7 @@ test({
},
});
-test({
+Deno.test({
name:
"setPriority(): if only one argument specified, then this is the priority, NOT the pid",
fn() {
@@ -153,7 +152,7 @@ test({
},
});
-test({
+Deno.test({
name: "Signals are as expected",
fn() {
// Test a few random signals for equality
@@ -163,21 +162,21 @@ test({
},
});
-test({
+Deno.test({
name: "EOL is as expected",
fn() {
assert(os.EOL == "\r\n" || os.EOL == "\n");
},
});
-test({
+Deno.test({
name: "Endianness is determined",
fn() {
assert(["LE", "BE"].includes(os.endianness()));
},
});
-test({
+Deno.test({
name: "Load average is an array of 3 numbers",
fn() {
const result = os.loadavg();
@@ -188,7 +187,7 @@ test({
},
});
-test({
+Deno.test({
name: "Primitive coercion works as expected",
fn() {
assertEquals(`${os.arch}`, os.arch());
@@ -199,7 +198,7 @@ test({
},
});
-test({
+Deno.test({
name: "APIs not yet implemented",
fn() {
assertThrows(
diff --git a/std/node/process.ts b/std/node/process.ts
index 9da41b45b..cad72a00a 100644
--- a/std/node/process.ts
+++ b/std/node/process.ts
@@ -1,32 +1,22 @@
import { notImplemented } from "./_utils.ts";
-const version = `v${Deno.version.deno}`;
-
-const versions = {
- node: Deno.version.deno,
- ...Deno.version,
-};
-
-const platform = Deno.build.os === "windows" ? "win32" : Deno.build.os;
-
-const { arch } = Deno.build;
-
-const { pid, cwd, chdir, exit } = Deno;
-
function on(_event: string, _callback: Function): void {
// TODO(rsp): to be implemented
notImplemented();
}
export const process = {
- version,
- versions,
- platform,
- arch,
- pid,
- cwd,
- chdir,
- exit,
+ version: `v${Deno.version.deno}`,
+ versions: {
+ node: Deno.version.deno,
+ ...Deno.version,
+ },
+ platform: Deno.build.os === "windows" ? "win32" : Deno.build.os,
+ arch: Deno.build.arch,
+ pid: Deno.pid,
+ cwd: Deno.cwd,
+ chdir: Deno.chdir,
+ exit: Deno.exit,
on,
get env(): { [index: string]: string } {
// using getter to avoid --allow-env unless it's used
diff --git a/std/node/process_test.ts b/std/node/process_test.ts
index 3afaa4cdf..058105a4a 100644
--- a/std/node/process_test.ts
+++ b/std/node/process_test.ts
@@ -1,11 +1,10 @@
-const { test } = Deno;
import { assert, assertThrows, assertEquals } from "../testing/asserts.ts";
import { process } from "./process.ts";
// NOTE: Deno.execPath() (and thus process.argv) currently requires --allow-env
// (Also Deno.env.toObject() (and process.env) requires --allow-env but it's more obvious)
-test({
+Deno.test({
name: "process.cwd and process.chdir success",
fn() {
// this should be run like other tests from directory up
@@ -17,7 +16,7 @@ test({
},
});
-test({
+Deno.test({
name: "process.chdir failure",
fn() {
assertThrows(
@@ -33,7 +32,7 @@ test({
},
});
-test({
+Deno.test({
name: "process.version",
fn() {
assertEquals(typeof process, "object");
@@ -43,14 +42,14 @@ test({
},
});
-test({
+Deno.test({
name: "process.platform",
fn() {
assertEquals(typeof process.platform, "string");
},
});
-test({
+Deno.test({
name: "process.arch",
fn() {
assertEquals(typeof process.arch, "string");
@@ -59,7 +58,7 @@ test({
},
});
-test({
+Deno.test({
name: "process.pid",
fn() {
assertEquals(typeof process.pid, "number");
@@ -67,7 +66,7 @@ test({
},
});
-test({
+Deno.test({
name: "process.on",
fn() {
assertEquals(typeof process.on, "function");
@@ -81,7 +80,7 @@ test({
},
});
-test({
+Deno.test({
name: "process.argv",
fn() {
assert(Array.isArray(process.argv));
@@ -93,7 +92,7 @@ test({
},
});
-test({
+Deno.test({
name: "process.env",
fn() {
assertEquals(typeof process.env.PATH, "string");
diff --git a/std/node/querystring_test.ts b/std/node/querystring_test.ts
index 0a37eee6b..63abf471b 100644
--- a/std/node/querystring_test.ts
+++ b/std/node/querystring_test.ts
@@ -1,8 +1,7 @@
-const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { stringify, parse } from "./querystring.ts";
-test({
+Deno.test({
name: "stringify",
fn() {
assertEquals(
@@ -17,7 +16,7 @@ test({
},
});
-test({
+Deno.test({
name: "parse",
fn() {
assertEquals(parse("a=hello&b=5&c=true&d=foo&d=bar"), {
diff --git a/std/node/util_test.ts b/std/node/util_test.ts
index b64396441..cedd85a87 100644
--- a/std/node/util_test.ts
+++ b/std/node/util_test.ts
@@ -1,8 +1,7 @@
-const { test } = Deno;
import { assert } from "../testing/asserts.ts";
import * as util from "./util.ts";
-test({
+Deno.test({
name: "[util] isBoolean",
fn() {
assert(util.isBoolean(true));
@@ -14,7 +13,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isNull",
fn() {
let n;
@@ -25,7 +24,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isNullOrUndefined",
fn() {
let n;
@@ -36,7 +35,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isNumber",
fn() {
assert(util.isNumber(666));
@@ -46,7 +45,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isString",
fn() {
assert(util.isString("deno"));
@@ -55,7 +54,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isSymbol",
fn() {
assert(util.isSymbol(Symbol()));
@@ -64,7 +63,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isUndefined",
fn() {
let t;
@@ -74,7 +73,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isObject",
fn() {
const dio = { stand: "Za Warudo" };
@@ -84,7 +83,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isError",
fn() {
const java = new Error();
@@ -96,7 +95,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isFunction",
fn() {
const f = function (): void {};
@@ -106,7 +105,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isRegExp",
fn() {
assert(util.isRegExp(new RegExp(/f/)));
@@ -116,7 +115,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isArray",
fn() {
assert(util.isArray([]));
@@ -125,7 +124,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isPrimitive",
fn() {
const stringType = "hasti";
@@ -149,7 +148,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] TextDecoder",
fn() {
assert(util.TextDecoder === TextDecoder);
@@ -158,7 +157,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] TextEncoder",
fn() {
assert(util.TextEncoder === TextEncoder);
@@ -167,7 +166,7 @@ test({
},
});
-test({
+Deno.test({
name: "[util] isDate",
fn() {
// Test verifies the method is exposed. See _util/_util_types_test for details