Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iautom8things committed Jun 26, 2021
1 parent 496c5c8 commit d9a44d8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 44 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ inputs:
test_value:
description: "Set to specify what patterns are applied against"
required: true
default: ""
default: "."
branch:
description: "Set to specify a specific branch, default is the current HEAD"
required: true
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async function run() {
let versionBranch = core.getInput('branch', { required: true });
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
const testValue = createMatchTest(core.getInput('test_value', { required: true }));
const testValue = core.getInput('test_value', { required: true });
const changePath = core.getInput('change_path') || '';

const onHead = versionBranch === 'HEAD';
Expand Down
104 changes: 62 additions & 42 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ const windows = process.platform === "win32";

// Action input variables
const defaultInputs = {
test_value: ".",
branch: "HEAD",
tag_prefix: "v",
major_pattern: "(MAJOR)",
minor_pattern: "(MINOR)",
format: "${major}.${minor}.${patch}",
short_tags: true,
bump_each_commit: false
use_test_value: false
};

// Creates a randomly named git repository and returns a function to execute commands in it
Expand Down Expand Up @@ -580,68 +581,87 @@ test('Tag prefix can include forward slash', () => {
});

test('[Use Branch Names] Commit messages do not affect version', () => {
const repo = createTestRepo({ tag_prefix: '', use_branch_names: true}); // 0.0.0
const repo = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'some_patch', major_pattern: "major/", minor_pattern: "minor/"}); // 0.0.0
repo.makeCommit('Initial Commit');
repo.exec('git tag 1.2.3');

repo.makeCommit('Initial Commit'); // 0.0.1+0
expect(repo.runAction()).toMatch('Version is 0.0.1+0');
repo.makeCommit('First commit on patch branch');
expect(repo.runAction()).toMatch('Version is 1.2.4+0');

repo.makeCommit('Second Commit (MINOR)'); // 0.0.1+1
expect(repo.runAction()).toMatch('Version is 0.0.1+1');
const repo2 = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'major/banger', major_pattern: "major/", minor_pattern: "minor/"}); // 0.0.0
repo2.makeCommit('Initial Commit');
repo2.exec('git tag 1.2.3');

repo2.makeCommit('First commit on major branch');
expect(repo2.runAction()).toMatch('Version is 2.0.0+0');

const repo3 = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'minor/problem', major_pattern: "major/", minor_pattern: "minor/"}); // 0.0.0
repo3.makeCommit('Initial Commit');
repo3.exec('git tag 1.2.3');

repo.makeCommit('Second Commit (MAJOR)'); // 0.0.1+2
expect(repo.runAction()).toMatch('Version is 0.0.1+2');
repo3.makeCommit('First commit on minor branch');
expect(repo3.runAction()).toMatch('Version is 1.3.0+0');

repo.clean();
repo2.clean();
repo3.clean();
});

test('[Use Branch Names] Commit messages do not affect version', () => {
const repo = createTestRepo({ tag_prefix: '', use_branch_names: true, major_pattern: "major/", minor_pattern: "minor/"}); // 0.0.0

test('[Use Branch Names] regex works as expected', () => {
const repo = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'some_patch', major_pattern: "/^(major|breaking)/", minor_pattern: "/^(minor|feature|feat)//"}); // 0.0.0
repo.makeCommit('Initial Commit');
repo.exec('git tag 1.2.3');
repo.exec('git switch -c some_patch');

repo.makeCommit('First commit on patch branch');
expect(repo.runAction()).toMatch('Version is 1.2.4+0');

repo.exec('git switch -c major/banger');
repo.makeCommit('First commit on major branch');
expect(repo.runAction()).toMatch('Version is 2.0.0+1');
const repo2 = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'major/banger', major_pattern: "/^(major|breaking)/", minor_pattern: "/^(minor|feature|feat)//"}); // 0.0.0
repo2.makeCommit('Initial Commit');
repo2.exec('git tag 1.2.3');

repo.exec('git switch -c minor/foo');
repo.makeCommit('First commit on minor branch');
expect(repo.runAction()).toMatch('Version is 1.3.0+2');
repo2.makeCommit('First commit on major branch');
expect(repo2.runAction()).toMatch('Version is 2.0.0+0');

repo.clean();
});
const repo3 = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'minor/problem', major_pattern: "/^(major|breaking)/", minor_pattern: "/^(minor|feature|feat)//"}); // 0.0.0
repo3.makeCommit('Initial Commit');
repo3.exec('git tag 1.2.3');

test('[Use Branch Names] regex works as expected', () => {
const repo = createTestRepo({ tag_prefix: '', use_branch_names: true, major_pattern: "/^(major|breaking)//", minor_pattern: "/^(minor|feature|feat)//"}); // 0.0.0
repo3.makeCommit('First commit on minor branch');
expect(repo3.runAction()).toMatch('Version is 1.3.0+0');

repo.makeCommit('Initial Commit');
repo.exec('git tag 1.2.3');
repo.exec('git switch -c some_patch');
repo.makeCommit('First commit on patch branch');
expect(repo.runAction()).toMatch('Version is 1.2.4+0');
const repo4 = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'breaking/banger', major_pattern: "/^(major|breaking)/", minor_pattern: "/^(minor|feature|feat)//"}); // 0.0.0
repo4.makeCommit('Initial Commit');
repo4.exec('git tag 1.2.3');

repo4.makeCommit('First commit on major branch');
expect(repo4.runAction()).toMatch('Version is 2.0.0+0');

const repo5 = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'feature/problem', major_pattern: "/^(major|breaking)/", minor_pattern: "/^(minor|feature|feat)//"}); // 0.0.0
repo5.makeCommit('Initial Commit');
repo5.exec('git tag 1.2.3');

repo.exec('git switch -c major/banger');
repo.makeCommit('First commit on major branch');
expect(repo.runAction()).toMatch('Version is 2.0.0');
repo5.makeCommit('First commit on minor branch');
expect(repo5.runAction()).toMatch('Version is 1.3.0+0');

repo.exec('git switch -c minor/foo');
repo.makeCommit('another commit');
expect(repo.runAction()).toMatch('Version is 1.3.0');
const repo6 = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'feat/problem', major_pattern: "/^(major|breaking)/", minor_pattern: "/^(minor|feature|feat)//"}); // 0.0.0
repo6.makeCommit('Initial Commit');
repo6.exec('git tag 1.2.3');

repo.exec('git switch -c feature/foo');
repo.makeCommit('another commit');
expect(repo.runAction()).toMatch('Version is 1.3.0');
repo6.makeCommit('First commit on minor branch');
expect(repo6.runAction()).toMatch('Version is 1.3.0+0');

repo.exec('git switch -c feat/foo');
repo.makeCommit('another commit');
expect(repo.runAction()).toMatch('Version is 1.3.0');
const repo7 = createTestRepo({ tag_prefix: '', use_test_value: true, test_value: 'team/feat/bar', major_pattern: "/^(major|breaking)/", minor_pattern: "/^(minor|feature|feat)//"}); // 0.0.0
repo7.makeCommit('Initial Commit');
repo7.exec('git tag 1.2.3');

repo.exec('git switch -c breaking/foo');
repo.makeCommit('another commit');
expect(repo.runAction()).toMatch('Version is 2.0.0');
repo7.makeCommit('First commit on patch branch');
expect(repo7.runAction()).toMatch('Version is 1.2.4+0');

repo.clean();
repo2.clean();
repo3.clean();
repo4.clean();
repo5.clean();
repo6.clean();
repo7.clean();
});

0 comments on commit d9a44d8

Please sign in to comment.