summaryrefslogtreecommitdiff
path: root/js/mkdir_test.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-01-17 23:39:06 -0500
committerGitHub <noreply@github.com>2019-01-17 23:39:06 -0500
commit315e4abd7e88c428e78c006ccf2dfdb499911a05 (patch)
treeb48136d6f0437374c5c0a9a8f717f7495b5ff808 /js/mkdir_test.ts
parentd06c95637a2a19588fcb549ed7b760a916b3cbfd (diff)
mkdir should not be recursive by default (#1530)
It should return an error if a file with the given path exists and recursive isn't specified. Because mode is not used on windows and rarely used in unix, it is made to the last parameter. In collaboration with Stefan Dombrowski <sdo451@gmail.com>
Diffstat (limited to 'js/mkdir_test.ts')
-rw-r--r--js/mkdir_test.ts33
1 files changed, 29 insertions, 4 deletions
diff --git a/js/mkdir_test.ts b/js/mkdir_test.ts
index ea6028c9e..963f73806 100644
--- a/js/mkdir_test.ts
+++ b/js/mkdir_test.ts
@@ -3,15 +3,15 @@ import { testPerm, assert, assertEqual } from "./test_util.ts";
import * as deno from "deno";
testPerm({ write: true }, function mkdirSyncSuccess() {
- const path = deno.makeTempDirSync() + "/dir/subdir";
+ const path = deno.makeTempDirSync() + "/dir";
deno.mkdirSync(path);
const pathInfo = deno.statSync(path);
assert(pathInfo.isDirectory());
});
testPerm({ write: true }, function mkdirSyncMode() {
- const path = deno.makeTempDirSync() + "/dir/subdir";
- deno.mkdirSync(path, 0o755); // no perm for x
+ const path = deno.makeTempDirSync() + "/dir";
+ deno.mkdirSync(path, false, 0o755); // no perm for x
const pathInfo = deno.statSync(path);
if (pathInfo.mode !== null) {
// Skip windows
@@ -31,8 +31,33 @@ testPerm({ write: false }, function mkdirSyncPerm() {
});
testPerm({ write: true }, async function mkdirSuccess() {
- const path = deno.makeTempDirSync() + "/dir/subdir";
+ const path = deno.makeTempDirSync() + "/dir";
await deno.mkdir(path);
const pathInfo = deno.statSync(path);
assert(pathInfo.isDirectory());
});
+
+testPerm({ write: true }, function mkdirErrIfExists() {
+ let err;
+ try {
+ deno.mkdirSync(".");
+ } catch (e) {
+ err = e;
+ }
+ assertEqual(err.kind, deno.ErrorKind.AlreadyExists);
+ assertEqual(err.name, "AlreadyExists");
+});
+
+testPerm({ write: true }, function mkdirSyncRecursive() {
+ const path = deno.makeTempDirSync() + "/nested/directory";
+ deno.mkdirSync(path, true);
+ const pathInfo = deno.statSync(path);
+ assert(pathInfo.isDirectory());
+});
+
+testPerm({ write: true }, async function mkdirRecursive() {
+ const path = deno.makeTempDirSync() + "/nested/directory";
+ await deno.mkdir(path, true);
+ const pathInfo = deno.statSync(path);
+ assert(pathInfo.isDirectory());
+});