ZDDC/tests/build-label.spec.js
ZDDC ea385b5366 Initial commit
ZDDC — Zero Day Document Control. A file-naming convention plus five
single-file HTML tools (archive, transmittal, classifier, mdedit,
landing) and an optional Go HTTP server (zddc-server) with ACL and a
virtual archive index. Self-contained, offline-capable, dependency-free.

See README.md for an overview, AGENTS.md and ARCHITECTURE.md for the
build/release/architecture detail, bootstrap/README.md for the
two-level deployment install pattern, and zddc/README.md for the
HTTP server.
2026-04-27 11:05:47 -05:00

64 lines
2.9 KiB
JavaScript

/**
* build-label.spec.js
*
* Verifies that the {{BUILD_LABEL}} placeholder is correctly substituted in all
* four tool dist and website files:
*
* - No placeholder text leaks through
* - The .build-timestamp element is present and visible in the browser
* - The label content is either a timestamp ("Built: 20...") or a version ("v...")
* - website/ files (when present) always show the version format
*
* Note: dist/ files may show either format depending on whether the last build
* was a dev build (timestamp) or a release build (version). Both are valid.
*/
import { test, expect } from '@playwright/test';
import * as path from 'path';
import * as fs from 'fs';
const tools = ['archive', 'transmittal', 'classifier', 'mdedit'];
for (const tool of tools) {
const distPath = path.resolve(`${tool}/dist/${tool}.html`);
const websitePath = path.resolve(`website/${tool}.html`);
test.describe(`${tool}: build-label`, () => {
test(`dist file: no placeholder text leaks through`, async () => {
const html = fs.readFileSync(distPath, 'utf8');
expect(html).not.toContain('{{BUILD_LABEL}}');
expect(html).not.toContain('{{BUILD_TIMESTAMP}}');
});
test(`dist file: .build-timestamp element is visible in browser`, async ({ page }) => {
const waitUntil = tool === 'mdedit' ? 'load' : 'domcontentloaded';
await page.goto(`file://${distPath}`, { waitUntil });
const el = page.locator('.build-timestamp');
await expect(el).toBeVisible({ timeout: 10000 });
});
test(`dist file: label is a valid timestamp or version string`, async () => {
const html = fs.readFileSync(distPath, 'utf8');
// BETA labels are wrapped in an inner <span style="color:red...">; non-BETA are bare text.
const match = html.match(/class="build-timestamp">(?:<span[^>]*>)?([^<]+?)(?:<\/span>)?</);
expect(match, 'build-timestamp element must have text content').toBeTruthy();
const label = match[1];
const isTimestamp = /^Built: 20\d\d-\d\d-\d\d \d\d:\d\d:\d\d( BETA)?$/.test(label);
const isVersion = /^v\d+\.\d+\.\d+( BETA)?$/.test(label);
expect(isTimestamp || isVersion,
`Expected timestamp or version, got: "${label}"`
).toBe(true);
});
test(`website file: label shows version format (release build)`, async () => {
if (!fs.existsSync(websitePath)) {
test.skip(true, `website/${tool}.html not present — run sh ${tool}/build.sh --release first`);
return;
}
const html = fs.readFileSync(websitePath, 'utf8');
expect(html).not.toContain('{{BUILD_LABEL}}');
expect(html).not.toContain('{{BUILD_TIMESTAMP}}');
expect(html).toMatch(/class="build-timestamp">(?:<span[^>]*>)?v\d+\.\d+\.\d+( BETA)?(?:<\/span>)?</);
});
});
}