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
57 changes: 57 additions & 0 deletions e2e/linkRewrite.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"/,
);
Comment on lines +103 to +111

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion locks in a broken link. The doubled analyses/analyses/ path is what production currently renders (verified on the live site), but it 404s on GitHub — the file lives at analyses/2023/backstage/index.md. Mechanism: docusaurus.config.ts:92 sets editUrl: ${repo}/tree/main/analyses, and Docusaurus appends the plugin content path on top (compare the docs plugin: editUrl: ${repo}/tree/main at line 71 renders tree/main/docs/assistance.md). Consequence: every analyses page's "edit this page" link is dead, and this test would fail the eventual fix. Suggest fixing line 92 to ${repo}/tree/main in this PR (plus the config-value assertion in lib/docusaurusConfigBuildContext.test.mts) and asserting the single-analyses URL here.

});

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\/"/,
);
});
});
Loading