Skip to content
Merged
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
57 changes: 57 additions & 0 deletions e2e/linkRewrite.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,60 @@ describe('production build rewrites .mdx link destinations end-to-end', () => {
);
});
});

// `lib/remarkRewriteLinks/index.test.mts` unit-tests rewriteHref()'s bare
// query/fragment branch directly ("leaves a bare query/fragment href (empty
// path) untouched", asserting `rewriteHref('?view=raw', source) ===
// '?view=raw'`), but no suite had exercised that branch through the real
// remark pipeline wired into a Docusaurus build: splitHref() returns an
// empty `path` only when the href is a query string with no leading path
// segment, so `if (!original) return href;` short-circuits before the
// cross-plugin/asset rewrite logic runs. Every other e2e link in this file
// has a non-empty path, so a regression that dropped or mis-handled this
// early return (e.g. one that started stripping the query string instead of
// leaving the href untouched) would pass every existing unit and e2e
// assertion. This suite writes a temporary fixture containing such a link
// into the real content tree so the genuine build exercises it, removing
// the fixture afterward so no content change survives the test run.
describe('production build leaves a bare query-string link destination untouched end-to-end', () => {
const fixture = path.join(
repoRoot,
'analyses/2024/keda/e2e-bare-query-fixture.md',
);
let outDir;

before(async () => {
await writeFile(
fixture,
[
'---',
'title: E2E bare query-string fixture',
'---',
'',
'# E2E bare query-string fixture',
'',
'See [raw view](?view=raw) for details.',
'',
].join('\n'),
);
outDir = await mkdtemp(path.join(tmpdir(), 'techdocs-e2e-bare-query-'));
execFileSync('npx', ['docusaurus', 'build', '--out-dir', outDir], {
cwd: repoRoot,
env: { ...process.env, BUILD_ENV: 'dev', DEPLOY_PRIME_URL: '' },
stdio: 'inherit',
});
});

after(async () => {
await unlink(fixture).catch(() => {});
if (outDir) await rm(outDir, { recursive: true, force: true });
});

it('leaves the bare query-string href unchanged instead of rewriting or stripping it', async () => {
const html = await readFile(
path.join(outDir, 'analyses/2024/keda/e2e-bare-query-fixture/index.html'),
'utf-8',
);
assert.match(html, /<a class="" href="\/\?view=raw">raw view<\/a>/);
});
});