blob: b06670b6c74a034ce84fd76b37ed4afe3bc919a0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import path from "path";
import { isWriteable } from "../src/utils/isWriteable";
import { setupTestFixtures } from "@turbo/test-utils";
import fs from "fs-extra";
describe("isWriteable", () => {
const { useFixture } = setupTestFixtures({
directory: path.join(__dirname, "../"),
});
it("correctly identifies a writeable directory", async () => {
const { root } = useFixture({ fixture: `is-writeable` });
const result = await isWriteable(root);
expect(result).toEqual(true);
});
it("correctly identifies a non-writeable directory", async () => {
const { root } = useFixture({ fixture: `is-writeable` });
const result = await isWriteable(path.join(root, "does-not-exist"));
expect(result).toEqual(false);
});
it("returns false on unexpected failure", async () => {
const { root } = useFixture({ fixture: `is-writeable` });
const mockFsAccess = jest
.spyOn(fs, "access")
.mockRejectedValue(new Error("unknown error"));
const result = await isWriteable(root);
expect(result).toEqual(false);
expect(mockFsAccess).toHaveBeenCalledWith(root, fs.constants.W_OK);
mockFsAccess.mockRestore();
});
});
|