Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/upstream-state/hallmark/hallmark
Original file line number Diff line number Diff line change
@@ -1 +1 @@
407fa689f4a276f2fd389208d271d0fef08f5058
04977e15f3dfd6ee4b74c887dac3eb52665d6c92
10 changes: 6 additions & 4 deletions skills/hallmark/scripts/capture.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// of the viewport; --full captures the whole scroll height. It never draws a browser bar or a device
// frame: the page frames the picture in the theme's material.
import { mkdirSync, existsSync, writeFileSync } from 'node:fs';
import { join, dirname, resolve, relative } from 'node:path';
import { join, dirname, resolve, relative, sep } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { createRequire } from 'node:module';

Expand Down Expand Up @@ -70,7 +70,7 @@ if (has('cdp')) {
const dpr = await page.evaluate(() => devicePixelRatio).catch(() => 1);
const rel = relative(process.cwd(), file);
console.log(`${rel} ${Math.round(box.width * dpr)} x ${Math.round(box.height * dpr)} (app window)`);
console.log(` <img src="${rel}" width="${Math.round(box.width * dpr)}" height="${Math.round(box.height * dpr)}" alt="" loading="lazy">`);
console.log(` <img src="${rel.split(sep).join('/')}" width="${Math.round(box.width * dpr)}" height="${Math.round(box.height * dpr)}" alt="" loading="lazy">`);
await app.disconnect();
process.exit(0);
}
Expand Down Expand Up @@ -107,7 +107,9 @@ try {
await new Promise((r) => setTimeout(r, wait));
await p.bringToFront();
const slug = route === '/' ? 'home' : route.replace(/^\/|\/$/g, '').replace(/[^\w-]+/g, '-');
const file = join(out, `${name}-${slug}-${size}${selector ? '-part' : ''}.png`);
const stem = join(out, `${name}-${slug}-${size}${selector ? '-part' : ''}`);
let file = `${stem}.png`, suffix = 2;
while (made.some((m) => m.file === file)) file = `${stem}-${suffix++}.png`;
let shot;
if (selector) {
const el = await p.$(selector);
Expand All @@ -124,7 +126,7 @@ try {
for (const m of made) {
const rel = relative(process.cwd(), m.file);
console.log(`${rel} ${m.w} x ${m.h} (${m.route}, ${m.size})`);
console.log(` <img src="${rel}" width="${m.w}" height="${m.h}" alt="" loading="lazy">`);
console.log(` <img src="${rel.split(sep).join('/')}" width="${m.w}" height="${m.h}" alt="" loading="lazy">`);
}
if (!made.length) process.exitCode = 1;
else console.log(`\n${made.length} screenshot${made.length > 1 ? 's' : ''}. Look at each one before placing it: sample data only, nothing personal (names, emails, tokens), the screen in the state that tells the page's story.`);
25 changes: 22 additions & 3 deletions skills/hallmark/scripts/capture.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import test from 'node:test';

const skip = !process.env.HALLMARK_PUPPETEER || !process.env.CHROME_PATH ? 'set HALLMARK_PUPPETEER and CHROME_PATH for real-browser regressions' : false;
const script = fileURLToPath(new URL('./capture.mjs', import.meta.url));
async function capture(routes, prepare, check) {
async function capture(routes, prepare, check, out) {
const dir = mkdtempSync(join(tmpdir(), 'hallmark-capture-'));
const server = createServer((req, res) => {
if (req.url === '/redirect') { res.writeHead(302, { Location: '/ok' }); res.end(); return; }
const status = req.url === '/ok' ? 200 : req.url === '/missing' ? 404 : 500;
const status = ['/ok', '/', '/home', '/a/b', '/a-b', '/a-b-2'].includes(req.url) ? 200 : req.url === '/missing' ? 404 : 500;
res.writeHead(status, { 'Content-Type': 'text/html' });
res.end(`<html><title>${status}</title><h1>${status === 200 ? 'Owned product fixture' : 'Error document'}</h1></html>`);
});
await new Promise((r) => server.listen(0, '127.0.0.1', r));
try {
prepare?.(dir);
const result = await new Promise((resolve, reject) => {
const p = spawn(process.execPath, [script, `http://127.0.0.1:${server.address().port}`, '--routes', routes, '--sizes', 'desktop', '--wait', '0', '--scale', '1', '--out', dir], { env: process.env });
const p = spawn(process.execPath, [script, `http://127.0.0.1:${server.address().port}`, '--routes', routes, '--sizes', 'desktop', '--wait', '0', '--scale', '1', '--out', out || dir], { cwd: dir, env: process.env });
let stdout = '', stderr = '';
p.stdout.on('data', (s) => { stdout += s; });
p.stderr.on('data', (s) => { stderr += s; });
Expand Down Expand Up @@ -54,10 +54,29 @@ test('capture keeps successful routes when another route fails', { skip }, async
assert.deepEqual([...readFileSync(join(dir, 'screen-ok-desktop.png')).subarray(0, 8)], [137, 80, 78, 71, 13, 10, 26, 10]);
});
});
test('capture prints the <img> src with forward slashes', { skip }, async () => {
await capture('/ok', null, (dir, result) => {
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /<img src="images\/screens\/screen-ok-desktop\.png" /);
}, 'images/screens');
});
test('capture accepts a redirect to a successful document', { skip }, async () => {
await capture('/redirect', null, (dir, result) => {
assert.equal(result.status, 0, result.stderr);
assert.deepEqual(readdirSync(dir), ['screen-redirect-desktop.png']);
assert.match(result.stdout, /<img /);
});
});

for (const routes of ['/a/b,/a-b', '/,/home', '/a/b,/a-b,/a/b', '/a/b,/a-b,/a-b-2', '/a-b-2,/a-b,/a/b']) {
test(`capture keeps distinct files for colliding routes ${routes}`, { skip }, async () => {
await capture(routes, null, (dir, result) => {
assert.equal(result.status, 0, result.stdout + result.stderr);
const files = readdirSync(dir);
assert.equal(files.length, routes.split(',').length);
for (const file of files) assert.deepEqual([...readFileSync(join(dir, file)).subarray(0, 8)], [137, 80, 78, 71, 13, 10, 26, 10]);
const sources = [...result.stdout.matchAll(/<img src="([^"]+)"/g)].map((m) => m[1]);
assert.equal(new Set(sources).size, files.length);
});
});
}
Loading