From 0914206eb0c5628cb6f747e2c5eeac320d958968 Mon Sep 17 00:00:00 2001 From: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:43:49 -0500 Subject: [PATCH] test: add end-to-end coverage for link-rewrite plugins in the real build lib/docusaurusConfigPreprocessor.test.mts and lib/remarkRewriteLinks/index.test.mts cover the pure rewrite functions in isolation at 100% statement/branch coverage, but nothing verifies they still work once wired into the actual docusaurus.config.ts plugin registration (option shape, preset/plugin ordering). A regression there would pass every existing unit test and only surface as a broken link in a Netlify preview, which doesn't assert specific rewritten URLs. Add e2e/linkRewrite.test.mjs, which runs a real `docusaurus build` against this repo's own content and asserts the three known rewrite paths render correctly in the generated HTML: - README.md's imported /docs/*.md link loses its .md suffix - a cross-plugin analyses -> docs .md link resolves to a trailing slash - an unbundled .csv asset link rewrites to its GitHub blob URL Verified the regression coverage is real: temporarily dropping beforeDefaultRemarkPlugins from the analyses plugin's config made the csv assertion fail while all existing unit tests still passed. Wired as a new, separate 'test:e2e' script (not part of test:unit or test:coverage) since a full production build takes 30-60s - too slow for the fast unit-test/coverage gate, and c8 can't usefully instrument a spawned 'docusaurus build' subprocess anyway. Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- e2e/linkRewrite.test.mjs | 60 ++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 61 insertions(+) create mode 100644 e2e/linkRewrite.test.mjs diff --git a/e2e/linkRewrite.test.mjs b/e2e/linkRewrite.test.mjs new file mode 100644 index 00000000..16372356 --- /dev/null +++ b/e2e/linkRewrite.test.mjs @@ -0,0 +1,60 @@ +// cSpell:ignore keda litmuschaos +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; +import { execFileSync } from 'node:child_process'; +import { mkdtemp, readFile, rm } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import path from 'node:path'; +import url from 'node:url'; + +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); +const repoRoot = path.join(__dirname, '..'); + +// Unit tests (lib/docusaurusConfigPreprocessor.test.mts, +// lib/remarkRewriteLinks/index.test.mts) cover the pure rewrite functions in +// isolation. Neither one proves the rewrites actually survive being wired +// into Docusaurus's real build pipeline (plugin registration, option +// shape, remark plugin ordering). This suite runs the genuine +// `docusaurus build` against this repo's own content and asserts the +// known-affected pages render the rewritten links, so a wiring regression +// fails here even when the unit tests still pass. +describe('production build applies the link-rewrite plugins end-to-end', () => { + let outDir; + + before(async () => { + outDir = await mkdtemp(path.join(tmpdir(), 'techdocs-e2e-build-')); + execFileSync('npx', ['docusaurus', 'build', '--out-dir', outDir], { + cwd: repoRoot, + env: { ...process.env, BUILD_ENV: 'dev' }, + stdio: 'inherit', + }); + }); + + after(async () => { + if (outDir) await rm(outDir, { recursive: true, force: true }); + }); + + it('strips .md from a site-absolute /docs link imported from README.md', async () => { + const html = await readFile(path.join(outDir, 'index.html'), 'utf-8'); + assert.match(html, /href="\/docs\/assistance\/"/); + }); + + it('rewrites a cross-plugin analyses -> docs .md link to a trailing slash', async () => { + const html = await readFile( + path.join(outDir, 'analyses/2024/keda/analysis/index.html'), + 'utf-8', + ); + assert.match(html, /href="\/docs\/analysis\/criteria\/"/); + }); + + it('rewrites an unbundled .csv asset link to its GitHub blob URL', async () => { + const html = await readFile( + path.join(outDir, 'analyses/2023/backstage/index.html'), + 'utf-8', + ); + assert.match( + html, + /https:\/\/github\.com\/cncf\/techdocs\/blob\/main\/analyses\/2023\/backstage\/backstage-doc-survey\.csv/, + ); + }); +}); diff --git a/package.json b/package.json index 5beb9545..842f67d7 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "seq": "bash -c 'for cmd in \"$@\"; do npm run $cmd || exit 1; done' - ", "serve": "npm run docus:serve", "test:coverage": "c8 --reporter=text --reporter=lcov --exclude 'docusaurus.config.ts' --exclude 'lib/testHelpers/**' --check-coverage --lines 99 --statements 99 --branches 97 --functions 100 npm run test:unit", + "test:e2e": "node --test 'e2e/**/*.test.mjs'", "test:unit": "node --experimental-strip-types --experimental-test-module-mocks --test 'lib/**/*.test.mts' 'scripts/**/*.test.mjs'", "test": "npm run check && npm run test:unit", "typecheck": "tsc",