-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #689 from novice1993/main
[vscode/engine] getGitLog 함수 관련 테스트 코드 구현
- Loading branch information
Showing
6 changed files
with
255 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const config = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
testPathIgnorePatterns: ["/node_modules/", "/out/"], | ||
verbose: true, | ||
rootDir: "./", | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as cp from "child_process"; | ||
|
||
import { getGitLog } from "../../utils/git.util"; | ||
|
||
const generateMockGitLogData = (index: number) => ` | ||
commit ${index}1234567890abcdef1234567890abcdef${index}5678 (HEAD -> main) | ||
Author: Mock User ${index} <mock${index}@example.com> | ||
AuthorDate: Mon Sep ${index} 21:42:00 2023 +0000 | ||
Commit: Mock Committer ${index} <committer${index}@example.com> | ||
CommitDate: Mon Sep ${index} 21:43:00 2023 +0000 | ||
Commit message ${index} | ||
`; | ||
|
||
jest.mock("child_process"); | ||
const mockSpawn = cp.spawn as jest.Mock; | ||
|
||
let mockSpawnCallCount = 0; | ||
|
||
mockSpawn.mockImplementation(() => { | ||
return { | ||
stdout: { | ||
on: jest.fn((event, callback) => { | ||
if (event === "data") { | ||
const mockData = generateMockGitLogData(mockSpawnCallCount); | ||
callback(Buffer.from(mockData)); | ||
mockSpawnCallCount++; | ||
} | ||
if (event === "close") { | ||
callback(); | ||
} | ||
}), | ||
}, | ||
stderr: { | ||
on: jest.fn((event, callback) => { | ||
callback(Buffer.from("mocked error message")); | ||
}), | ||
}, | ||
on: jest.fn((event, callback) => { | ||
if (event === "exit") { | ||
callback(0); | ||
} | ||
}), | ||
}; | ||
}); | ||
|
||
describe("getGitLog util test", () => { | ||
afterEach(() => { | ||
mockSpawnCallCount = 0; // initailize call count | ||
}); | ||
|
||
it("should return the combined git log output from number of threads", async () => { | ||
const result = await getGitLog("git", "/mocked/path/to/repo"); | ||
|
||
const expectedData = Array.from({ length: mockSpawnCallCount }) // Create an array with length equal to call count | ||
.map((_, index) => generateMockGitLogData(index)) // Insert mock data into the array for each index | ||
.join(""); // Concatenate all mock data into a single string | ||
|
||
return expect(result).toEqual(expectedData); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters