Fix unit test & run in CI (#372)
This commit is contained in:
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@@ -49,6 +49,10 @@ jobs:
|
|||||||
# do not run this on windows (it's redunant)
|
# do not run this on windows (it's redunant)
|
||||||
if: contains(matrix.os.name, 'macos')
|
if: contains(matrix.os.name, 'macos')
|
||||||
run: npm run ts
|
run: npm run ts
|
||||||
|
- name: Unit tests
|
||||||
|
# do not run this on windows (it's redunant)
|
||||||
|
if: contains(matrix.os.name, 'macos')
|
||||||
|
run: npm run test
|
||||||
- name: Install Chromium browser for Playwright
|
- name: Install Chromium browser for Playwright
|
||||||
run: npx playwright install chromium --with-deps
|
run: npx playwright install chromium --with-deps
|
||||||
- name: Build
|
- name: Build
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ vi.mock("node:fs", async () => {
|
|||||||
existsSync: vi.fn(),
|
existsSync: vi.fn(),
|
||||||
renameSync: vi.fn(),
|
renameSync: vi.fn(),
|
||||||
unlinkSync: vi.fn(),
|
unlinkSync: vi.fn(),
|
||||||
|
lstatSync: vi.fn().mockReturnValue({ isDirectory: () => false }),
|
||||||
|
promises: {
|
||||||
|
readFile: vi.fn().mockResolvedValue(""),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -29,6 +33,7 @@ vi.mock("isomorphic-git", () => ({
|
|||||||
add: vi.fn().mockResolvedValue(undefined),
|
add: vi.fn().mockResolvedValue(undefined),
|
||||||
remove: vi.fn().mockResolvedValue(undefined),
|
remove: vi.fn().mockResolvedValue(undefined),
|
||||||
commit: vi.fn().mockResolvedValue(undefined),
|
commit: vi.fn().mockResolvedValue(undefined),
|
||||||
|
statusMatrix: vi.fn().mockResolvedValue([]),
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -37,6 +42,7 @@ vi.mock("../paths/paths", () => ({
|
|||||||
getDyadAppPath: vi.fn().mockImplementation((appPath) => {
|
getDyadAppPath: vi.fn().mockImplementation((appPath) => {
|
||||||
return `/mock/user/data/path/${appPath}`;
|
return `/mock/user/data/path/${appPath}`;
|
||||||
}),
|
}),
|
||||||
|
getUserDataPath: vi.fn().mockReturnValue("/mock/user/data/path"),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock db
|
// Mock db
|
||||||
@@ -46,7 +52,15 @@ vi.mock("../db", () => ({
|
|||||||
chats: {
|
chats: {
|
||||||
findFirst: vi.fn(),
|
findFirst: vi.fn(),
|
||||||
},
|
},
|
||||||
|
messages: {
|
||||||
|
findFirst: vi.fn(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
update: vi.fn(() => ({
|
||||||
|
set: vi.fn(() => ({
|
||||||
|
where: vi.fn().mockResolvedValue(undefined),
|
||||||
|
})),
|
||||||
|
})),
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -99,6 +113,7 @@ console.log("TodoItem");
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
path: "src/components/TodoItem.tsx",
|
path: "src/components/TodoItem.tsx",
|
||||||
|
description: "Creating a component for individual todo items",
|
||||||
content: `import React from "react";
|
content: `import React from "react";
|
||||||
console.log("TodoItem");`,
|
console.log("TodoItem");`,
|
||||||
},
|
},
|
||||||
@@ -117,6 +132,7 @@ console.log("TodoItem");
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
path: "src/components/TodoItem.tsx",
|
path: "src/components/TodoItem.tsx",
|
||||||
|
description: "Creating a component for individual todo items",
|
||||||
content: `import React from "react";
|
content: `import React from "react";
|
||||||
console.log("TodoItem");`,
|
console.log("TodoItem");`,
|
||||||
},
|
},
|
||||||
@@ -515,6 +531,16 @@ describe("processFullResponse", () => {
|
|||||||
messages: [],
|
messages: [],
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
vi.mocked(db.query.messages.findFirst).mockResolvedValue({
|
||||||
|
id: 1,
|
||||||
|
chatId: 1,
|
||||||
|
role: "assistant",
|
||||||
|
content: "some content",
|
||||||
|
createdAt: new Date(),
|
||||||
|
approvalState: null,
|
||||||
|
commitHash: null,
|
||||||
|
} as any);
|
||||||
|
|
||||||
// Default mock for existsSync to return true
|
// Default mock for existsSync to return true
|
||||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||||
});
|
});
|
||||||
@@ -528,7 +554,11 @@ describe("processFullResponse", () => {
|
|||||||
messageId: 1,
|
messageId: 1,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
expect(result).toEqual({});
|
expect(result).toEqual({
|
||||||
|
updatedFiles: false,
|
||||||
|
extraFiles: undefined,
|
||||||
|
extraFilesError: undefined,
|
||||||
|
});
|
||||||
expect(fs.mkdirSync).not.toHaveBeenCalled();
|
expect(fs.mkdirSync).not.toHaveBeenCalled();
|
||||||
expect(fs.writeFileSync).not.toHaveBeenCalled();
|
expect(fs.writeFileSync).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -703,7 +733,11 @@ describe("processFullResponse", () => {
|
|||||||
expect(fs.mkdirSync).toHaveBeenCalled();
|
expect(fs.mkdirSync).toHaveBeenCalled();
|
||||||
expect(fs.renameSync).not.toHaveBeenCalled();
|
expect(fs.renameSync).not.toHaveBeenCalled();
|
||||||
expect(git.commit).not.toHaveBeenCalled();
|
expect(git.commit).not.toHaveBeenCalled();
|
||||||
expect(result).toEqual({});
|
expect(result).toEqual({
|
||||||
|
updatedFiles: false,
|
||||||
|
extraFiles: undefined,
|
||||||
|
extraFilesError: undefined,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should process dyad-delete tags and delete files", async () => {
|
it("should process dyad-delete tags and delete files", async () => {
|
||||||
@@ -744,7 +778,11 @@ describe("processFullResponse", () => {
|
|||||||
expect(fs.unlinkSync).not.toHaveBeenCalled();
|
expect(fs.unlinkSync).not.toHaveBeenCalled();
|
||||||
expect(git.remove).not.toHaveBeenCalled();
|
expect(git.remove).not.toHaveBeenCalled();
|
||||||
expect(git.commit).not.toHaveBeenCalled();
|
expect(git.commit).not.toHaveBeenCalled();
|
||||||
expect(result).toEqual({});
|
expect(result).toEqual({
|
||||||
|
updatedFiles: false,
|
||||||
|
extraFiles: undefined,
|
||||||
|
extraFilesError: undefined,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should process mixed operations (write, rename, delete) in one response", async () => {
|
it("should process mixed operations (write, rename, delete) in one response", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user