-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vscode/engine] getGitLog 함수 관련 테스트 코드 구현 #689
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fe6865a
chore: vscode 패캐지에 jest 설치 및 jest.config 설정
2ea6056
Merge branch 'main' of github.com:novice1993/githru-vscode-ext
8df2ea5
chore: getGitLog 함수 관련 테스트 코드 작성
151c18f
chore: 테스트용 .git 데이터 압축 파일로 추가 (nginx)
2f1d805
chore: getGitLog 관련 테스트 코드 수정
d0ff9ff
feat: getGitLog 테스트 코드 구현
2aa037b
Merge pull request #1 from novice1993/test-repo
novice1993 d78b457
Merge branch 'main' of github.com:githru/githru-vscode-ext
52473ea
chore: package-lock.json 버전 수정
214c69d
chore: jest.config.ts 옵션 수정 (rootDir)
novice1993 17dfbc6
chore: package.json 스크립트 수정 (test 스크립트 설정)
novice1993 d68166a
refactor: getGitLog.ts 관련 테스트 코드 수정
novice1993 a63954c
chore: jest.config.ts 옵션 수정
novice1993 6ef09c3
chore: 사용하지 않는 테스트 파일 확장자 변경
novice1993 ffd514c
chore: 불필요한 코드 제거
novice1993 f55b7eb
chore: tsconfig.json 설전 변경
b27c819
feat: getGitLog 테스트 코드 수정
07f0c21
feat: getGitLog 테스트 코드 수정 (멀티 쓰레드/프로세스 활용 시 테스트 가능하도록)
24d53e9
chore: getGitLog 테스트 설명 문구 수정
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😊👍 |
||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗. 이 부분은 바로 상대경로를 쓰는게 아니라, engine pkg lib를 import 해서 쓰셔야 해요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
�넵 해당 부분 수정하도록 하겠습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ytaek
영택님 코멘트 주셨던 부분 중 아래의 2가지는 수정하여 반영하였는데
해당 이슈 (engine 모듈 import 수정) 는 어떻게 해결해야할지 잘 모르습니다..!
getGitLog 함수를 "@githru-vscode-ext/analysis-engine"에서 import 하려고 하니,
해당 패키지에서 export 하지 않는다고 나오는 상황입니다!
getGitLog 함수는 vscode/src/utils/git.util.ts 파일에서 선언된 함수라서 상대 경로로 import 하는 게 맞지 않나 생각이 되는데
(https://github.com/githru/githru-vscode-ext/blob/main/packages/vscode/src/utils/git.util.ts)
혹시 제가 잘못 이해하고 있는 거라면 어떻게 수정하는게 좋을지 코멘트 부탁드립니다..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헉... 제가 상대경로 위치를 잘 못 봣었네요 ㅜ.ㅜ 죄송합니당.
../../
부분이 package 바깥으로 가는 경로인 걸로 착각했습니다 😭😭😭😭😭