aboutsummaryrefslogtreecommitdiff
path: root/website/scripts/docs-preview.integration.test.ts
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-09-01 14:48:45 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-09-01 14:48:45 +0300
commit8a6d697308162874a236c84aac0b0f8c7ac01f83 (patch)
treeed7dc7e8c6f50d66bde721fae78576aede929f66 /website/scripts/docs-preview.integration.test.ts
parentb54a78aa510b87d1e3b56c619b72eaeb59e4a2a1 (diff)
refactor: separate website presentation from runtime
Diffstat (limited to 'website/scripts/docs-preview.integration.test.ts')
-rw-r--r--website/scripts/docs-preview.integration.test.ts90
1 files changed, 0 insertions, 90 deletions
diff --git a/website/scripts/docs-preview.integration.test.ts b/website/scripts/docs-preview.integration.test.ts
deleted file mode 100644
index f850689c..00000000
--- a/website/scripts/docs-preview.integration.test.ts
+++ /dev/null
@@ -1,90 +0,0 @@
-import { afterEach, describe, expect, test } from 'bun:test';
-import { execFileSync } from 'node:child_process';
-import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
-import { join, resolve } from 'node:path';
-import { tmpdir } from 'node:os';
-
-const script = resolve(import.meta.dir, 'docs-preview.mjs');
-const temporaryDirectories: string[] = [];
-
-afterEach(async () => {
- await Promise.all(
- temporaryDirectories.splice(0).map((path) => rm(path, { recursive: true, force: true })),
- );
-});
-
-describe('preview documentation snapshots', () => {
- test('snapshots and validates the selected commit exactly', async () => {
- const root = await fixture();
- const commit = git(root, ['rev-parse', 'HEAD']).trim();
- await write(root, 'docs/preview/website/stale.mdx', 'stale\n');
- await writeManifest(root, commit);
-
- runScript(root, ['snapshot', commit]);
- runScript(root, ['check']);
-
- expect(await read(root, 'docs/preview/website/src/content/docs/index.mdx')).toBe(
- 'selected preview\n',
- );
- await expect(read(root, 'docs/preview/website/stale.mdx')).rejects.toThrow();
- });
-
- test('rejects snapshot drift', async () => {
- const root = await fixture();
- const commit = git(root, ['rev-parse', 'HEAD']).trim();
- await writeManifest(root, commit);
- runScript(root, ['snapshot', commit]);
- await write(root, 'docs/preview/website/src/content/docs/index.mdx', 'changed\n');
-
- expect(() => runScript(root, ['check'])).toThrow();
- });
-});
-
-async function fixture() {
- const root = await mkdtemp(join(tmpdir(), 'herdr-preview-docs-'));
- temporaryDirectories.push(root);
- await write(root, 'docs/next/website/src/content/docs/index.mdx', 'selected preview\n');
- await write(root, 'docs/next/website/src/data/config-reference.json', '{"preview":true}\n');
- git(root, ['init', '-q']);
- git(root, ['config', 'user.email', 'test@example.com']);
- git(root, ['config', 'user.name', 'Test']);
- git(root, ['add', '.']);
- git(root, ['commit', '-qm', 'preview fixture']);
- return root;
-}
-
-async function writeManifest(root: string, commit: string) {
- await write(
- root,
- 'website/preview.json',
- `${JSON.stringify({
- schema_version: 1,
- channel: 'preview',
- build_id: 'test-build',
- commit,
- builds: { 'test-build': { commit, tag: 'preview-test-build' } },
- })}\n`,
- );
-}
-
-async function write(root: string, path: string, content: string) {
- const destination = resolve(root, path);
- await mkdir(resolve(destination, '..'), { recursive: true });
- await writeFile(destination, content, 'utf8');
-}
-
-async function read(root: string, path: string) {
- return readFile(resolve(root, path), 'utf8');
-}
-
-function git(root: string, args: string[]) {
- return execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: 'pipe' });
-}
-
-function runScript(root: string, args: string[]) {
- execFileSync('node', [script, ...args], {
- cwd: root,
- env: { ...process.env, HERDR_DOCS_REPO_ROOT: root },
- stdio: 'pipe',
- });
-}