From 64259723085eaa21a281391acb9fc0704319c8b3 Mon Sep 17 00:00:00 2001 From: tommywo Date: Thu, 5 Sep 2019 10:39:25 +0200 Subject: [PATCH] fix(preset-loader): fix handling conventionalcommits preset without config object closes #512 --- packages/conventional-changelog-cli/test/test.js | 13 +++++++++++++ .../conventional-changelog-preset-loader/index.js | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/conventional-changelog-cli/test/test.js b/packages/conventional-changelog-cli/test/test.js index 88785669a..4c8187e00 100644 --- a/packages/conventional-changelog-cli/test/test.js +++ b/packages/conventional-changelog-cli/test/test.js @@ -367,6 +367,19 @@ describe('cli', function () { done() })) }) + it('--preset "conventionalcommits" should work', function (done) { + writeFileSync('angular', '') + shell.exec('git add --all && git commit -m"fix: fix it!"') + var cp = spawn(cliPath, ['--preset', 'conventionalcommits'], { + stdio: [process.stdin, null, null] + }) + + cp.stdout + .pipe(concat(function (chunk) { + expect(chunk.toString()).to.include('Bug Fixes') + done() + })) + }) it('--config should work with --preset', function (done) { var cp = spawn(cliPath, ['--preset', 'angular', '--config', path.join(__dirname, 'fixtures/config.js')], { diff --git a/packages/conventional-changelog-preset-loader/index.js b/packages/conventional-changelog-preset-loader/index.js index d16702afa..4061e87fe 100644 --- a/packages/conventional-changelog-preset-loader/index.js +++ b/packages/conventional-changelog-preset-loader/index.js @@ -33,8 +33,9 @@ function presetLoader (requireMethod) { // rather than returning a promise, presets can return a builder function // which accepts a config object (allowing for customization) and returns // a promise. - if (config && !config.then && typeof path === 'object') { - return config(path) + if (config && !config.then) { + const options = typeof path === 'object' ? path : {} + return config(options) } else { // require returned a promise that resolves to a config object. return config