summaryrefslogtreecommitdiff
path: root/std/node/_fs/_fs_mkdtemp_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/node/_fs/_fs_mkdtemp_test.ts')
-rw-r--r--std/node/_fs/_fs_mkdtemp_test.ts121
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);
+ }
+ },
+});