deno.land / std@0.166.0 / node / _fs / _fs_opendir_test.ts

_fs_opendir_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertFalse, assertInstanceOf, assertThrows,} from "../../testing/asserts.ts";import { opendir, opendirSync } from "./_fs_opendir.ts";import { Buffer } from "../buffer.ts";import { assertCallbackErrorUncaught } from "../_test_utils.ts";
Deno.test("[node/fs] opendir()", async (t) => { const path = await Deno.makeTempDir(); const file = await Deno.makeTempFile();
await t.step( "fails if encoding is invalid", () => opendir( path, { encoding: "invalid-encoding" }, (err) => assertInstanceOf(err, TypeError), ), );
await t.step( "fails if bufferSize is invalid", () => opendir( path, { bufferSize: -1 }, (err) => assertInstanceOf(err, RangeError), ), );
await t.step( "fails if directory does not exist", () => opendir( "directory-that-does-not-exist", (err) => assertInstanceOf(err, Error), ), );
await t.step( "fails if not a directory", () => opendir( file, (err) => assertInstanceOf(err, Error), ), );
await t.step( "passes if path is a string", () => opendir( path, (err, dir) => { assertEquals(err, null); assert(dir); }, ), );
await t.step( "passes if path is a Buffer", () => opendir( Buffer.from(path), (err, dir) => { assertFalse(err); assert(dir); }, ), );
await t.step( "passes if path is a URL", () => opendir( new URL(`file://` + path), (err, dir) => { assertFalse(err); assert(dir); }, ), );
await t.step("passes if callback isn't called twice", async () => { const importUrl = new URL("./_fs_opendir.ts", import.meta.url); await assertCallbackErrorUncaught({ prelude: `import { opendir } from ${JSON.stringify(importUrl)}`, invocation: `opendir(${JSON.stringify(path)}, `, }); });
await Deno.remove(path); await Deno.remove(file);});
Deno.test("[node/fs] opendirSync()", async (t) => { const path = await Deno.makeTempDir(); const file = await Deno.makeTempFile();
await t.step("fails if encoding is invalid", () => { assertThrows( () => opendirSync(path, { encoding: "invalid-encoding" }), TypeError, ); });
await t.step("fails if bufferSize is invalid", () => { assertThrows( () => opendirSync(path, { bufferSize: -1 }), RangeError, ); });
await t.step("fails if directory does not exist", () => { assertThrows(() => opendirSync("directory-that-does-not-exist")); });
await t.step("fails if not a directory", () => { assertThrows(() => opendirSync(file)); });
await t.step("passes if path is a string", () => { assert(opendirSync(path)); });
await t.step("passes if path is a Buffer", () => { assert(opendirSync(Buffer.from(path))); });
await t.step("passes if path is a URL", () => { assert(opendirSync(new URL(`file://` + path))); });
await Deno.remove(path); await Deno.remove(file);});
std

Version Info

Tagged at
a year ago