140 lines
8 KiB
TypeScript
140 lines
8 KiB
TypeScript
// The teaser video (media/teaser): the scan text it shows is the real `storebound scan` output of the teaser fixtures,
|
|
// every cut sits on the beat grid, every caption is short and stays readable, every scene holds long enough.
|
|
import { beforeAll, describe, expect, test } from 'bun:test';
|
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
|
|
const ROOT = join(import.meta.dir, '..');
|
|
const CLI = join(ROOT, 'cli', 'index.ts');
|
|
const FX = join(import.meta.dir, 'fixtures', 'scan');
|
|
|
|
interface Scene { id: string; from: number; to: number; start: number; end: number; in: string | null }
|
|
interface Finding { sev: string; guideline: string; title: string; where: string; fix: string; skill: string }
|
|
interface Teaser {
|
|
BEAT: number; DURATION: number; SCENES: Scene[];
|
|
CAPTIONS: { id: string; lines: string[] }[];
|
|
captionTimes(): { id: string; words: string; count: number; at: number; from: number; to: number; hold: number }[];
|
|
SCAN_HEAD: { text: string }[]; SDKS: { name: string; what: string; dep: string; where: string }[];
|
|
RISKS_LINE: string; FINDINGS: Finding[]; RESCAN_LINE: string; RESCAN_NONE: string;
|
|
DECL_LINES: { what: string; value: string; where: string }[]; DECL_ASK: string; CMD: string;
|
|
MORE: { at: number; cmd: string; lines: string[]; stat: { text: string } }[]; MORE_CUTS: number[];
|
|
}
|
|
const path: string = join(ROOT, 'media/teaser/script.js');
|
|
const T = (await import(path)) as Teaser;
|
|
|
|
const scanText = (dir: string, demo: boolean): string => {
|
|
const env = { ...process.env, NO_COLOR: '1', REVIEW_DEMO_USER: demo ? 'demo@example.com' : '', REVIEW_DEMO_PASSWORD: demo ? 'example' : '' };
|
|
const r = Bun.spawnSync(['bun', CLI, 'scan', '--dir', join(FX, dir)], { env, stdout: 'pipe', stderr: 'pipe' });
|
|
// exit code 1 when blockers are found (the fixture before the fixes), 0 after
|
|
expect(r.exitCode).toBe(demo ? 0 : 1);
|
|
return r.stdout.toString() + r.stderr.toString();
|
|
};
|
|
let before = '', after = '';
|
|
beforeAll(() => { before = scanText('teaser', false); after = scanText('teaser-fixed', true); });
|
|
|
|
/** Runs a CLI command as the montage shows it (`storebound …` -> bun cli/index.ts …), offline, no store keys. */
|
|
const run = (cmd: string, cwd: string): string => {
|
|
const env = { ...process.env, NO_COLOR: '1', ASC_KEY_ID: '', ASC_ISSUER_ID: '', ASC_P8: '', PLAY_SERVICE_ACCOUNT: '' };
|
|
const r = Bun.spawnSync(['bun', CLI, ...cmd.replace(/^storebound /, '').split(' ')], { cwd, env, stdout: 'pipe', stderr: 'pipe' });
|
|
expect(r.exitCode, cmd).toBe(0);
|
|
return r.stdout.toString() + r.stderr.toString();
|
|
};
|
|
/** A throwaway Capacitor project with an example.com config (as in tests/build-sign.test.ts) for `play build --dry`. */
|
|
function buildProject(): string {
|
|
const d = mkdtempSync(join(tmpdir(), 'sb-teaser-'));
|
|
const put = (f: string, body = ''): void => { mkdirSync(join(d, f, '..'), { recursive: true }); writeFileSync(join(d, f), body); };
|
|
put('storebound.config.ts', `export default { app: { name: 'Example', privacyPolicyUrl: 'https://example.com/p', supportUrl: 'https://example.com', website: 'https://example.com', contactEmail: 'hi@example.com' },
|
|
languages: [{ id: 'en', apple: 'en-US', play: 'en-US' }], apple: { bundleId: 'com.example.game' }, play: { packageName: 'com.example.game' } };\n`);
|
|
put('capacitor.config.ts', 'export default {}');
|
|
put('android/settings.gradle'); put('android/gradlew', '#!/bin/sh'); put('android/app/build.gradle');
|
|
return d;
|
|
}
|
|
|
|
describe('teaser: the CLI montage is real output', () => {
|
|
test('three panels, two cuts on the beat', () => {
|
|
expect(T.MORE).toHaveLength(3);
|
|
expect(T.MORE_CUTS).toEqual([T.MORE[1]!.at, T.MORE[2]!.at]);
|
|
const s = T.SCENES.find(x => x.id === 'more')!;
|
|
expect(T.MORE[0]!.at).toBe(s.start);
|
|
for (const t of T.MORE_CUTS) { expect(t).toBeGreaterThan(s.start); expect(t).toBeLessThan(s.end); }
|
|
});
|
|
test('`storebound api coverage`: the operation counts (revision dates left out)', () => {
|
|
const p = T.MORE[0]!;
|
|
expect(p.cmd).toBe('storebound api coverage');
|
|
const out = run(p.cmd, ROOT).replace(/ \(\d{8}\)/g, '');
|
|
for (const l of p.lines) expect(out).toContain(l);
|
|
const ops = (name: string): number => Number(out.match(new RegExp(`${name}[^:\n]*: (\\d+) operations`))![1]);
|
|
const apple = ops('App Store Connect API'), play = ops('Google Play Android Developer API') + ops('Google Play Developer Reporting API');
|
|
expect(p.stat.text).toBe(`*${apple}* App Store Connect + *${play}* Google Play endpoints`);
|
|
});
|
|
test('`storebound play build --dry`: the plan (clock and [build] prefix left out, the gradle flags trimmed)', () => {
|
|
const p = T.MORE[1]!;
|
|
expect(p.cmd).toStartWith('storebound play build --dry');
|
|
const d = buildProject();
|
|
try {
|
|
const out = run(p.cmd, d).split('\n').map(l => l.replace(/^\d\d:\d\d:\d\d \[build\] /, '').replace(/ \(\d+s\)$/, ''));
|
|
for (const l of p.lines) expect(out.some(o => o.startsWith(l)), l).toBe(true);
|
|
} finally { rmSync(d, { recursive: true, force: true }); }
|
|
});
|
|
test('`storebound console fill apple-app-privacy --dry` in examples/demo-app: answer lines (source column left out)', () => {
|
|
const p = T.MORE[2]!;
|
|
expect(p.cmd).toBe('storebound console fill apple-app-privacy --dry');
|
|
const out = run(p.cmd, join(ROOT, 'examples/demo-app')).split('\n').map(l => l.trim().replace(/\s+\([^()]*\)$/, ''));
|
|
for (const l of p.lines) expect(out).toContain(l);
|
|
expect(out.join('\n')).toContain('press Publish yourself');
|
|
});
|
|
});
|
|
|
|
describe('teaser: the scan text is real', () => {
|
|
test('command, header, SDKs and the risks line come from `storebound scan` of tests/fixtures/scan/teaser', () => {
|
|
expect(T.CMD).toBe('storebound scan');
|
|
for (const l of T.SCAN_HEAD) expect(before).toContain(l.text);
|
|
for (const s of T.SDKS) expect(before).toMatch(new RegExp(`${s.name}\\s+${s.what.replace(/[()]/g, '\\$&')} · ${s.dep} \\(${s.where}\\)`));
|
|
expect(before).toContain(T.RISKS_LINE);
|
|
});
|
|
test('the five findings: severity, guideline, title, file:line, a verbatim piece of the fix, the skill', () => {
|
|
expect(T.FINDINGS).toHaveLength(5);
|
|
const blocks = before.split(/\n\s+\d\. /).slice(1);
|
|
T.FINDINGS.forEach((f, i) => {
|
|
const b = blocks[i]!;
|
|
expect(b.startsWith(`${f.sev.padEnd(7)} ${f.guideline} · App Store · ${f.title}`)).toBe(true);
|
|
expect(b).toContain(`at ${f.where}`);
|
|
expect(b).toContain(`skill: ${f.skill}`);
|
|
expect(b.match(/fix: (.*)/)![1]).toContain(f.fix);
|
|
});
|
|
});
|
|
test('declarations proposal lines', () => {
|
|
for (const d of T.DECL_LINES) expect(before).toContain(`detected ${d.what}: ${d.value}`);
|
|
for (const d of T.DECL_LINES) expect(before).toContain(`(${d.where})`);
|
|
expect(before).toContain(T.DECL_ASK);
|
|
});
|
|
test('the re-scan after the fixes (tests/fixtures/scan/teaser-fixed, demo account in the environment) is clean', () => {
|
|
expect(after).toContain(T.RESCAN_LINE);
|
|
expect(after).toContain(T.RESCAN_NONE);
|
|
});
|
|
});
|
|
|
|
describe('teaser: timing', () => {
|
|
const near = (x: number): boolean => Math.abs(x / T.BEAT - Math.round(x / T.BEAT)) < 1e-9;
|
|
test('scenes are contiguous, cover the video and cut on the beat', () => {
|
|
expect(T.SCENES[0]!.start).toBe(0);
|
|
for (let i = 1; i < T.SCENES.length; i++) expect(T.SCENES[i]!.start).toBe(T.SCENES[i - 1]!.end);
|
|
expect(T.SCENES.at(-1)!.end).toBeCloseTo(T.DURATION, 9);
|
|
for (const s of T.SCENES) expect(near(s.start), s.id).toBe(true);
|
|
expect(T.DURATION).toBeGreaterThan(29);
|
|
expect(T.DURATION).toBeLessThan(38);
|
|
});
|
|
test('every scene holds at least 2.5 s', () => {
|
|
for (const s of T.SCENES) expect(s.end - s.start, s.id).toBeGreaterThanOrEqual(2.5);
|
|
});
|
|
test('captions: at most 7 words, fully on screen for at least 1.2 s, never overlapping', () => {
|
|
const c = T.captionTimes();
|
|
expect(c).toHaveLength(T.CAPTIONS.length);
|
|
for (const x of c) {
|
|
expect(x.count, x.words).toBeLessThanOrEqual(7);
|
|
expect(x.hold, x.words).toBeGreaterThanOrEqual(1.2);
|
|
}
|
|
for (let i = 1; i < c.length; i++) expect(c[i]!.at).toBeGreaterThanOrEqual(c[i - 1]!.to);
|
|
});
|
|
});
|