deno/tests/unit_node/_fs/_fs_mkdir_test.ts
Asher Gomez 92f6188253
chore: use @std import instead of @test_util/std (#22398)
This PR:
1. Replaces `@test_util/std`-prefixed imports with `@std`.
2. Adds `@std/` import map entries to a few `deno.json` files.
2024-02-13 02:05:10 +00:00

44 lines
1.2 KiB
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import * as path from "@std/path/mod.ts";
import { assert } from "@std/assert/mod.ts";
import { assertCallbackErrorUncaught } from "../_test_utils.ts";
import { existsSync, mkdir, mkdirSync } from "node:fs";
const tmpDir = "./tmpdir";
Deno.test({
name: "[node/fs] mkdir",
fn: async () => {
const result = await new Promise((resolve) => {
mkdir(tmpDir, (err) => {
err && resolve(false);
resolve(existsSync(tmpDir));
Deno.removeSync(tmpDir);
});
});
assert(result);
},
});
Deno.test({
name: "[node/fs] mkdirSync",
fn: () => {
mkdirSync(tmpDir);
assert(existsSync(tmpDir));
Deno.removeSync(tmpDir);
},
});
Deno.test("[std/node/fs] mkdir callback isn't called twice if error is thrown", async () => {
const tempDir = await Deno.makeTempDir();
const subdir = path.join(tempDir, "subdir");
const importUrl = new URL("node:fs", import.meta.url);
await assertCallbackErrorUncaught({
prelude: `import { mkdir } from ${JSON.stringify(importUrl)}`,
invocation: `mkdir(${JSON.stringify(subdir)}, `,
async cleanup() {
await Deno.remove(tempDir, { recursive: true });
},
});
});