diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-08-03 01:21:30 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-08-03 01:21:30 +0300 |
| commit | 0e434881b3f8da1db58dba8d103ddc234ad17238 (patch) | |
| tree | a25d6e4655710d2e0b4d5c3fb3ca72570e5403a7 /website/scripts/docs-versions.integration.test.ts | |
| parent | 0a800b8f2e9894433c6ef9d106d10766ac408218 (diff) | |
fix(docs): publish only released documentation
Diffstat (limited to 'website/scripts/docs-versions.integration.test.ts')
| -rw-r--r-- | website/scripts/docs-versions.integration.test.ts | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/website/scripts/docs-versions.integration.test.ts b/website/scripts/docs-versions.integration.test.ts index c3f97bfe..5e2d36a5 100644 --- a/website/scripts/docs-versions.integration.test.ts +++ b/website/scripts/docs-versions.integration.test.ts @@ -5,6 +5,7 @@ import { join, resolve } from 'node:path'; import { tmpdir } from 'node:os'; const script = resolve(import.meta.dir, 'docs-versions.mjs'); +const prepareScript = resolve(import.meta.dir, 'prepare-docs.mjs'); const temporaryDirectories: string[] = []; afterEach(async () => { @@ -12,7 +13,7 @@ afterEach(async () => { }); describe('documentation release publishing', () => { - test('snapshots tagged next docs and promotes the same content', async () => { + test('snapshots tagged next docs and switches stable to generated snapshots', async () => { const root = await mkdtemp(join(tmpdir(), 'herdr-docs-')); temporaryDirectories.push(root); await write(root, 'website/src/content/docs/index.mdx', 'stable docs\n'); @@ -30,26 +31,63 @@ describe('documentation release publishing', () => { git(root, ['config', 'user.name', 'Test']); git(root, ['add', '.']); git(root, ['commit', '-qm', 'release fixture']); + git(root, ['tag', 'v0.9.0']); git(root, ['tag', 'v1.0.0']); runScript(root, ['publish', 'v1.0.0']); - expect(await read(root, 'website/src/content/docs/index.mdx')).toBe('next docs\n'); - expect(await read(root, 'website/src/data/config-reference.json')).toBe('{"next":true}\n'); + await expect(read(root, 'website/src/content/docs/index.mdx')).rejects.toThrow(); + await expect(read(root, 'website/src/data/config-reference.json')).rejects.toThrow(); expect(await read(root, 'README.md')).toBe('next readme\n'); expect(await read(root, 'README.zh-CN.md')).toBe('next readme zh-cn\n'); expect(await read(root, 'docs/versions/1.0.0/website/src/content/docs/index.mdx')).toBe('next docs\n'); const manifest = JSON.parse(await read(root, 'docs/versions/manifest.json')); expect(manifest.current).toBe('1.0.0'); + expect(manifest.stable_source).toBe('snapshot'); expect(manifest.versions[0]).toMatchObject({ version: '1.0.0', tag: 'v1.0.0', + commit: expect.stringMatching(/^[0-9a-f]{40}$/), source: 'docs/next/website/src/content/docs', }); + const previewCommit = git(root, ['rev-parse', 'HEAD']).trim(); + await write(root, 'docs/preview/website/src/content/docs/index.mdx', 'preview docs\n'); + await write( + root, + 'docs/preview/website/src/data/config-reference.json', + '{"preview":true}\n', + ); + await write( + root, + 'website/preview.json', + `${JSON.stringify({ build_id: 'preview-test', commit: previewCommit })}\n`, + ); + runPrepare(root); + expect(await read(root, 'website/src/content/docs/index.mdx')).toBe('next docs\n'); + expect(await read(root, 'website/src/content/docs/preview/index.mdx')).toContain( + 'Preview build `preview-test`', + ); + expect(await read(root, 'website/src/data/config-reference.json')).toBe('{"next":true}\n'); + await write(root, 'website/latest.json', '{"version":"1.0.0"}\n'); runScript(root, ['check']); + + await write(root, 'README.md', 'post-release correction\n'); + runScript(root, ['publish', 'v1.0.0']); + expect(await read(root, 'README.md')).toBe('post-release correction\n'); + + runScript(root, ['publish', 'v0.9.0']); + const archivedManifest = JSON.parse(await read(root, 'docs/versions/manifest.json')); + expect(archivedManifest.current).toBe('1.0.0'); + expect(archivedManifest.versions.map(({ version }) => version)).toEqual(['1.0.0', '0.9.0']); + expect(await read(root, 'README.md')).toBe('post-release correction\n'); + runScript(root, ['check']); + + delete archivedManifest.versions[0].commit; + await write(root, 'docs/versions/manifest.json', `${JSON.stringify(archivedManifest)}\n`); + expect(() => runScript(root, ['check'])).toThrow(); }); }); @@ -64,7 +102,7 @@ async function read(root: string, path: string) { } function git(root: string, args: string[]) { - execFileSync('git', args, { cwd: root, stdio: 'pipe' }); + return execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: 'pipe' }); } function runScript(root: string, args: string[]) { @@ -74,3 +112,11 @@ function runScript(root: string, args: string[]) { stdio: 'pipe', }); } + +function runPrepare(root: string) { + execFileSync('node', [prepareScript, '--docs-only'], { + cwd: root, + env: { ...process.env, HERDR_DOCS_REPO_ROOT: root }, + stdio: 'pipe', + }); +} |
