Skip to content

Commit

Permalink
Merge pull request #708 from yoouyeon/main
Browse files Browse the repository at this point in the history
[engine] getCommitRaws 테스트코드 보완
  • Loading branch information
yoouyeon authored Sep 9, 2024
2 parents aaf3fbc + 28fb5e8 commit 44bc322
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions packages/analysis-engine/src/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,17 @@ describe("commit message type", () => {
});

describe("getCommitRaws", () => {
const testAuthorCommitter = [
"John Park",
"mail@gmail.com",
"Sun Sep 4 20:17:59 2022 +0900",
"John Park 2",
"mail2@gmail.com",
"Sun Sep 5 20:17:59 2022 +0900",
];

const testRefs = [
"HEAD",
"HEAD -> main, origin/main, origin/HEAD",
"HEAD, tag: v1.0.0",
"HEAD -> main, origin/main, origin/HEAD, tag: v2.0.0",
"HEAD, tag: v2.0.0, tag: v1.4",
];
const testAuthorAndCommitter = `${GIT_LOG_SEPARATOR}John Park${GIT_LOG_SEPARATOR}mail@gmail.com${GIT_LOG_SEPARATOR}Sun Sep 4 20:17:59 2022 +0900${GIT_LOG_SEPARATOR}John Park 2${GIT_LOG_SEPARATOR}mail2@gmail.com${GIT_LOG_SEPARATOR}Sun Sep 5 20:17:59 2022 +0900`;

const testCommitHash = ["a", "b"];
const testCommitMessage = `${GIT_LOG_SEPARATOR}commit message`;

const testCommitMessage = "commit message";

const testCommitLines = testRefs.map((ref) =>
[...testCommitHash, ref, ...testAuthorCommitter, testCommitMessage].join(GIT_LOG_SEPARATOR)
);
const testCommitHashAndRefs = [
`a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD`,
`a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD -> main, origin/main, origin/HEAD`,
`a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD, tag: v1.0.0`,
`a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD -> main, origin/main, origin/HEAD, tag: v2.0.0`,
`a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD, tag: v2.0.0, tag: v1.4`,
];

const expectedBranches = [
["HEAD"],
Expand Down Expand Up @@ -114,11 +101,11 @@ describe("getCommitRaws", () => {
parents: ["b"],
branches: ["HEAD"],
tags: [],
author: { name: testAuthorCommitter[0], email: testAuthorCommitter[1] },
authorDate: new Date(testAuthorCommitter[2]),
committer: { name: testAuthorCommitter[3], email: testAuthorCommitter[4] },
committerDate: new Date(testAuthorCommitter[5]),
message: testCommitMessage,
author: { name: "John Park", email: "mail@gmail.com" },
authorDate: new Date("Sun Sep 4 20:17:59 2022 +0900"),
committer: { name: "John Park 2", email: "mail2@gmail.com" },
committerDate: new Date("Sun Sep 5 20:17:59 2022 +0900"),
message: "commit message",
differenceStatistic: {
totalInsertionCount: 0,
totalDeletionCount: 0,
Expand All @@ -127,9 +114,9 @@ describe("getCommitRaws", () => {
commitMessageType: "",
};

testCommitLines.forEach((mockLog, index) => {
testCommitHashAndRefs.forEach((hashAndRefs, index) => {
it(`should parse gitlog to commitRaw(branch, tag)`, () => {
const result = getCommitRaws(COMMIT_SEPARATOR + mockLog);
const result = getCommitRaws(`${COMMIT_SEPARATOR}${hashAndRefs}${testAuthorAndCommitter}${testCommitMessage}`);
const expectedResult = {
...commonExpectatedResult,
branches: expectedBranches[index],
Expand All @@ -140,9 +127,9 @@ describe("getCommitRaws", () => {
});
});

testCommitFileChanges.forEach((mockLog, index) => {
testCommitFileChanges.forEach((fileChange, index) => {
it(`should parse gitlog to commitRaw(file changed)`, () => {
const mock = `${COMMIT_SEPARATOR}${testCommitLines[0]}\n${mockLog}`;
const mock = `${COMMIT_SEPARATOR}${testCommitHashAndRefs[0]}${testAuthorAndCommitter}${testCommitMessage}\n${fileChange}`;
const result = getCommitRaws(mock);
const expectedResult = { ...commonExpectatedResult, differenceStatistic: expectedFileChanged[index] };

Expand Down

0 comments on commit 44bc322

Please sign in to comment.