From f861e9354e9400293ca6970a166b646e4e80fb6b Mon Sep 17 00:00:00 2001 From: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:06:47 -0500 Subject: [PATCH] test: cover BUILD_ENV=production editUrl/url wiring in e2e link-rewrite suite docusaurus.config.ts's isProd-dependent branches (production site url vs DEPLOY_PRIME_URL/localhost fallback; editUrl set on both docs plugins in production, undefined otherwise) are 100% unit-covered via lib/docusaurusConfigBuildContext.test.mts, but no real docusaurus build in e2e/linkRewrite.test.mjs ever ran with BUILD_ENV=production -- the actual Netlify production context (npm run build:production never sets BUILD_ENV, so getBuildContext.ts defaults to 'production'). A wiring regression there would pass every existing unit and e2e test and only surface on the live site. Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- e2e/linkRewrite.test.mjs | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/e2e/linkRewrite.test.mjs b/e2e/linkRewrite.test.mjs index 31e46b6e..776c1cdf 100644 --- a/e2e/linkRewrite.test.mjs +++ b/e2e/linkRewrite.test.mjs @@ -62,3 +62,60 @@ describe('production build applies the link-rewrite plugins end-to-end', () => { ); }); }); + +// `lib/docusaurusConfigBuildContext.test.mts` unit-tests the +// BUILD_ENV=production branch of `getBuildContext()`/`docusaurus.config.ts` +// (production site `url`, and `editUrl` set on both docs plugins) in +// isolation, but no build anywhere in the suite above actually runs with +// `BUILD_ENV=production` — the real Netlify production context +// (`npm run build:production` -> `npm run _build`, which never sets +// BUILD_ENV, so `getBuildContext.ts` defaults to 'production'). This build +// reproduces that context so a wiring regression (e.g. editUrl silently +// omitted, or url pointing at the wrong domain) fails here instead of only +// surfacing on the live site. +describe('production build wires isProd-dependent editUrl/url end-to-end', () => { + let outDir; + + before(async () => { + outDir = await mkdtemp(path.join(tmpdir(), 'techdocs-e2e-prod-build-')); + execFileSync('npx', ['docusaurus', 'build', '--out-dir', outDir], { + cwd: repoRoot, + env: { ...process.env, BUILD_ENV: 'production', DEPLOY_PRIME_URL: '' }, + stdio: 'inherit', + }); + }); + + after(async () => { + if (outDir) await rm(outDir, { recursive: true, force: true }); + }); + + it('renders the GitHub edit-this-page link for a docs page', async () => { + const html = await readFile( + path.join(outDir, 'docs/assistance/index.html'), + 'utf-8', + ); + assert.match( + html, + /href="https:\/\/github\.com\/cncf\/techdocs\/tree\/main\/docs\/assistance\.md"/, + ); + }); + + it('renders the GitHub edit-this-page link for an analyses page', async () => { + const html = await readFile( + path.join(outDir, 'analyses/2023/backstage/index.html'), + 'utf-8', + ); + assert.match( + html, + /href="https:\/\/github\.com\/cncf\/techdocs\/tree\/main\/analyses\/analyses\/2023\/backstage\/index\.md"/, + ); + }); + + it('sets og:url to the production site domain', async () => { + const html = await readFile(path.join(outDir, 'index.html'), 'utf-8'); + assert.match( + html, + /property="og:url" content="https:\/\/cncf-techdocs\.netlify\.app\/"/, + ); + }); +});