Skip to content

Commit cbe8860

Browse files
committed
start writing unit tests for local-path fs
1 parent d03d6f9 commit cbe8860

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
import { localPathFileserver } from "../local-path";
2+
import { mkdtemp, rm } from "node:fs/promises";
3+
import { tmpdir } from "node:os";
4+
import { join } from "path";
5+
import { fsClient } from "@cocalc/conat/files/fs";
6+
7+
let tempDir;
8+
beforeAll(async () => {
9+
tempDir = await mkdtemp(join(tmpdir(), "cocalc-local-path"));
10+
});
11+
112
describe("use the simple fileserver", () => {
2-
it("does nothing", async () => {});
13+
let service;
14+
it("creates the simple fileserver service", async () => {
15+
service = await localPathFileserver({ service: "fs", path: tempDir });
16+
});
17+
18+
const project_id = "6b851643-360e-435e-b87e-f9a6ab64a8b1";
19+
let fs;
20+
it("create a client", () => {
21+
fs = fsClient({ subject: `fs.project-${project_id}` });
22+
});
23+
24+
it("checks appendFile works", async () => {
25+
await fs.appendFile("a", "foo");
26+
expect(await fs.readFile("a", "utf8")).toEqual("foo");
27+
});
28+
29+
it("checks chmod works", async () => {
30+
await fs.writeFile("b", "hi");
31+
await fs.chmod("b", 0o755);
32+
const s = await fs.stat("b");
33+
expect(s.mode.toString(8)).toBe("100755");
34+
});
35+
36+
it("closes the service", () => {
37+
service.close();
38+
});
39+
});
40+
41+
afterAll(async () => {
42+
await rm(tempDir, { force: true, recursive: true });
343
});

src/packages/file-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"preinstall": "npx only-allow pnpm",
1313
"build": "pnpm exec tsc --build",
1414
"tsc": "pnpm exec tsc --watch --pretty --preserveWatchOutput",
15-
"test": "pnpm exec jest",
15+
"test": "pnpm exec jest --forceExit",
1616
"depcheck": "pnpx depcheck",
1717
"clean": "rm -rf node_modules dist"
1818
},

0 commit comments

Comments
 (0)