From bc685be46ca90417a03867717393bb9018e6036c Mon Sep 17 00:00:00 2001 From: jan-mrm <67435696+jan-mrm@users.noreply.github.com> Date: Tue, 22 Aug 2023 13:40:34 +0200 Subject: [PATCH] fix(bump): propagate the parserOpts from args to conventionalRecommendedBump, fixing an issue with custom headerPatterns (#89) * chore(bump): also propagate the parserOpts from args to conventionalRecommendedBump * chore(tests): add the third possible parameter for the bump function to the mocking for tests --- lib/lifecycles/bump.js | 2 +- test/config-files.spec.js | 6 +++--- test/core.spec.js | 8 ++++---- test/git.spec.js | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/lifecycles/bump.js b/lib/lifecycles/bump.js index 7758dc6e6..da72199f6 100644 --- a/lib/lifecycles/bump.js +++ b/lib/lifecycles/bump.js @@ -124,7 +124,7 @@ function bumpVersion (releaseAs, currentVersion, args) { path: args.path, tagPrefix: args.tagPrefix, lernaPackage: args.lernaPackage - }, function (err, release) { + }, args.parserOpts, function (err, release) { if (err) return reject(err) else return resolve(release) }) diff --git a/test/config-files.spec.js b/test/config-files.spec.js index 9e04877c1..8f39693f6 100644 --- a/test/config-files.spec.js +++ b/test/config-files.spec.js @@ -22,15 +22,15 @@ function exec () { * * Mocks should be unregistered in test cleanup by calling unmock() * - * bump?: 'major' | 'minor' | 'patch' | Error | (opt, cb) => { cb(err) | cb(null, { releaseType }) } + * bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) } * changelog?: string | Error | Array string | null> * tags?: string[] | Error */ function mock ({ bump, changelog, tags } = {}) { mockery.enable({ warnOnUnregistered: false, useCleanCache: true }) - mockery.registerMock('conventional-recommended-bump', function (opt, cb) { - if (typeof bump === 'function') bump(opt, cb) + mockery.registerMock('conventional-recommended-bump', function (opt, parserOpts, cb) { + if (typeof bump === 'function') bump(opt, parserOpts, cb) else if (bump instanceof Error) cb(bump) else cb(null, bump ? { releaseType: bump } : {}) }) diff --git a/test/core.spec.js b/test/core.spec.js index a94ac5035..a6dfbf0fe 100644 --- a/test/core.spec.js +++ b/test/core.spec.js @@ -36,7 +36,7 @@ function getPackageVersion () { * * Mocks should be unregistered in test cleanup by calling unmock() * - * bump?: 'major' | 'minor' | 'patch' | Error | (opt, cb) => { cb(err) | cb(null, { releaseType }) } + * bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) } * changelog?: string | Error | Array string | null> * execFile?: ({ dryRun, silent }, cmd, cmdArgs) => Promise * fs?: { [string]: string | Buffer | any } @@ -46,8 +46,8 @@ function getPackageVersion () { function mock ({ bump, changelog, execFile, fs, pkg, tags } = {}) { mockery.enable({ warnOnUnregistered: false, useCleanCache: true }) - mockery.registerMock('conventional-recommended-bump', function (opt, cb) { - if (typeof bump === 'function') bump(opt, cb) + mockery.registerMock('conventional-recommended-bump', function (opt, parserOpts, cb) { + if (typeof bump === 'function') bump(opt, parserOpts, cb) else if (bump instanceof Error) cb(bump) else cb(null, bump ? { releaseType: bump } : {}) }) @@ -405,7 +405,7 @@ describe('cli', function () { it('creates a prerelease with a new minor version after two prerelease patches', async function () { let releaseType = 'patch' - const bump = (_, cb) => cb(null, { releaseType }) + const bump = (_, __, cb) => cb(null, { releaseType }) mock({ bump, fs: { 'CHANGELOG.md': 'legacy header format\n' } diff --git a/test/git.spec.js b/test/git.spec.js index 74ee6313e..22b345a04 100644 --- a/test/git.spec.js +++ b/test/git.spec.js @@ -38,7 +38,7 @@ function getPackageVersion () { /** * Mock external conventional-changelog modules * - * bump: 'major' | 'minor' | 'patch' | Error | (opt, cb) => { cb(err) | cb(null, { releaseType }) } + * bump: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) } * changelog?: string | Error | Array string | null> * tags?: string[] | Error */ @@ -46,8 +46,8 @@ function mock ({ bump, changelog, tags }) { if (bump === undefined) throw new Error('bump must be defined for mock()') mockery.enable({ warnOnUnregistered: false, useCleanCache: true }) - mockery.registerMock('conventional-recommended-bump', function (opt, cb) { - if (typeof bump === 'function') bump(opt, cb) + mockery.registerMock('conventional-recommended-bump', function (opt, parserOpts, cb) { + if (typeof bump === 'function') bump(opt, parserOpts, cb) else if (bump instanceof Error) cb(bump) else cb(null, { releaseType: bump }) })