diff options
| author | Casper Beyer <caspervonb@pm.me> | 2021-02-02 19:05:46 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-02 12:05:46 +0100 |
| commit | 6abf126c2a7a451cded8c6b5e6ddf1b69c84055d (patch) | |
| tree | fd94c013a19fcb38954844085821ec1601c20e18 /std/node/_fs/promises | |
| parent | a2b5d44f1aa9d64f448a2a3cc2001272e2f60b98 (diff) | |
chore: remove std directory (#9361)
This removes the std folder from the tree.
Various parts of the tests are pretty tightly dependent
on std (47 direct imports and 75 indirect imports, not
counting the cli tests that use them as fixtures) so I've
added std as a submodule for now.
Diffstat (limited to 'std/node/_fs/promises')
| -rw-r--r-- | std/node/_fs/promises/_fs_readFile.ts | 30 | ||||
| -rw-r--r-- | std/node/_fs/promises/_fs_readFile_test.ts | 62 | ||||
| -rw-r--r-- | std/node/_fs/promises/_fs_writeFile.ts | 18 | ||||
| -rw-r--r-- | std/node/_fs/promises/_fs_writeFile_test.ts | 137 | ||||
| -rw-r--r-- | std/node/_fs/promises/mod.ts | 2 |
5 files changed, 0 insertions, 249 deletions
diff --git a/std/node/_fs/promises/_fs_readFile.ts b/std/node/_fs/promises/_fs_readFile.ts deleted file mode 100644 index 3067b301f..000000000 --- a/std/node/_fs/promises/_fs_readFile.ts +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import type { - BinaryOptionsArgument, - FileOptionsArgument, - TextOptionsArgument, -} from "../_fs_common.ts"; -import { readFile as readFileCallback } from "../_fs_readFile.ts"; - -export function readFile( - path: string | URL, - options: TextOptionsArgument, -): Promise<string>; -export function readFile( - path: string | URL, - options?: BinaryOptionsArgument, -): Promise<Uint8Array>; -export function readFile( - path: string | URL, - options?: FileOptionsArgument, -): Promise<string | Uint8Array> { - return new Promise((resolve, reject) => { - readFileCallback(path, options, (err, data): void => { - if (err) return reject(err); - if (data == null) { - return reject(new Error("Invalid state: data missing, but no error")); - } - resolve(data); - }); - }); -} diff --git a/std/node/_fs/promises/_fs_readFile_test.ts b/std/node/_fs/promises/_fs_readFile_test.ts deleted file mode 100644 index 2810d1773..000000000 --- a/std/node/_fs/promises/_fs_readFile_test.ts +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { readFile } from "./_fs_readFile.ts"; -import * as path from "../../../path/mod.ts"; -import { assert, assertEquals } from "../../../testing/asserts.ts"; - -const moduleDir = path.dirname(path.fromFileUrl(import.meta.url)); -const testData = path.resolve(moduleDir, "..", "testdata", "hello.txt"); - -Deno.test("readFileSuccess", async function () { - const data: Uint8Array = await readFile(testData); - - assert(data instanceof Uint8Array); - assertEquals(new TextDecoder().decode(data), "hello world"); -}); - -Deno.test("readFileBinarySuccess", async function () { - const data: Uint8Array = await readFile(testData, "binary"); - - assert(data instanceof Uint8Array); - assertEquals(new TextDecoder().decode(data), "hello world"); -}); - -Deno.test("readFileBinaryObjectSuccess", async function () { - const data: Uint8Array = await readFile(testData, { encoding: "binary" }); - - assert(data instanceof Uint8Array); - assertEquals(new TextDecoder().decode(data), "hello world"); -}); - -Deno.test("readFileStringObjectSuccess", async function () { - const data: string = await readFile(testData, { encoding: "utf8" }); - - assertEquals(typeof data, "string"); - assertEquals(data, "hello world"); -}); - -Deno.test("readFileEncodeHexSuccess", async function () { - const data: string = await readFile(testData, { encoding: "hex" }); - assertEquals(typeof data, "string"); - assertEquals(data as string, "68656c6c6f20776f726c64"); -}); - -Deno.test("readFileEncodeBase64Success", async function () { - const data: string = await readFile(testData, { encoding: "base64" }); - assertEquals(typeof data, "string"); - assertEquals(data as string, "aGVsbG8gd29ybGQ="); -}); - -Deno.test("readFileStringSuccess", async function () { - const data: string = await readFile(testData, "utf8"); - - assertEquals(typeof data, "string"); - assertEquals(data, "hello world"); -}); - -Deno.test("readFileError", async function () { - try { - await readFile("invalid-file", "utf8"); - } catch (e) { - assert(e instanceof Deno.errors.NotFound); - } -}); diff --git a/std/node/_fs/promises/_fs_writeFile.ts b/std/node/_fs/promises/_fs_writeFile.ts deleted file mode 100644 index 554b65d24..000000000 --- a/std/node/_fs/promises/_fs_writeFile.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import type { WriteFileOptions } from "../_fs_common.ts"; -import type { Encodings } from "../../_utils.ts"; - -import { writeFile as writeFileCallback } from "../_fs_writeFile.ts"; - -export function writeFile( - pathOrRid: string | number | URL, - data: string | Uint8Array, - options?: Encodings | WriteFileOptions, -): Promise<void> { - return new Promise((resolve, reject) => { - writeFileCallback(pathOrRid, data, options, (err?: Error | null) => { - if (err) return reject(err); - resolve(); - }); - }); -} diff --git a/std/node/_fs/promises/_fs_writeFile_test.ts b/std/node/_fs/promises/_fs_writeFile_test.ts deleted file mode 100644 index 644a416ca..000000000 --- a/std/node/_fs/promises/_fs_writeFile_test.ts +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { - assert, - assertEquals, - assertNotEquals, - assertThrowsAsync, -} from "../../../testing/asserts.ts"; -import { writeFile } from "./_fs_writeFile.ts"; -import type { TextEncodings } from "../../_utils.ts"; - -const decoder = new TextDecoder("utf-8"); - -Deno.test("Invalid encoding results in error()", function testEncodingErrors() { - assertThrowsAsync( - async () => { - // @ts-expect-error Type '"made-up-encoding"' is not assignable to type - await writeFile("some/path", "some data", "made-up-encoding"); - }, - Error, - `The value "made-up-encoding" is invalid for option "encoding"`, - ); - assertThrowsAsync( - async () => { - await writeFile("some/path", "some data", { - // @ts-expect-error Type '"made-up-encoding"' is not assignable to type - encoding: "made-up-encoding", - }); - }, - Error, - `The value "made-up-encoding" is invalid for option "encoding"`, - ); -}); - -Deno.test( - "Unsupported encoding results in error()", - function testUnsupportedEncoding() { - assertThrowsAsync( - async () => { - await writeFile("some/path", "some data", "utf16le"); - }, - Error, - `Not implemented: "utf16le" 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( - "Data is written to correct file encodings", - async function testCorrectWritePromiseUsingDifferentEncodings() { - const encodings = [ - ["hex", "68656c6c6f20776f726c64"], - ["HEX", "68656c6c6f20776f726c64"], - ["base64", "aGVsbG8gd29ybGQ="], - ["BASE64", "aGVsbG8gd29ybGQ="], - ["utf8", "hello world"], - ["utf-8", "hello world"], - ]; - - for (const [encoding, value] of encodings) { - await writeFile( - "_fs_writeFile_test_file.txt", - value, - encoding as TextEncodings, - ); - - 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 }); - - const fileInfo = await Deno.stat(filename); - await Deno.remove(filename); - assert(fileInfo && fileInfo.mode); - assertEquals(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/_fs/promises/mod.ts b/std/node/_fs/promises/mod.ts deleted file mode 100644 index 4cc6462b9..000000000 --- a/std/node/_fs/promises/mod.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { writeFile } from "./_fs_writeFile.ts"; -export { readFile } from "./_fs_readFile.ts"; |
