Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a basic test for updateChangelog #49

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading