Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zanminkian committed Apr 19, 2024
1 parent 58288c8 commit 886cb8f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@changesets/cli": "2.27.1",
"git-validator": "0.15.12",
"git-validator": "0.15.13",
"typescript": "5.4.5",
"vitest": "1.5.0"
},
Expand Down
39 changes: 39 additions & 0 deletions packages/tscx/src/cmd/remove.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { remove } from "./remove.js";

const TMP = os.tmpdir();
const tmpFilePath = path.resolve(TMP, "tscx_tmp_file_name");
const tmpDirPath = path.resolve(TMP, "tscx_tmp_dir_name");
const tmpDirPathChild = path.resolve(tmpDirPath, "tscx_tmp_dir_name_child");

describe("remove", () => {
beforeAll(async () => {
await fs.writeFile(tmpFilePath, "foo");

await fs.mkdir(tmpDirPath);
await fs.mkdir(tmpDirPathChild);
await fs.writeFile(path.resolve(tmpDirPathChild, "file"), "bar");
});

afterAll(async () => {
await fs.rm(tmpFilePath, { force: true });
await fs.rm(tmpDirPath, { force: true, recursive: true });
});

it("should remove file", async () => {
expect((await fs.stat(tmpFilePath)).isFile()).toBe(true);
expect(fs.access(tmpFilePath)).resolves.toBeUndefined();
await remove(tmpFilePath);
expect(fs.access(tmpFilePath)).rejects.toBeInstanceOf(Error);
});

it("show remove dir", async () => {
expect((await fs.stat(tmpDirPath)).isDirectory()).toBe(true);
expect(fs.access(tmpDirPath)).resolves.toBeUndefined();
await remove(tmpDirPath);
expect(fs.access(tmpDirPath)).rejects.toBeInstanceOf(Error);
});
});

0 comments on commit 886cb8f

Please sign in to comment.