-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsimple-git-fetcher.test.ts
More file actions
89 lines (73 loc) · 2.66 KB
/
simple-git-fetcher.test.ts
File metadata and controls
89 lines (73 loc) · 2.66 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import { SimpleGitFetcher } from "../src/utils/download-repo";
import { downloadRepo } from "@begit/core";
import { existsSync, rmSync, mkdirSync } from "fs";
import { join } from "path";
const TEST_DIR = "./test-simple-git-fetcher";
describe("SimpleGitFetcher", () => {
beforeAll(() => {
// Clean up test directory before tests
if (existsSync(TEST_DIR)) {
rmSync(TEST_DIR, { recursive: true, force: true });
}
mkdirSync(TEST_DIR, { recursive: true });
});
afterAll(() => {
// Clean up test directory after tests
if (existsSync(TEST_DIR)) {
rmSync(TEST_DIR, { recursive: true, force: true });
}
});
describe("fetchLatestCommit", () => {
it("should fetch the latest commit hash", async () => {
const repo = { owner: "solidjs", name: "templates" };
const commit = await SimpleGitFetcher.fetchLatestCommit(repo);
expect(typeof commit).toBe("string");
expect(commit.length).toBeGreaterThanOrEqual(7);
expect(commit).toMatch(/^[a-f0-9]+$/);
}, 30000);
it("should fetch commit for a specific branch", async () => {
const repo = { owner: "solidjs", name: "templates", branch: "main" };
const commit = await SimpleGitFetcher.fetchLatestCommit(repo);
expect(typeof commit).toBe("string");
expect(commit).toMatch(/^[a-f0-9]+$/);
}, 30000);
it("should throw for non-existent repo", async () => {
const repo = { owner: "solidjs", name: "non-existent-repo-12345" };
await expect(SimpleGitFetcher.fetchLatestCommit(repo)).rejects.toThrow();
}, 30000);
});
describe("fetchTarball", () => {
it("should return a valid tarball object", async () => {
const repo = { owner: "solidjs", name: "templates" };
const tarball = await SimpleGitFetcher.fetchTarball(repo);
expect(tarball).toBeDefined();
expect(typeof tarball.name).toBe("string");
expect(tarball.name).toContain("solidjs");
expect(tarball.name.endsWith(".tar.gz")).toBe(true);
expect(tarball.body).toBeDefined();
// Clean up - cancel the stream
await tarball.body.cancel();
}, 120000);
});
describe("integration with downloadRepo", () => {
it("should download a repository subdirectory using SimpleGitFetcher", async () => {
const dest = join(TEST_DIR, "vanilla-basic");
await downloadRepo(
{
repo: {
owner: "solidjs",
name: "templates",
subdir: "vanilla/basic",
},
dest,
},
SimpleGitFetcher,
);
// Verify key files exist
expect(existsSync(dest)).toBe(true);
expect(existsSync(join(dest, "package.json"))).toBe(true);
expect(existsSync(join(dest, "src"))).toBe(true);
}, 120000); // 2 minute timeout for full download
});
});