-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.test.ts
More file actions
67 lines (53 loc) · 2.3 KB
/
Copy pathtest.test.ts
File metadata and controls
67 lines (53 loc) · 2.3 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { test, expect } from "bun:test";
import { execSync } from "child_process";
import { existsSync, mkdirSync, writeFileSync, rmSync } from "fs";
import { join } from "path";
test("zig-asar CLI is available", () => {
const result = execSync("zig-out/bin/zig-asar").toString();
expect(result).toContain("zig-asar - ASAR archive tool");
});
test("pack and extract basic archive", () => {
const testDir = "/tmp/zig-asar-test";
const asarPath = "/tmp/test-archive.asar";
// Clean up
if (existsSync(testDir)) rmSync(testDir, { recursive: true });
if (existsSync(asarPath)) rmSync(asarPath);
// Create test files
mkdirSync(testDir, { recursive: true });
mkdirSync(join(testDir, "subdir"), { recursive: true });
writeFileSync(join(testDir, "test.txt"), "Hello ASAR!");
writeFileSync(join(testDir, "subdir", "nested.txt"), "Nested content");
// Pack
execSync(`zig-out/bin/zig-asar pack ${testDir} ${asarPath}`);
expect(existsSync(asarPath)).toBe(true);
// Extract and verify
const extracted = execSync(`zig-out/bin/zig-asar extract ${asarPath} test.txt`).toString();
expect(extracted).toBe("Hello ASAR!");
const extractedNested = execSync(`zig-out/bin/zig-asar extract ${asarPath} subdir/nested.txt`).toString();
expect(extractedNested).toBe("Nested content");
// Clean up
rmSync(testDir, { recursive: true });
rmSync(asarPath);
});
test("unpack pattern excludes files", () => {
const testDir = "/tmp/zig-asar-unpack-test";
const asarPath = "/tmp/test-unpack.asar";
const unpackedDir = asarPath + ".unpacked";
// Clean up
if (existsSync(testDir)) rmSync(testDir, { recursive: true });
if (existsSync(asarPath)) rmSync(asarPath);
if (existsSync(unpackedDir)) rmSync(unpackedDir, { recursive: true });
// Create test files
mkdirSync(testDir, { recursive: true });
writeFileSync(join(testDir, "regular.txt"), "Regular file");
writeFileSync(join(testDir, "native.node"), "Native module");
// Pack with unpack pattern
execSync(`zig-out/bin/zig-asar pack ${testDir} ${asarPath} --unpack "*.node"`);
expect(existsSync(asarPath)).toBe(true);
expect(existsSync(unpackedDir)).toBe(true);
expect(existsSync(join(unpackedDir, "native.node"))).toBe(true);
// Clean up
rmSync(testDir, { recursive: true });
rmSync(asarPath);
rmSync(unpackedDir, { recursive: true });
});