Skip to content

Commit 209e4bd

Browse files
committed
Tests: add CHANGELOG consistency checks, fix forwardRef export assertion
1 parent fdef65c commit 209e4bd

2 files changed

Lines changed: 65 additions & 2 deletions

File tree

tests/bundle/changelog.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// @vitest-environment node
2+
/**
3+
* CHANGELOG.md consistency checks.
4+
*
5+
* Validates that version headers have matching compare links,
6+
* that [Unreleased] points to the latest version, and that
7+
* package.json version matches the latest CHANGELOG entry.
8+
*/
9+
10+
import { describe, it, expect } from 'vitest';
11+
import { readFileSync } from 'node:fs';
12+
import { resolve } from 'node:path';
13+
import { fileURLToPath } from 'node:url';
14+
15+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
16+
const ROOT = resolve(__dirname, '../..');
17+
18+
const changelog = readFileSync(resolve(ROOT, 'CHANGELOG.md'), 'utf-8');
19+
const pkg = JSON.parse(readFileSync(resolve(ROOT, 'package.json'), 'utf-8'));
20+
21+
/** Extract all `## [x.y.z]` version headers (excludes [Unreleased]). */
22+
function getVersionHeaders(text: string): string[] {
23+
return [...text.matchAll(/^## \[(\d+\.\d+\.\d+)\]/gm)].map((m) => m[1]);
24+
}
25+
26+
/** Extract all `[x.y.z]: <url>` reference links at the bottom. */
27+
function getCompareLinks(text: string): Map<string, string> {
28+
const links = new Map<string, string>();
29+
for (const m of text.matchAll(/^\[([^\]]+)\]:\s*(.+)$/gm)) {
30+
links.set(m[1], m[2].trim());
31+
}
32+
return links;
33+
}
34+
35+
describe('CHANGELOG.md', () => {
36+
const versions = getVersionHeaders(changelog);
37+
const links = getCompareLinks(changelog);
38+
39+
it('has at least one version entry', () => {
40+
expect(versions.length).toBeGreaterThan(0);
41+
});
42+
43+
it('latest version matches package.json', () => {
44+
expect(versions[0]).toBe(pkg.version);
45+
});
46+
47+
it('every version header has a matching compare link', () => {
48+
const missing = versions.filter((v) => !links.has(v));
49+
expect(missing).toEqual([]);
50+
});
51+
52+
it('[Unreleased] link points to latest version tag', () => {
53+
const unreleased = links.get('Unreleased');
54+
expect(unreleased).toBeDefined();
55+
expect(unreleased).toContain(`v${versions[0]}...HEAD`);
56+
});
57+
58+
it('compare links are in descending version order', () => {
59+
const linkVersions = [...links.keys()].filter((k) => k !== 'Unreleased' && /^\d+\.\d+\.\d+$/.test(k));
60+
expect(linkVersions).toEqual(versions);
61+
});
62+
});

tests/bundle/exports.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ describe('built bundle (dist/monkeytab.js)', () => {
3939
const bundle = await import(BUNDLE_PATH);
4040

4141
// Core public components from src/browser/index.ts
42-
expect(typeof bundle.MonkeyTable).toBe('function');
42+
// MonkeyTable is wrapped in forwardRef (since 0.3.0), which returns an object.
43+
expect(bundle.MonkeyTable).toBeDefined();
4344
expect(typeof bundle.BrowserClient).toBe('function');
4445
expect(typeof bundle.Grid).toBe('function');
4546
expect(typeof bundle.PaginationBar).toBe('function');
@@ -65,6 +66,6 @@ describe('built bundle (dist/monkeytab.js)', () => {
6566
// MonkeyTable is the headline export — guard explicitly so the
6667
// failure message is unambiguous if it ever disappears.
6768
expect(bundle.MonkeyTable).toBeDefined();
68-
expect(bundle.MonkeyTable.name).toBe('MonkeyTable');
69+
expect(bundle.MonkeyTable.displayName).toBe('MonkeyTable');
6970
});
7071
});

0 commit comments

Comments
 (0)