Repository navigation
test: cover deploy-preview branch/repo wiring in e2e link-rewrite suite #426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,3 +62,52 @@ describe('production build applies the link-rewrite plugins end-to-end', () => { | |||||||||||
| ); | ||||||||||||
| }); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| // The production build above always resolves to the `main` branch/repo | ||||||||||||
| // because `BUILD_ENV=dev` + a cleared `DEPLOY_PRIME_URL` keeps | ||||||||||||
| // getBuildContext() out of deploy-preview mode. getCurrentBranch() and | ||||||||||||
| // getGitHubRepoUrl() are 100% unit-covered in isolation | ||||||||||||
| // (lib/getCurrentBranch.test.mts, lib/getGitHubRepoUrl.test.mts), but no | ||||||||||||
| // suite asserted that docusaurus.config.ts's assetBaseUrl actually wires | ||||||||||||
| // their deploy-preview output into the rewritten .csv link during a real | ||||||||||||
| // build. This suite exercises exactly that path with deterministic env | ||||||||||||
| // vars, so a regression in that wiring fails here even when the unit | ||||||||||||
| // tests for each helper still pass in isolation. | ||||||||||||
| describe('deploy-preview build wires branch/repo detection into the rewritten .csv link', () => { | ||||||||||||
| let outDir; | ||||||||||||
|
|
||||||||||||
| before(async () => { | ||||||||||||
| outDir = await mkdtemp(path.join(tmpdir(), 'techdocs-e2e-preview-')); | ||||||||||||
| execFileSync('npx', ['docusaurus', 'build', '--out-dir', outDir], { | ||||||||||||
| cwd: repoRoot, | ||||||||||||
| env: { | ||||||||||||
| ...process.env, | ||||||||||||
| BUILD_ENV: 'deploy-preview', | ||||||||||||
| DEPLOY_PRIME_URL: 'https://deploy-preview-1--cncf-techdocs.netlify.app', | ||||||||||||
| // Pin branch/repo detection to deterministic values instead of | ||||||||||||
| // relying on the sandbox's ambient git checkout/remote state, | ||||||||||||
| // matching the env vars getCurrentBranch()/getGitHubRepoUrl() | ||||||||||||
| // already read for Netlify/GitHub Actions deploy-preview builds. | ||||||||||||
| GITHUB_REF_NAME: 'e2e-preview-branch', | ||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| REPOSITORY_URL: 'https://github.com/example-org/example-repo', | ||||||||||||
| }, | ||||||||||||
| stdio: 'inherit', | ||||||||||||
| }); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| after(async () => { | ||||||||||||
| if (outDir) await rm(outDir, { recursive: true, force: true }); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('rewrites the .csv asset link to the preview branch and repo, not main', async () => { | ||||||||||||
| const html = await readFile( | ||||||||||||
| path.join(outDir, 'analyses/2023/backstage/index.html'), | ||||||||||||
| 'utf-8', | ||||||||||||
| ); | ||||||||||||
| assert.match( | ||||||||||||
| html, | ||||||||||||
| /https:\/\/github\.com\/example-org\/example-repo\/blob\/e2e-preview-branch\/analyses\/2023\/backstage\/backstage-doc-survey\.csv/, | ||||||||||||
| ); | ||||||||||||
| assert.doesNotMatch(html, /\/blob\/main\//); | ||||||||||||
| }); | ||||||||||||
| }); | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCurrentBranch()(lib/getCurrentBranch.ts:5-10) readsHEAD || BRANCH || GITHUB_HEAD_REF || GITHUB_REF_NAME, in that order, and this env block spreads...process.env. Pinning onlyGITHUB_REF_NAMEtherefore loses to any ambient higher-precedence var: in a GitHub Actions PR runGITHUB_HEAD_REFis always set, and on NetlifyHEAD/BRANCHare. Reproduced:GITHUB_HEAD_REF=pr-head-branch node --test e2e/linkRewrite.test.mjsfails this suite (branch resolves topr-head-branch, so both the match and thedoesNotMatch(/\/blob\/main\//)expectations break — the latter because the URL no longer contains the pinned branch). The first suite in this file already clearsDEPLOY_PRIME_URLfor exactly this reason; this block needs the same treatment for the branch vars.