-
Notifications
You must be signed in to change notification settings - Fork 170
/
lib_fs_test.ts
34 lines (31 loc) · 1.09 KB
/
lib_fs_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
import { assert, assertEquals } from "std/testing/asserts.ts";
import { SEP } from "std/path/separator.ts";
import { existsDir, existsFile } from "../lib/fs.ts";
Deno.test(`lib/fs.ts: existsDir`, async () => {
// true test cases
const dir = await Deno.makeTempDir();
assert(await existsDir(dir));
assert(await existsDir(await Deno.realPath(getStandardFolder())));
// false test cases
const file = await Deno.makeTempFile();
assertEquals(await existsDir(file), false);
assertEquals(await existsDir(`${dir}${SEP}foo${SEP}bar`), false);
});
Deno.test(`lib/fs.ts: existsFile`, async () => {
// true test cases
const file = await Deno.makeTempFile();
assert(await existsFile(file));
// false test cases
const dir = await Deno.makeTempDir();
assert(!await existsFile(`${dir}`));
assert(!await existsFile(`${dir}${SEP}foo${SEP}bar`));
});
/**
* Returns an operating system-specific
* example folder.
* @returns 'C:\Windows' for Windows or
* '/tmp' for unix-based operating systems
*/
const getStandardFolder = () => {
return Deno.build.os === "windows" ? "C:\\Windows" : "/tmp";
};