diff options
| author | Louis-Philippe Perron <32278+lp@users.noreply.github.com> | 2020-12-28 15:58:58 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-28 21:58:58 +0100 |
| commit | 34513c032cb96dd9f80647d5d19db5ba55cfdb0b (patch) | |
| tree | 1a82e35daf330371be1352d9336de7d3bb5e1abe /std/node/_fs/_fs_mkdtemp_test.ts | |
| parent | 091059450eab50c1975fb0d3ecd4fcdefcb22b76 (diff) | |
feat(std/node): adds fs.mkdtemp & fs.mkdtempSync (#8604)
Diffstat (limited to 'std/node/_fs/_fs_mkdtemp_test.ts')
| -rw-r--r-- | std/node/_fs/_fs_mkdtemp_test.ts | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/std/node/_fs/_fs_mkdtemp_test.ts b/std/node/_fs/_fs_mkdtemp_test.ts new file mode 100644 index 000000000..c1048acba --- /dev/null +++ b/std/node/_fs/_fs_mkdtemp_test.ts @@ -0,0 +1,121 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import { assert } from "../../testing/asserts.ts"; +import { mkdtemp, mkdtempSync } from "./_fs_mkdtemp.ts"; +import { existsSync } from "./_fs_exists.ts"; +import { env } from "../process.ts"; +import { isWindows } from "../../_util/os.ts"; +import { promisify } from "../_util/_util_promisify.ts"; + +const prefix = isWindows ? env.TEMP + "\\" : (env.TMPDIR || "/tmp") + "/"; +const doesNotExists = "/does/not/exists/"; +const options = { encoding: "ascii" }; +const badOptions = { encoding: "bogus" }; + +const mkdtempP = promisify(mkdtemp); + +Deno.test({ + name: "[node/fs] mkdtemp", + fn: async () => { + try { + const directory = await mkdtempP(prefix); + assert(existsSync(directory)); + Deno.removeSync(directory); + } catch (error) { + assert(false); + } + }, +}); + +Deno.test({ + name: "[node/fs] mkdtemp (does not exists)", + fn: async () => { + try { + const directory = await mkdtempP(doesNotExists); + + // should have thrown already... + assert(!existsSync(directory)); + Deno.removeSync(directory); + } catch (error) { + assert(true); + } + }, +}); + +Deno.test({ + name: "[node/fs] mkdtemp (with options)", + fn: async () => { + try { + const directory = await mkdtempP(prefix, options); + assert(existsSync(directory)); + Deno.removeSync(directory); + } catch (error) { + assert(false); + } + }, +}); + +Deno.test({ + name: "[node/fs] mkdtemp (with bad options)", + fn: async () => { + try { + const directory = await mkdtempP(prefix, badOptions); + + // should have thrown already... + assert(!existsSync(directory)); + Deno.removeSync(directory); + } catch (error) { + assert(true); + } + }, +}); + +Deno.test({ + name: "[node/fs] mkdtempSync", + fn: () => { + const directory = mkdtempSync(prefix); + const dirExists = existsSync(directory); + Deno.removeSync(directory); + assert(dirExists); + }, +}); + +Deno.test({ + name: "[node/fs] mkdtempSync (does not exists)", + fn: () => { + try { + const directory = mkdtempSync(doesNotExists); + // should have thrown already... + + const dirExists = existsSync(directory); + Deno.removeSync(directory); + assert(!dirExists); + } catch (error) { + assert(true); + } + }, +}); + +Deno.test({ + name: "[node/fs] mkdtempSync (with options)", + fn: () => { + const directory = mkdtempSync(prefix, options); + const dirExists = existsSync(directory); + Deno.removeSync(directory); + assert(dirExists); + }, +}); + +Deno.test({ + name: "[node/fs] mkdtempSync (with bad options)", + fn: () => { + try { + const directory = mkdtempSync(prefix, badOptions); + // should have thrown already... + + Deno.removeSync(directory); + assert(false); + } catch (error) { + assert(true); + } + }, +}); |
