/** * Changesets integration tests — covers the pure helpers in * changesets.ts. The impure pieces (running `bunx changeset version`, * doing git commits) are thin wrappers around well-tested external * tools; we don't unit-test those. */ import { describe, expect, test } from 'bun:test'; import { filterChangesetEntries, parseGitStatusFiles } from './changesets'; describe('filterChangesetEntries', () => { test('returns nothing for an empty dir', () => { expect(filterChangesetEntries([])).toEqual([]); }); test('returns only .md files', () => { expect( filterChangesetEntries([ 'fancy-tigers-jump.md', 'config.json', '.DS_Store', 'noisy-cats-walk.md', ]), ).toEqual(['fancy-tigers-jump.md', 'noisy-cats-walk.md']); }); test('excludes README.md (the default scaffolding doc)', () => { expect(filterChangesetEntries(['README.md', 'happy-birds-sing.md'])).toEqual([ 'happy-birds-sing.md', ]); }); test('excludes config.json regardless of extension filtering', () => { // config.json doesn't end in .md so it's already excluded by the // extension filter; this test documents that the extension check // alone is sufficient — no special-case needed for config.json. expect(filterChangesetEntries(['config.json'])).toEqual([]); }); test('preserves input order (changesets has no inherent ordering)', () => { expect(filterChangesetEntries(['z-z-z.md', 'a-a-a.md', 'm-m-m.md'])).toEqual([ 'z-z-z.md', 'a-a-a.md', 'm-m-m.md', ]); }); }); describe('parseGitStatusFiles', () => { test('returns empty for empty input', () => { expect(parseGitStatusFiles('')).toEqual([]); expect(parseGitStatusFiles('\n\n')).toEqual([]); }); test('parses modified and untracked entries (XY-space-path format)', () => { const output = [ ' M packages/cli-display/package.json', ' M packages/event-bus/package.json', 'A packages/cli-display/CHANGELOG.md', '?? .changeset/quick-flowers-jump.md', ].join('\n'); expect(parseGitStatusFiles(output)).toEqual([ 'packages/cli-display/package.json', 'packages/event-bus/package.json', 'packages/cli-display/CHANGELOG.md', '.changeset/quick-flowers-jump.md', ]); }); test('handles deletions (changeset version removes consumed changesets)', () => { const output = [' D .changeset/old-bumpy-cats.md', 'D .changeset/consumed.md'].join('\n'); expect(parseGitStatusFiles(output)).toEqual([ '.changeset/old-bumpy-cats.md', '.changeset/consumed.md', ]); }); test('handles renames (uses destination path)', () => { const output = 'R old/path.md -> new/path.md'; expect(parseGitStatusFiles(output)).toEqual(['new/path.md']); }); test('ignores blank lines', () => { const output = [' M foo.txt', '', ' ', ' M bar.txt'].join('\n'); expect(parseGitStatusFiles(output)).toEqual(['foo.txt', 'bar.txt']); }); });