Skip to content

Commit

Permalink
Merge pull request #49 from embroider-build/updateChangelog-test
Browse files Browse the repository at this point in the history
add a basic test for updateChangelog
  • Loading branch information
mansona committed Jan 24, 2024
2 parents 033a0c5 + 1866d5e commit cfbbc4d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/prepare.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { describe, it, expect, vi } from 'vitest';

import { updateChangelog } from './prepare.js';

const mocks = vi.hoisted(() => {
return {
readFileSync: vi.fn().mockImplementation(() => ''),
writeFileSync: vi.fn().mockImplementation(() => ''),
};
});

vi.mock('node:fs', () => {
return mocks;
});

describe('prepare', function () {
describe('updateChangelog', function () {
it('updates changelog correctly', function () {
mocks.readFileSync.mockReturnValue(`# A Totally ficticious Changelog
## Some Old version
- added some features
- spent a lot of time trying to figure out releases (if only there was a tool to help with that)
`);
updateChangelog(
`## v1.0.0
- added release-plan (how did I live without it!?)
- releasing initial working version`,
new Map([['thing', { newVersion: 'v1.0.0', impact: 'major' }]]) as any,
);
const [, newChangelog] = mocks.writeFileSync.mock.lastCall;
expect(newChangelog).to.eq(`# A Totally ficticious Changelog
## v1.0.0
thing v1.0.0 (major)
- added release-plan (how did I live without it!?)
- releasing initial working version
## Some Old version
- added some features
- spent a lot of time trying to figure out releases (if only there was a tool to help with that)
`);
});
});
});
4 changes: 2 additions & 2 deletions src/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseChangeLogOrExit } from './change-parser.js';
import { readFileSync, writeFileSync } from 'fs';
import { readFileSync, writeFileSync } from 'node:fs';
import type { Solution } from './plan.js';
import { planVersionBumps, saveSolution } from './plan.js';
import fsExtra from 'fs-extra';
Expand All @@ -8,7 +8,7 @@ const { readJSONSync, writeJSONSync } = fsExtra;

const changelogPreamblePattern = /#.*Changelog.*$/;

function updateChangelog(
export function updateChangelog(
newChangelogContent: string,
solution: Solution,
): string {
Expand Down

0 comments on commit cfbbc4d

Please sign in to comment.