Files
eleith 67cb29b7f6
ci/woodpecker/pr/config Pipeline was successful
ci/woodpecker/pr/hledger Pipeline was successful
ci/woodpecker/pr/jobs Pipeline was successful
ci/woodpecker/pr/snapshots Pipeline was successful
ci/woodpecker/pr/web Pipeline was successful
ci/woodpecker/pr/worker Pipeline was successful
ci/woodpecker/push/config Pipeline was successful
ci/woodpecker/push/hledger Pipeline was successful
ci/woodpecker/push/jobs Pipeline was successful
ci/woodpecker/push/snapshots Pipeline was successful
ci/woodpecker/push/web Pipeline was successful
ci/woodpecker/push/worker Pipeline was successful
test: generate small fixtures and simplify CI setup
2026-11-06 16:38:05 -08:00

46 lines
1.9 KiB
JavaScript

import { lstat, mkdir } from 'node:fs/promises';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { prepareBrowserFixture } from './fixture.js';
async function main() {
const root = fileURLToPath(new URL('../../../', import.meta.url));
if (process.cwd() !== resolve(root) || process.argv.length !== 2) {
throw new Error('Run node apps/web/e2e/prepare.js from the repository root without arguments.');
}
const username = process.env.PLAYWRIGHT_USERNAME;
if (!username?.trim() || username.includes('${')) {
throw new Error('Set an explicit fictional PLAYWRIGHT_USERNAME before preparing the fixture.');
}
const cache = join(root, 'apps', 'web', '.cache');
try {
await mkdir(cache, { mode: 0o700 });
} catch (error) {
if (!(error instanceof Error) || !('code' in error) || error.code !== 'EEXIST') throw error;
// Never follow an operator-controlled cache symlink to another deployment.
if (!(await lstat(cache)).isDirectory())
throw new Error('Browser cache must be a directory.', { cause: error });
}
await prepareBrowserFixture(join(cache, 'browser-fixture'), {
journal: '/journal/main.journal',
auth: {
secret: '${AUTH_SECRET}',
credentials: { username, password: '${AUTH_PASSWORD}' }
}
});
console.log('Prepared apps/web/.cache/browser-fixture for the fictional browser deployment.');
}
// Importing the helper or CLI never materializes a deployment.
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
try {
await main();
} catch {
// Do not print environment values, config contents, or unsanitized errors.
console.error(
'Browser fixture preparation failed. Run from the repository root without arguments, set an explicit fictional PLAYWRIGHT_USERNAME, and use an absent apps/web/.cache/browser-fixture directory. Existing files were not overwritten.'
);
process.exitCode = 1;
}
}