summaryrefslogtreecommitdiff
path: root/fs/mkdirp_test.ts
blob: a3a4fac037905ee2b7fffc35a50311abd11fffad (plain)
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
import { cwd, lstat, makeTempDirSync, removeAll, FileInfo } from "deno";
import { test, assert } from "../testing/mod.ts";
import { mkdirp } from "./mkdirp.ts";

let root: string = `${cwd()}/${Date.now()}`; //makeTempDirSync();

test(async function createsNestedDirs(): Promise<void> {
  const leaf: string = `${root}/levelx/levely`;
  await mkdirp(leaf);
  const info: FileInfo = await lstat(leaf);
  assert(info.isDirectory());
  await removeAll(root);
});

test(async function handlesAnyPathSeparator(): Promise<void> {
  const leaf: string = `${root}\\levelx\\levely`;
  await mkdirp(leaf);
  const info: FileInfo = await lstat(leaf.replace(/\\/g, "/"));
  assert(info.isDirectory());
  await removeAll(root);
});

test(async function failsNonDir(): Promise<void> {
  try {
    await mkdirp("./test.ts/fest.fs");
  } catch (err) {
    // TODO: assert caught DenoError of kind NOT_A_DIRECTORY or similar
    assert(err);
  }
});