From d9a44d87cd35ab5927a8ac841789c3da3af5f6d6 Mon Sep 17 00:00:00 2001 From: Manuel Zubieta Date: Sat, 26 Jun 2021 13:55:23 -0500 Subject: [PATCH] fix tests --- action.yml | 2 +- index.js | 2 +- index.test.js | 104 ++++++++++++++++++++++++++++++-------------------- 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/action.yml b/action.yml index 1f1e6a1..32fc19a 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/index.js b/index.js index 2e27bed..ff2d0f0 100644 --- a/index.js +++ b/index.js @@ -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'; diff --git a/index.test.js b/index.test.js index 63f6276..f62e582 100644 --- a/index.test.js +++ b/index.test.js @@ -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 @@ -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(); }); \ No newline at end of file