Skip to content
Open
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
28 changes: 28 additions & 0 deletions lib/remarkRewriteLinks/index.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ describe('rewriteHref (cross-plugin links)', () => {
'/analyses/2024/keda/analysis/',
);
});

it('strips .mdx from site-absolute /docs/.../foo.mdx', () => {
assert.strictEqual(
rewriteHref('/docs/analysis/criteria.mdx', 'analyses/2025/x/a.md'),
'/docs/analysis/criteria/',
);
});

it('adds a trailing slash to a bare (../)+docs link with no sub-path', () => {
assert.strictEqual(
rewriteHref('../docs', 'analyses/2025/x/a.md'),
'/docs/',
);
});
});

describe('rewriteHref (asset links)', () => {
Expand Down Expand Up @@ -151,6 +165,10 @@ describe('rewriteHref (passthroughs)', () => {
'../../../docs/images/gapi_info_arch.png',
);
});

it('leaves a bare query/fragment href (empty path) untouched', () => {
assert.strictEqual(rewriteHref('?view=raw', source), '?view=raw');
});
});

describe('remarkRewriteLinks (full pipeline)', () => {
Expand Down Expand Up @@ -194,4 +212,14 @@ describe('remarkRewriteLinks (full pipeline)', () => {
const out = await run(md, 'analyses/2023/backstage/x.md');
assert.strictEqual(out, '[x](/docs/analysis/criteria/ "a title")');
});

it('runs without a VFile path, falling back to an empty sourceFile', async () => {
const file = new VFile({ value: '[x](../../docs/analysis/criteria.md)' });
const out = await unified()
.use(remarkParse)
.use(remarkRewriteLinks, { assetBaseUrl: ASSET_BASE })
.use(remarkStringify)
.process(file);
assert.strictEqual(String(out).trim(), '[x](/docs/analysis/criteria/)');
});
});
Loading