From 806914e2a388910f59f4ce5b1f2aa97bd964e891 Mon Sep 17 00:00:00 2001 From: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:44:51 -0500 Subject: [PATCH] test: cover 4 uncovered branches in remarkRewriteLinks Branch coverage for lib/remarkRewriteLinks/index.ts was 89.74% (c8 --reporter=text). Adds 4 unit test cases that exercise: a bare query/fragment href (empty path after split), a cross-plugin link with no sub-path (undefined capture group), the .mdx branch of the site-absolute strip-extension ternary, and running the plugin against a VFile with no path set. Branch coverage is now 100%. Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- lib/remarkRewriteLinks/index.test.mts | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/remarkRewriteLinks/index.test.mts b/lib/remarkRewriteLinks/index.test.mts index 560dda02..2f11351c 100644 --- a/lib/remarkRewriteLinks/index.test.mts +++ b/lib/remarkRewriteLinks/index.test.mts @@ -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)', () => { @@ -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)', () => { @@ -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/)'); + }); });