|
| 1 | +const t = require('tap') |
| 2 | +const Version = require('../../lib/release-please/version.js') |
| 3 | + |
| 4 | +const COMMITS = { |
| 5 | + major: [{ type: 'feat' }, {}, {}, { breaking: true }], |
| 6 | + minor: [{}, {}, { type: 'feat' }], |
| 7 | + patch: [{}, { type: 'chore' }, { type: 'fix' }], |
| 8 | +} |
| 9 | + |
| 10 | +const COMMIT_NAME = (c) => Object.entries(COMMITS).find(([, i]) => i === c)[0] |
| 11 | + |
| 12 | +t.test('bumps', async (t) => { |
| 13 | + const checks = [ |
| 14 | + // Normal releases |
| 15 | + ['2.0.0', COMMITS.major, false, '3.0.0'], |
| 16 | + ['2.0.0', COMMITS.minor, false, '2.1.0'], |
| 17 | + ['2.0.0', COMMITS.patch, false, '2.0.1'], |
| 18 | + // premajor -> normal |
| 19 | + ['2.0.0-pre.1', COMMITS.major, false, '2.0.0'], |
| 20 | + ['2.0.0-pre.5', COMMITS.minor, false, '2.0.0'], |
| 21 | + ['2.0.0-pre.4', COMMITS.patch, false, '2.0.0'], |
| 22 | + // preminor -> normal |
| 23 | + ['2.1.0-pre.1', COMMITS.major, false, '3.0.0'], |
| 24 | + ['2.1.0-pre.5', COMMITS.minor, false, '2.1.0'], |
| 25 | + ['2.1.0-pre.4', COMMITS.patch, false, '2.1.0'], |
| 26 | + // prepatch -> normal |
| 27 | + ['2.0.1-pre.1', COMMITS.major, false, '3.0.0'], |
| 28 | + ['2.0.1-pre.5', COMMITS.minor, false, '2.1.0'], |
| 29 | + ['2.0.1-pre.4', COMMITS.patch, false, '2.0.1'], |
| 30 | + // Prereleases |
| 31 | + ['2.0.0', COMMITS.major, true, '3.0.0-pre.0'], |
| 32 | + ['2.0.0', COMMITS.minor, true, '2.1.0-pre.0'], |
| 33 | + ['2.0.0', COMMITS.patch, true, '2.0.1-pre.0'], |
| 34 | + // premajor - prereleases |
| 35 | + ['2.0.0-pre.1', COMMITS.major, true, '2.0.0-pre.2'], |
| 36 | + ['2.0.0-pre.1', COMMITS.minor, true, '2.0.0-pre.2'], |
| 37 | + ['2.0.0-pre.1', COMMITS.patch, true, '2.0.0-pre.2'], |
| 38 | + // preminor - prereleases |
| 39 | + ['2.1.0-pre.1', COMMITS.major, true, '3.0.0-pre.0'], |
| 40 | + ['2.1.0-pre.1', COMMITS.minor, true, '2.1.0-pre.2'], |
| 41 | + ['2.1.0-pre.1', COMMITS.patch, true, '2.1.0-pre.2'], |
| 42 | + // prepatch - prereleases |
| 43 | + ['2.0.1-pre.1', COMMITS.major, true, '3.0.0-pre.0'], |
| 44 | + ['2.0.1-pre.1', COMMITS.minor, true, '2.1.0-pre.0'], |
| 45 | + ['2.0.1-pre.1', COMMITS.patch, true, '2.0.1-pre.2'], |
| 46 | + // different prerelease identifiers |
| 47 | + ['2.0.0-beta.1', COMMITS.major, true, '2.0.0-beta.2'], |
| 48 | + ['2.0.0-alpha.1', COMMITS.major, true, '2.0.0-alpha.2'], |
| 49 | + ['2.0.0-rc.1', COMMITS.major, true, '2.0.0-rc.2'], |
| 50 | + ['2.0.0-0', COMMITS.major, true, '2.0.0-1'], |
| 51 | + ] |
| 52 | + |
| 53 | + for (const [version, commits, prerelease, expected] of checks) { |
| 54 | + const name = [version, COMMIT_NAME(commits), prerelease ? 'pre' : 'normal', expected] |
| 55 | + const r = new Version({ prerelease }).bump(version, commits) |
| 56 | + t.equal( |
| 57 | + `${r.major}.${r.minor}.${r.patch}${r.preRelease ? `-${r.preRelease}` : ''}`, |
| 58 | + expected, |
| 59 | + name.join(' - ') |
| 60 | + ) |
| 61 | + } |
| 62 | +}) |
0 commit comments