Skip to content

Commit

Permalink
test: add tests for commit_format behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
thislooksfun committed Jun 16, 2020
1 parent 95431a9 commit 9681fb4
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 0 deletions.
155 changes: 155 additions & 0 deletions spec/analyze_commits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,161 @@ def execute_lane_test(params)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_LAST_INCOMPATIBLE_CODEPUSH_VERSION]).to eq("0.0.3")
end

describe "commit_format" do
describe "default" do
it "should allow for certain types" do
commits = [
"docs: ...|",
"fix: ...|",
"feat: ...|",
"chore: ...|",
"style: ...|",
"refactor: ...|",
"perf: ...|",
"test: ...|"
]
test_analyze_commits(commits)

is_releasable = execute_lane_test(
match: 'v*',
releases: {
docs: "minor",
fix: "minor",
feat: "minor",
chore: "minor",
style: "minor",
refactor: "minor",
perf: "minor",
test: "minor"
}
)
expect(is_releasable).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.8.0")
end

it "should not allow for custom types" do
commits = [
"foo: ...|",
"bar: ...|",
"baz: ...|"
]
test_analyze_commits(commits)

is_releasable = execute_lane_test(
match: 'v*',
releases: {
foo: "minor",
bar: "minor",
baz: "minor"
}
)
expect(is_releasable).to eq(false)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.0.8")
end
end

describe "angular" do
it "should allow for default types" do
commits = [
"docs: ...|",
"fix: ...|",
"feat: ...|",
"chore: ...|",
"style: ...|",
"refactor: ...|",
"perf: ...|",
"test: ...|"
]
test_analyze_commits(commits)

is_releasable = execute_lane_test(
match: 'v*',
commit_format: 'angular',
releases: {
docs: "minor",
fix: "minor",
feat: "minor",
chore: "minor",
style: "minor",
refactor: "minor",
perf: "minor",
test: "minor"
}
)
expect(is_releasable).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.8.0")
end

it "should allow for custom types" do
commits = [
"foo: ...|",
"bar: ...|",
"baz: ...|"
]
test_analyze_commits(commits)

is_releasable = execute_lane_test(
match: 'v*',
commit_format: 'angular',
releases: {
foo: "minor",
bar: "minor",
baz: "minor"
}
)
expect(is_releasable).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.3.0")
end
end

describe "custom" do
format_pattern = /^prefix-(foo|bar|baz)(?:\.(.*))?(): (.*)/
commits = [
"prefix-foo.ios: ...|",
"prefix-foo.android: ...|",
"prefix-bar.ios: ...|",
"prefix-bar.android: ...|",
"prefix-baz.ios: ...|",
"prefix-baz.android: ...|",
"prefix-qux.ios: ...|",
"prefix-qux.android: ...|"
]

it "should allow for arbetrary formatting" do
test_analyze_commits(commits)

is_releasable = execute_lane_test(
match: 'v*',
commit_format: format_pattern,
releases: {
foo: "major",
bar: "minor",
baz: "patch"
}
)
expect(is_releasable).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("3.2.2")
end

it "should allow for arbetrary formatting with scope" do
test_analyze_commits(commits)

is_releasable = execute_lane_test(
match: 'v*',
commit_format: format_pattern,
releases: {
foo: "major",
bar: "minor",
baz: "patch"
},
ignore_scopes: ['android']
)
expect(is_releasable).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("2.1.1")
end
end
end

after do
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/conventional_changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe Fastlane::Actions::ConventionalChangelogAction do
describe "Conventional Changelog" do
before do
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::CONVENTIONAL_CHANGELOG_ACTION_FORMAT_PATTERN] = Fastlane::Helper::SemanticReleaseHelper.format_patterns["default"]
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION] = '1.0.2'
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_ANALYZED] = true
end
Expand Down Expand Up @@ -226,6 +227,37 @@ def execute_lane_test_no_links_slack
end
end

describe "commit format" do
format_pattern = /^prefix-(foo|bar|baz)(?:\.(.*))?(): (.*)/
commits = [
"prefix-foo: sub|body|long_hash|short_hash|Jiri Otahal|time",
"prefix-bar: sub|body|long_hash|short_hash|Jiri Otahal|time",
"prefix-baz.android: sub|body|long_hash|short_hash|Jiri Otahal|time",
"prefix-qux: sub|body|long_hash|short_hash|Jiri Otahal|time"
]

before do
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::CONVENTIONAL_CHANGELOG_ACTION_FORMAT_PATTERN] = format_pattern
allow(Fastlane::Actions::ConventionalChangelogAction).to receive(:get_commits_from_hash).and_return(commits)
allow(Date).to receive(:today).and_return(Date.new(2019, 5, 25))
end

it "should use the commit format" do
result = "# 1.0.2 (2019-05-25)\n\n### Bazz\n- **android:** sub ([short_hash](/long_hash))\n\n### Foo\n- sub ([short_hash](/long_hash))\n\n### Bar\n- sub ([short_hash](/long_hash))\n\n### Other\n- prefix-qux: sub ([short_hash](/long_hash))"

changelog = execute_lane_test(
order: ['baz', 'foo', 'bar', 'no_type'],
sections: {
foo: "Foo",
bar: "Bar",
baz: "Bazz",
no_type: "Other"
}
)
expect(changelog).to eq(result)
end
end

after do
end
end
Expand Down

0 comments on commit 9681fb4

Please sign in to comment.