/
_fs_fstat_test.ts
83 lines (75 loc) · 1.98 KB
/
_fs_fstat_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
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { fstat, fstatSync } from "./_fs_fstat.ts";
import { fail } from "../../testing/asserts.ts";
import { assertStats, assertStatsBigInt } from "./_fs_stat_test.ts";
import type { BigIntStats, Stats } from "./_fs_stat.ts";
Deno.test({
name: "ASYNC: get a file Stats",
async fn() {
const file = await Deno.makeTempFile();
const { rid } = await Deno.open(file);
await new Promise<Stats>((resolve, reject) => {
fstat(rid, (err: Error | null, stat: Stats) => {
if (err) reject(err);
resolve(stat);
});
})
.then(
(stat) => {
assertStats(stat, Deno.fstatSync(rid));
},
() => fail(),
)
.finally(() => {
Deno.removeSync(file);
Deno.close(rid);
});
},
});
Deno.test({
name: "ASYNC: get a file BigInt Stats",
async fn() {
const file = await Deno.makeTempFile();
const { rid } = await Deno.open(file);
await new Promise<BigIntStats>((resolve, reject) => {
fstat(rid, { bigint: true }, (err: Error | null, stat: BigIntStats) => {
if (err) reject(err);
resolve(stat);
});
})
.then(
(stat) => assertStatsBigInt(stat, Deno.fstatSync(rid)),
() => fail(),
)
.finally(() => {
Deno.removeSync(file);
Deno.close(rid);
});
},
});
Deno.test({
name: "SYNC: get a file Stats",
fn() {
const file = Deno.makeTempFileSync();
const { rid } = Deno.openSync(file);
try {
assertStats(fstatSync(rid), Deno.fstatSync(rid));
} finally {
Deno.removeSync(file);
Deno.close(rid);
}
},
});
Deno.test({
name: "SYNC: get a file BigInt Stats",
fn() {
const file = Deno.makeTempFileSync();
const { rid } = Deno.openSync(file);
try {
assertStatsBigInt(fstatSync(rid, { bigint: true }), Deno.fstatSync(rid));
} finally {
Deno.removeSync(file);
Deno.close(rid);
}
},
});