Skip to content

Commit

Permalink
Minor edits to new header logic and tests
Browse files Browse the repository at this point in the history
webpro committed Feb 25, 2022
1 parent af66ee0 commit abef409
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ class ConventionalChangelog extends Plugin {
});
}

getOldChangelog() {
getPreviousChangelog() {
const { infile } = this.options;
return new Promise((resolve, reject) => {
const readStream = fs.createReadStream(infile);
@@ -112,11 +112,11 @@ class ConventionalChangelog extends Plugin {
this.debug(err);
}

let oldChangelog = ""
try{
oldChangelog = await this.getOldChangelog();
oldChangelog = oldChangelog.replace(header.split(/\r\n|\r|\n/g).join(EOL), '');
}catch(err){
let previousChangelog = '';
try {
previousChangelog = await this.getPreviousChangelog();
previousChangelog = previousChangelog.replace(header.split(/\r\n|\r|\n/g).join(EOL), '');
} catch (err) {
this.debug(err);
}

@@ -125,7 +125,7 @@ class ConventionalChangelog extends Plugin {
this.debug({ changelog });
}

fs.writeFileSync(infile, header + EOL + EOL + changelog + oldChangelog);
fs.writeFileSync(infile, header + EOL + EOL + changelog + previousChangelog);

if (!hasInfile) {
await this.exec(`git add ${infile}`);
7 changes: 5 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ test('should use provided version', async t => {
});

test(`should write and update infile (${infile})`, async t => {
const header = "The header"
const header = 'The header\n\nThe subheader';
const options = { [namespace]: { preset, infile, header }, git };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
@@ -139,7 +139,10 @@ test(`should write and update infile (${infile})`, async t => {
{
await runTasks(plugin);
const changelog = fs.readFileSync(infile);
assert.strictEqual(changelog.toString().trim(), `${header}${EOL}${EOL}The changelog${EOL}${EOL}The changelog`);
assert.strictEqual(
changelog.toString().trim(),
`The header${EOL}${EOL}The subheader${EOL}${EOL}The changelog${EOL}${EOL}The changelog`
);
}
fs.unlinkSync(infile);
});

0 comments on commit abef409

Please sign in to comment.