From 2c57b65a4a5ccd926ffd2374dddd25e01e5368e6 Mon Sep 17 00:00:00 2001 From: Anthony Seure Date: Wed, 23 Sep 2020 17:05:46 +0200 Subject: [PATCH 1/3] feat: understands `--config ` option in `conventionalChangelogArgs` --- .../prepare/__tests__/updateChangelog.spec.js | 24 +++++++++++++++++++ .../src/step/prepare/updateChangelog.js | 5 +++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js diff --git a/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js b/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js new file mode 100644 index 00000000..ca8fb229 --- /dev/null +++ b/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js @@ -0,0 +1,24 @@ +const path = require('path'); +import { prepareParams, parseArgs } from '../updateChangelog'; +import tempWrite from 'temp-write'; + +describe('prepareParams', () => { + it('loads configuration from --config option', () => { + const config = { + writerOpts: { + headerPartial: '## {{version}}', + }, + }; + const configString = `module.exports = { ${config} };`; + const configPath = tempWrite.sync(configString); + const configDir = path.basename(path.dirname(configPath)); + + const { args } = prepareParams({ + dir: configDir, + conventionalChangelogArgs: `--config ${configPath}`, + revisionRange: '1.0.0..1.0.1', + reject: () => {}, + }); + expect(args.config).toMatch(config); + }); +}); diff --git a/packages/shipjs/src/step/prepare/updateChangelog.js b/packages/shipjs/src/step/prepare/updateChangelog.js index 93a223d0..25353c12 100644 --- a/packages/shipjs/src/step/prepare/updateChangelog.js +++ b/packages/shipjs/src/step/prepare/updateChangelog.js @@ -78,7 +78,7 @@ const argSpec = { '-t': '--tag-prefix', }; -function prepareParams({ +export function prepareParams({ dir, conventionalChangelogArgs, releaseCount, @@ -118,6 +118,9 @@ function prepareParams({ } const templateContext = args.context && require(path.resolve(dir, args.context)); + if (args.config) { + args.config = require(path.resolve(dir, args.config)); + } return { args, gitRawCommitsOpts, templateContext }; } From 8f10fdd24e1815678be38a7624bd7003efcb05ea Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Fri, 25 Sep 2020 14:13:09 +0200 Subject: [PATCH 2/3] Update packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js Co-authored-by: Haroen Viaene --- .../shipjs/src/step/prepare/__tests__/updateChangelog.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js b/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js index ca8fb229..e9b79e01 100644 --- a/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js +++ b/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js @@ -1,5 +1,5 @@ const path = require('path'); -import { prepareParams, parseArgs } from '../updateChangelog'; +import { prepareParams } from '../updateChangelog'; import tempWrite from 'temp-write'; describe('prepareParams', () => { From 15e03fdb30972ebe06edc90c760a120200a70f0c Mon Sep 17 00:00:00 2001 From: shipjs Date: Fri, 25 Sep 2020 14:48:45 +0200 Subject: [PATCH 3/3] fix test case --- .../src/step/prepare/__tests__/updateChangelog.spec.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js b/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js index e9b79e01..5a8f2166 100644 --- a/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js +++ b/packages/shipjs/src/step/prepare/__tests__/updateChangelog.spec.js @@ -1,24 +1,26 @@ const path = require('path'); import { prepareParams } from '../updateChangelog'; +import { parseArgs } from '../../../util'; import tempWrite from 'temp-write'; describe('prepareParams', () => { it('loads configuration from --config option', () => { + parseArgs.mockImplementation(jest.requireActual('../../../util').parseArgs); const config = { writerOpts: { headerPartial: '## {{version}}', }, }; - const configString = `module.exports = { ${config} };`; + const configString = `module.exports = ${JSON.stringify(config)};`; const configPath = tempWrite.sync(configString); const configDir = path.basename(path.dirname(configPath)); const { args } = prepareParams({ dir: configDir, - conventionalChangelogArgs: `--config ${configPath}`, + conventionalChangelogArgs: `-i CHANGELOG.md -s --config ${configPath}`, revisionRange: '1.0.0..1.0.1', reject: () => {}, }); - expect(args.config).toMatch(config); + expect(args.config).toEqual(config); }); });