Skip to content

Commit

Permalink
test(engine) : 재사용 가능한 테스트코드 상수화
Browse files Browse the repository at this point in the history
  • Loading branch information
yoouyeon committed Sep 5, 2024
1 parent 3051635 commit f29fd92
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/analysis-engine/src/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ describe("commit message type", () => {
});

describe("getCommitRaws", () => {
const testCommitLines = [
`${COMMIT_SEPARATOR}a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD${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${GIT_LOG_SEPARATOR}commit message`,
`${COMMIT_SEPARATOR}a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD -> main, origin/main, origin/HEAD${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${GIT_LOG_SEPARATOR}commit message`,
`${COMMIT_SEPARATOR}a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD, tag: v1.0.0${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${GIT_LOG_SEPARATOR}commit message`,
`${COMMIT_SEPARATOR}a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD -> main, origin/main, origin/HEAD, tag: v2.0.0${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${GIT_LOG_SEPARATOR}commit message`,
`${COMMIT_SEPARATOR}a${GIT_LOG_SEPARATOR}b${GIT_LOG_SEPARATOR}HEAD, tag: v2.0.0, tag: v1.4${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${GIT_LOG_SEPARATOR}commit message`,
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 testCommitMessage = `${GIT_LOG_SEPARATOR}commit message`;

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 = [
Expand Down Expand Up @@ -110,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(mockLog);
const result = getCommitRaws(`${COMMIT_SEPARATOR}${hashAndRefs}${testAuthorAndCommitter}${testCommitMessage}`);
const expectedResult = {
...commonExpectatedResult,
branches: expectedBranches[index],
Expand All @@ -125,7 +129,7 @@ describe("getCommitRaws", () => {

testCommitFileChanges.forEach((mockLog, 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${mockLog}`;
const result = getCommitRaws(mock);
const expectedResult = { ...commonExpectatedResult, differenceStatistic: expectedFileChanged[index] };

Expand Down

0 comments on commit f29fd92

Please sign in to comment.