Skip to content

Commit

Permalink
test(writer-opts): compared the transform function accounting for gen…
Browse files Browse the repository at this point in the history
…eration with each load

as confirmed in conventional-changelog/conventional-changelog#1121 (comment)
  • Loading branch information
travi committed Sep 17, 2023
1 parent c6075a5 commit 73d5356
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions test/load-changelog-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ import loadChangelogConfig from "../lib/load-changelog-config.js";

const cwd = process.cwd();

/**
* assertion to compare loaded writerOpts with the expected writerOpts from the angular preset
*
* @param {Object} t AVA assertion library.
* @param {Object} loadedWriterOpts
* @param {Object} angularPresetWriterOpts
*/
function assertWriterOptsAreFromAngularPreset(t, loadedWriterOpts, angularPresetWriterOpts) {
const { transform: loadedTransform, ...loadedWriterOptsWithoutTransform } = loadedWriterOpts;
const { transform: angularPresetTransform, ...angularPresetWriterOptsWithoutTransform } = angularPresetWriterOpts;

t.deepEqual(loadedWriterOptsWithoutTransform, angularPresetWriterOptsWithoutTransform);
t.is(loadedTransform.toString(), angularPresetTransform.toString());
}

/**
* AVA macro to verify that `loadChangelogConfig` return a config object with parserOpts and writerOpts.
*
Expand Down Expand Up @@ -46,7 +61,7 @@ test('Load "conventional-changelog-angular" by default', async (t) => {
const angularChangelogConfig = await conventionalChangelogAngular();

t.deepEqual(changelogConfig.parserOpts, angularChangelogConfig.parserOpts);
t.deepEqual(changelogConfig.writerOpts, angularChangelogConfig.writerOpts);
assertWriterOptsAreFromAngularPreset(t, changelogConfig.writerOpts, angularChangelogConfig.writerOpts);
});

test('Accept a "parserOpts" object as option', async (t) => {
Expand All @@ -60,7 +75,7 @@ test('Accept a "parserOpts" object as option', async (t) => {
t.is(customParserOptions.headerPattern, changelogConfig.parserOpts.headerPattern);
t.deepEqual(customParserOptions.headerCorrespondence, changelogConfig.parserOpts.headerCorrespondence);
t.deepEqual(changelogConfig.parserOpts.noteKeywords, angularChangelogConfig.parserOpts.noteKeywords);
t.deepEqual(changelogConfig.writerOpts, angularChangelogConfig.writerOpts);
assertWriterOptsAreFromAngularPreset(t, changelogConfig.writerOpts, angularChangelogConfig.writerOpts);
});

test('Accept a "writerOpts" object as option', async (t) => {
Expand All @@ -85,7 +100,7 @@ test('Accept a partial "parserOpts" object as option that overwrite a preset', a
t.is(customParserOptions.headerPattern, changelogConfig.parserOpts.headerPattern);
t.deepEqual(customParserOptions.headerCorrespondence, changelogConfig.parserOpts.headerCorrespondence);
t.truthy(changelogConfig.parserOpts.noteKeywords);
t.deepEqual(changelogConfig.writerOpts, angularChangelogConfig.writerOpts);
assertWriterOptsAreFromAngularPreset(t, changelogConfig.writerOpts, angularChangelogConfig.writerOpts);
});

test('Accept a "writerOpts" object as option that overwrite a preset', async (t) => {
Expand Down Expand Up @@ -116,7 +131,7 @@ test('Accept a partial "parserOpts" object as option that overwrite a config', a
t.is(customParserOptions.headerPattern, changelogConfig.parserOpts.headerPattern);
t.deepEqual(customParserOptions.headerCorrespondence, changelogConfig.parserOpts.headerCorrespondence);
t.truthy(changelogConfig.parserOpts.noteKeywords);
t.deepEqual(changelogConfig.writerOpts, angularChangelogConfig.writerOpts);
assertWriterOptsAreFromAngularPreset(t, changelogConfig.writerOpts, angularChangelogConfig.writerOpts);
});

test('Accept a "writerOpts" object as option that overwrite a config', async (t) => {
Expand Down

0 comments on commit 73d5356

Please sign in to comment.