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

_fs_readlink_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
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.import { assertCallbackErrorUncaught } from "../_test_utils.ts";import { readlink, readlinkSync } from "./_fs_readlink.ts";import { assert, assertEquals } from "../../testing/asserts.ts";import * as path from "../path.ts";import { isWindows } from "../../_util/os.ts";
const testDir = Deno.makeTempDirSync();const oldname = path.join(testDir, "oldname");const newname = path.join(testDir, "newname");
if (isWindows) { Deno.symlinkSync(oldname, newname, { type: "file" });} else { Deno.symlinkSync(oldname, newname);}
Deno.test({ name: "readlinkSuccess", async fn() { const data = await new Promise((res, rej) => { readlink(newname, (err, data) => { if (err) { rej(err); } res(data); }); });
assertEquals(typeof data, "string"); assertEquals(data as string, oldname); },});
Deno.test({ name: "readlinkEncodeBufferSuccess", async fn() { const data = await new Promise((res, rej) => { readlink(newname, { encoding: "buffer" }, (err, data) => { if (err) { rej(err); } res(data); }); });
assert(data instanceof Uint8Array); assertEquals(new TextDecoder().decode(data as Uint8Array), oldname); },});
Deno.test({ name: "readlinkSyncSuccess", fn() { const data = readlinkSync(newname); assertEquals(typeof data, "string"); assertEquals(data as string, oldname); },});
Deno.test({ name: "readlinkEncodeBufferSuccess", fn() { const data = readlinkSync(newname, { encoding: "buffer" }); assert(data instanceof Uint8Array); assertEquals(new TextDecoder().decode(data as Uint8Array), oldname); },});
Deno.test("[std/node/fs] readlink callback isn't called twice if error is thrown", async () => { const importUrl = new URL("./_fs_readlink.ts", import.meta.url); await assertCallbackErrorUncaught({ prelude: `import { readlink } from ${JSON.stringify(importUrl)}`, invocation: `readlink(${JSON.stringify(newname)}, `, });});
std

Version Info

Tagged at
a year ago