Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
test(Release): add tests for commit and version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsKoud committed Jun 22, 2023
1 parent 11c6f22 commit a37132f
Show file tree
Hide file tree
Showing 4 changed files with 403 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/release/tests/commit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Commit, type CommitParserResult } from "../src/index.js";
import { fixScopeMockCommit, fixMockCommit, featBreakingMockCommit } from "./mockdata.js";

/** Checks whether the input is a class or not */
function isClass(input: unknown) {
return typeof input === "function" && typeof input.prototype === "object";
}

describe("Commit", () => {
test("Commit should be a class", () => {
expect(isClass(Commit)).toBe(true);
});

test("constructor", () => {
const commit = new Commit(fixMockCommit);
expect(commit.data).toStrictEqual(fixMockCommit);
});

test("parse: scope", () => {
const commit = new Commit(fixScopeMockCommit);
expect(commit.parse()).toStrictEqual<CommitParserResult>({
breaking: false,
merge: false,
message: "all the bugs",
type: "fix",
scope: "Manager"
});
});

test("parse: breaking", () => {
const commit = new Commit(featBreakingMockCommit);
expect(commit.parse()).toStrictEqual<CommitParserResult>({
breaking: true,
merge: false,
message: "add better caching",
type: "feat",
scope: "Manager"
});
});
});
315 changes: 315 additions & 0 deletions packages/release/tests/mockdata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
export const fixMockCommit = {
url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e",
node_id: "MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ==",
html_url: "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
comments_url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
commit: {
url: "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
author: {
name: "Monalisa Octocat",
email: "[email protected]",
date: "2011-04-14T16:00:49Z"
},
committer: {
name: "Monalisa Octocat",
email: "[email protected]",
date: "2011-04-14T16:00:49Z"
},
message: "fix: all the bugs",
tree: {
url: "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e"
},
comment_count: 0,
verification: {
verified: false,
reason: "unsigned",
signature: null,
payload: null
}
},
author: {
login: "octocat",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/octocat_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/octocat",
html_url: "https://github.com/octocat",
followers_url: "https://api.github.com/users/octocat/followers",
following_url: "https://api.github.com/users/octocat/following{/other_user}",
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
organizations_url: "https://api.github.com/users/octocat/orgs",
repos_url: "https://api.github.com/users/octocat/repos",
events_url: "https://api.github.com/users/octocat/events{/privacy}",
received_events_url: "https://api.github.com/users/octocat/received_events",
type: "User",
site_admin: false
},
committer: {
login: "octocat",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/octocat_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/octocat",
html_url: "https://github.com/octocat",
followers_url: "https://api.github.com/users/octocat/followers",
following_url: "https://api.github.com/users/octocat/following{/other_user}",
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
organizations_url: "https://api.github.com/users/octocat/orgs",
repos_url: "https://api.github.com/users/octocat/repos",
events_url: "https://api.github.com/users/octocat/events{/privacy}",
received_events_url: "https://api.github.com/users/octocat/received_events",
type: "User",
site_admin: false
},
parents: [
{
url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
]
};

export const fixScopeMockCommit = {
url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e",
node_id: "MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ==",
html_url: "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
comments_url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
commit: {
url: "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
author: {
name: "Monalisa Octocat",
email: "[email protected]",
date: "2011-04-14T16:00:49Z"
},
committer: {
name: "Monalisa Octocat",
email: "[email protected]",
date: "2011-04-14T16:00:49Z"
},
message: "fix(Manager): all the bugs",
tree: {
url: "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e"
},
comment_count: 0,
verification: {
verified: false,
reason: "unsigned",
signature: null,
payload: null
}
},
author: {
login: "octocat",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/octocat_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/octocat",
html_url: "https://github.com/octocat",
followers_url: "https://api.github.com/users/octocat/followers",
following_url: "https://api.github.com/users/octocat/following{/other_user}",
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
organizations_url: "https://api.github.com/users/octocat/orgs",
repos_url: "https://api.github.com/users/octocat/repos",
events_url: "https://api.github.com/users/octocat/events{/privacy}",
received_events_url: "https://api.github.com/users/octocat/received_events",
type: "User",
site_admin: false
},
committer: {
login: "octocat",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/octocat_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/octocat",
html_url: "https://github.com/octocat",
followers_url: "https://api.github.com/users/octocat/followers",
following_url: "https://api.github.com/users/octocat/following{/other_user}",
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
organizations_url: "https://api.github.com/users/octocat/orgs",
repos_url: "https://api.github.com/users/octocat/repos",
events_url: "https://api.github.com/users/octocat/events{/privacy}",
received_events_url: "https://api.github.com/users/octocat/received_events",
type: "User",
site_admin: false
},
parents: [
{
url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
]
};

export const featScopeMockCommit = {
url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e",
node_id: "MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ==",
html_url: "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
comments_url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
commit: {
url: "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
author: {
name: "Monalisa Octocat",
email: "[email protected]",
date: "2011-04-14T16:00:49Z"
},
committer: {
name: "Monalisa Octocat",
email: "[email protected]",
date: "2011-04-14T16:00:49Z"
},
message: "feat(Manager): add better caching",
tree: {
url: "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e"
},
comment_count: 0,
verification: {
verified: false,
reason: "unsigned",
signature: null,
payload: null
}
},
author: {
login: "octocat",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/octocat_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/octocat",
html_url: "https://github.com/octocat",
followers_url: "https://api.github.com/users/octocat/followers",
following_url: "https://api.github.com/users/octocat/following{/other_user}",
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
organizations_url: "https://api.github.com/users/octocat/orgs",
repos_url: "https://api.github.com/users/octocat/repos",
events_url: "https://api.github.com/users/octocat/events{/privacy}",
received_events_url: "https://api.github.com/users/octocat/received_events",
type: "User",
site_admin: false
},
committer: {
login: "octocat",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/octocat_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/octocat",
html_url: "https://github.com/octocat",
followers_url: "https://api.github.com/users/octocat/followers",
following_url: "https://api.github.com/users/octocat/following{/other_user}",
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
organizations_url: "https://api.github.com/users/octocat/orgs",
repos_url: "https://api.github.com/users/octocat/repos",
events_url: "https://api.github.com/users/octocat/events{/privacy}",
received_events_url: "https://api.github.com/users/octocat/received_events",
type: "User",
site_admin: false
},
parents: [
{
url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
]
};

export const featBreakingMockCommit = {
url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e",
node_id: "MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ==",
html_url: "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
comments_url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
commit: {
url: "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
author: {
name: "Monalisa Octocat",
email: "[email protected]",
date: "2011-04-14T16:00:49Z"
},
committer: {
name: "Monalisa Octocat",
email: "[email protected]",
date: "2011-04-14T16:00:49Z"
},
message: "feat(Manager)!: add better caching",
tree: {
url: "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e"
},
comment_count: 0,
verification: {
verified: false,
reason: "unsigned",
signature: null,
payload: null
}
},
author: {
login: "octocat",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/octocat_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/octocat",
html_url: "https://github.com/octocat",
followers_url: "https://api.github.com/users/octocat/followers",
following_url: "https://api.github.com/users/octocat/following{/other_user}",
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
organizations_url: "https://api.github.com/users/octocat/orgs",
repos_url: "https://api.github.com/users/octocat/repos",
events_url: "https://api.github.com/users/octocat/events{/privacy}",
received_events_url: "https://api.github.com/users/octocat/received_events",
type: "User",
site_admin: false
},
committer: {
login: "octocat",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/octocat_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/octocat",
html_url: "https://github.com/octocat",
followers_url: "https://api.github.com/users/octocat/followers",
following_url: "https://api.github.com/users/octocat/following{/other_user}",
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
organizations_url: "https://api.github.com/users/octocat/orgs",
repos_url: "https://api.github.com/users/octocat/repos",
events_url: "https://api.github.com/users/octocat/events{/privacy}",
received_events_url: "https://api.github.com/users/octocat/received_events",
type: "User",
site_admin: false
},
parents: [
{
url: "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
]
};
12 changes: 12 additions & 0 deletions packages/release/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "./",
"noEmit": true,
"incremental": true,
"tsBuildInfoFile": ".tsbuildinfo-2",
"types": ["vitest/globals"]
},
"include": ["*.test.ts", "mockdata.ts"],
"references": [{ "path": "../" }]
}
Loading

0 comments on commit a37132f

Please sign in to comment.