Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 26x 26x 26x 26x 26x 26x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 1x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 1x 1x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 47x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 51x 47x 26x 26x 1x 1x 45x 41x 41x 4x 45x 6x 6x 6x 6x 6x 6x 3x 3x 6x 1x 1x 6x 6x 1x 1x 6x 6x 6x 6x 1x 1x 1x 1x 6x 6x 6x 6x 4x 4x 1x | import { DyE2E_VQA_FeatureManifest_Interface } from '../_models/interfaces/feature-manifest.interface';
import { DyE2E_VQA_FlowStep_Interface } from '../_models/interfaces/flow-step.interface';
import { DyE2E_VQA_VisualState_Interface } from '../_models/interfaces/visual-state.interface';
/**
* `DyE2E_VQA_CaptureSpec_Generator` — manifest → executable Playwright spec emit (MP-B).
*
* A generált `.spec.ts` minden `viewport × state` kombinációra:
* 1. Beállítja a viewport-méretet + orientációt
* 2. Végrehajtja a manifest-szintű `flowSteps`-et
* 3. Végrehajtja a state-szintű `prepareFlow`-t
* 4. `page.screenshot()` full-page + viewport-only
* 5. DOM-snapshot szerializáció
* 6. axe-core a11y scan
* 7. 16 DOM-evidence-detektor futtatása
* 8. Artifact-okat a `OUT_DIR`-be ír
*
* **scope-LOCK**: NEM tartalmaz AI-call-ot. A `OUT_DIR` lesz a review-bundle alapja.
*
* A generált spec environment-driven:
* - `VQA_OUT_DIR`: output mappa (default: `./review-bundles/<featureId>/run-${Date.now()}`)
* - `VQA_BASE_URL`: target base-URL (default: `http://localhost:4200`)
* - `VQA_RUN_ID`: stable run-azonosító
*/
export interface DyE2E_VQA_CaptureSpec_Options {
/** Header-comment (autogen, do-not-edit). */
headerComment?: string;
/** Manifest-relative path-ek, ha kell. */
manifestImportPath?: string;
}
export class DyE2E_VQA_CaptureSpec_Generator {
static emit(
manifest: DyE2E_VQA_FeatureManifest_Interface,
options?: DyE2E_VQA_CaptureSpec_Options,
): string {
const header: string = options?.headerComment ??
`// AUTOGEN by @futdevpro/dynamo-e2e/vqa — DyE2E_VQA_CaptureSpec_Generator. DO NOT EDIT.`;
const orientations: ('portrait' | 'landscape')[] =
manifest.orientations && manifest.orientations.length > 0
? manifest.orientations
: ['portrait'];
const ctaSelectors: string[] = (manifest.criticalElements ?? [])
.filter((c) => c.regionType === 'primary-cta')
.map((c) => c.selector);
const criticalElementsLiteral: string = JSON.stringify(manifest.criticalElements ?? []);
const ctaSelectorsLiteral: string = JSON.stringify(ctaSelectors);
const manifestLiteral: string = JSON.stringify({
featureId: manifest.featureId,
featureName: manifest.featureName,
route: manifest.route,
});
const featureFlowEmit: string = this.emitFlowSteps(manifest.flowSteps ?? [], ' ');
const stateBlocks: string = manifest.states.map((s) => this.emitStateTest(
manifest,
s,
orientations,
ctaSelectorsLiteral,
criticalElementsLiteral,
featureFlowEmit,
)).join('\n\n');
const a11yEnabled: boolean =
((manifest.testDataSetup as { a11yEnabled?: boolean } | undefined)?.a11yEnabled) === true;
return `${header}
import { test, expect, type Page } from '@playwright/test';
import * as fs from 'fs';
import * as path from 'path';
import {
DyE2E_VQA_DomEvidencePageScripts_Const,
DyE2E_VQA_AntiFlake_Css_Const,${a11yEnabled ? `
DyE2E_VQA_Axe_CdnUrl_Const,
DyE2E_VQA_AxeRunScript_Const,` : ''}
} from '@futdevpro/dynamo-e2e/vqa';
const VQA_OUT_DIR: string = process.env.VQA_OUT_DIR
|| path.join(process.cwd(), 'review-bundles', '${manifest.featureId}', \`run-\${process.env.VQA_RUN_ID || Date.now()}\`);
const VQA_BASE_URL: string = process.env.VQA_BASE_URL || 'http://localhost:4200';
const A11Y_ENABLED: boolean = ${a11yEnabled};
const FEATURE = ${manifestLiteral};
function ensureDir(p: string): void {
fs.mkdirSync(p, { recursive: true });
}
async function stabilizePage(page: Page): Promise<void> {
// Anti-flake: disable animations + transitions
await page.addStyleTag({ content: DyE2E_VQA_AntiFlake_Css_Const });
// Font-loading await — szövegmérés stabilitásához
await page.evaluate(() => document.fonts && document.fonts.ready);
}
async function runDetectors(page: Page, ctaSelectors: string[], stateOut: string): Promise<unknown[]> {
const evidence: unknown[] = [];
for (const [, raw] of Object.entries(DyE2E_VQA_DomEvidencePageScripts_Const)) {
const script: string = (raw as string).replace(
/__CRITICAL_CTA_SELECTORS__/g, JSON.stringify(ctaSelectors),
);
try {
const r: unknown = await page.evaluate(script);
evidence.push(r);
} catch (e) {
evidence.push({ error: String(e) });
}
}
ensureDir(stateOut);
fs.writeFileSync(path.join(stateOut, 'evidence.json'), JSON.stringify(evidence, null, 2));
return evidence;
}
${a11yEnabled ? `async function runAxe(page: Page, stateOut: string): Promise<void> {
try {
await page.addScriptTag({ url: DyE2E_VQA_Axe_CdnUrl_Const });
const result: unknown = await page.evaluate(DyE2E_VQA_AxeRunScript_Const);
ensureDir(stateOut);
fs.writeFileSync(path.join(stateOut, 'a11y.json'), JSON.stringify(result, null, 2));
} catch (e) {
fs.writeFileSync(path.join(stateOut, 'a11y.json'),
JSON.stringify({ error: String(e) }, null, 2));
}
}` : `async function runAxe(_page: Page, _stateOut: string): Promise<void> { /* a11yEnabled=false */ }`}
async function captureDomSnapshot(page: Page, stateOut: string): Promise<void> {
const dom: unknown = await page.evaluate(() => {
return {
viewportWidth: window.innerWidth,
viewportHeight: window.innerHeight,
bodyScrollHeight: document.body.scrollHeight,
bodyScrollWidth: document.body.scrollWidth,
activeElement: document.activeElement
? { tag: document.activeElement.tagName.toLowerCase(),
id: (document.activeElement as HTMLElement).id || null }
: null,
scrollY: window.scrollY,
scrollX: window.scrollX,
title: document.title,
url: location.href,
};
});
ensureDir(stateOut);
fs.writeFileSync(path.join(stateOut, 'dom-snapshot.json'), JSON.stringify(dom, null, 2));
}
${stateBlocks}
`;
}
private static emitStateTest(
manifest: DyE2E_VQA_FeatureManifest_Interface,
state: DyE2E_VQA_VisualState_Interface,
orientations: ('portrait' | 'landscape')[],
ctaSelectorsLiteral: string,
_criticalElementsLiteral: string,
featureFlowEmit: string,
): string {
const prepareFlowEmit: string = this.emitFlowSteps(state.prepareFlow ?? [], ' ');
const readyTestIdEmit: string = state.readyTestId
? ` await page.waitForSelector('[data-testid="${state.readyTestId}"]', { timeout: 15_000 });`
: '';
const maskExpr: string = state.maskSelectors && state.maskSelectors.length > 0
? `[${state.maskSelectors.map((s) => `page.locator(${JSON.stringify(s)})`).join(', ')}]`
: '[]';
const blocks: string[] = [];
for (const vp of manifest.viewports) {
for (const orientation of orientations) {
const w: number = orientation === 'landscape' ? Math.max(vp.width, vp.height) : Math.min(vp.width, vp.height);
const h: number = orientation === 'landscape' ? Math.min(vp.width, vp.height) : Math.max(vp.width, vp.height);
blocks.push(`
test('${state.stateId} | ${vp.key} | ${orientation}', async ({ page }) => {
await page.setViewportSize({ width: ${w}, height: ${h} });
await page.goto(VQA_BASE_URL + '${manifest.route}');
${featureFlowEmit}
${prepareFlowEmit}
${readyTestIdEmit}
await stabilizePage(page);
const stateOut: string = path.join(VQA_OUT_DIR, 'states', '${state.stateId}', '${vp.key}-${orientation}');
ensureDir(stateOut);
const maskLocators = ${maskExpr};
await page.screenshot({ path: path.join(stateOut, 'full.png'), fullPage: true, mask: maskLocators });
await page.screenshot({ path: path.join(stateOut, 'fold.png'), fullPage: false, mask: maskLocators });
await captureDomSnapshot(page, stateOut);
await runDetectors(page, ${ctaSelectorsLiteral}, stateOut);
await runAxe(page, stateOut);
expect(fs.existsSync(path.join(stateOut, 'full.png'))).toBeTruthy();
});
`);
}
}
return blocks.join('\n');
}
private static emitFlowSteps(steps: DyE2E_VQA_FlowStep_Interface[], indent: string): string {
if (!steps || steps.length === 0) {
return '';
}
const lines: string[] = [];
for (const s of steps) {
const target: string = s.target ? JSON.stringify(s.target) : '""';
const value: string = s.value !== undefined ? JSON.stringify(s.value) : '""';
const timeoutStr: string = s.timeout !== undefined ? `, { timeout: ${s.timeout} }` : '';
switch (s.action) {
case 'navigate':
lines.push(`${indent}await page.goto(VQA_BASE_URL + ${target});`);
break;
case 'click':
lines.push(`${indent}await page.locator(${target}).click();`);
break;
case 'fill':
lines.push(`${indent}await page.locator(${target}).fill(${value});`);
break;
case 'select':
lines.push(`${indent}await page.locator(${target}).selectOption(${value});`);
break;
case 'press':
lines.push(`${indent}await page.keyboard.press(${value});`);
break;
case 'hover':
lines.push(`${indent}await page.locator(${target}).hover();`);
break;
case 'waitForSelector':
lines.push(`${indent}await page.waitForSelector(${target}${timeoutStr});`);
break;
case 'waitForTimeout':
lines.push(`${indent}await page.waitForTimeout(${s.value ?? 0});`);
break;
case 'setViewport': {
const dims: string[] = (s.target ?? '0x0').split('x');
lines.push(`${indent}await page.setViewportSize({ width: ${parseInt(dims[0] ?? '0', 10)}, height: ${parseInt(dims[1] ?? '0', 10)} });`);
break;
}
case 'evaluate':
lines.push(`${indent}await page.evaluate(${value});`);
break;
case 'mockResponse':
lines.push(`${indent}await page.route(${target}, route => route.fulfill(${value || '{}'}));`);
break;
}
}
return lines.join('\n');
}
}
|