All files / cwv cwv-suite.generator.ts

100% Statements 64/64
100% Branches 10/10
100% Functions 2/2
100% Lines 64/64

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 651x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 24x 24x 24x 24x 24x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 1x  
import { CWV_GOOD_THRESHOLDS } from '../contracts/_collections/constants/cwv-default-thresholds.const';
import { DyE2E_CWVThresholds_Interface } from '../contracts/_models/interfaces/cwv-thresholds.interface';
import { DyE2E_RouteDescriptor_Interface } from '../generators/_models/route-descriptor.interface';
import { DyE2E_SpecEmission_Util } from '../generators/_collections/spec-emission.util';
import { DyE2E_CWVEmission_Util } from './_collections/cwv-emission.util';
import { DYE2E_INP_PAGE_SCRIPT } from './_collections/inp-interaction-script.const';
import { DYE2E_WEB_VITALS_PAGE_SCRIPT } from './_collections/web-vitals-page-script.const';
import { DyE2E_CWVSuiteGenerate_Options } from './_models/cwv-suite-generate-options.interface';
 
/**
 * MP-05 — CWV-suite generator (synthetic measurement).
 *
 * Bemenet: route-lista + iter-count + thresholds. Kimenet: Playwright spec.ts
 * string, ami N iter / route futtatja a web-vitals-page-scriptet és asszertálja
 * a p75-thresholdokat.
 */
export class DyE2E_CWVSuite_Generator {
 
  static readonly STAMP_BUILT_AT: string = 'WAVE-3-STAMP';
 
  static emit(options: DyE2E_CWVSuiteGenerate_Options): string {
    const iterations: number = options.iterationsPerRoute ?? 5;
    const thresholds: DyE2E_CWVThresholds_Interface = options.thresholds ?? CWV_GOOD_THRESHOLDS;
    const reportDir: string = options.reportDir ?? 'e2e/cwv-report';
    const describePrefix: string = options.describePrefix ?? 'CWV diagnostics';
 
    const header: string = DyE2E_SpecEmission_Util.headerComment(
      'cwv-diag',
      options.routes.map((r: DyE2E_RouteDescriptor_Interface): string => r.path).join(', '),
      DyE2E_CWVSuite_Generator.STAMP_BUILT_AT,
      options.headerComment,
    );
 
    const routeBlocks: string[] = options.routes.map(
      (r: DyE2E_RouteDescriptor_Interface): string => DyE2E_CWVEmission_Util.emitRouteBlock(
        r,
        iterations,
        // Per-route threshold override Wave-3.5 — ha a route saját `cwvThresholds`-szal jön, használjuk azt.
        r.cwvThresholds ?? thresholds,
        reportDir,
      ),
    );
 
    // Wave-3 — ha LCP/CLS/FCP/TTFB MELLETT INP-t is mérünk, mindkét page-scriptet
    // kell injektálni. A `DyE2E_CWVSuiteGenerate_Options.thresholds.inp_p75_ms`
    // jelenléte signalizálja az INP-mérés-szándékot.
    const wantsInp: boolean = typeof thresholds.inp_p75_ms === 'number';
    const inpScriptDecl: string = wantsInp
      ? `\nconst DYE2E_INP_PAGE_SCRIPT: string = ${JSON.stringify(DYE2E_INP_PAGE_SCRIPT)};`
      : '';
 
    return `${header}
import { test, expect } from '@playwright/test';
 
const DYE2E_WEB_VITALS_PAGE_SCRIPT: string = ${JSON.stringify(DYE2E_WEB_VITALS_PAGE_SCRIPT)};${inpScriptDecl}
 
test.describe('${DyE2E_SpecEmission_Util.escapeString(describePrefix)}', (): void => {
 
${DyE2E_SpecEmission_Util.indent(routeBlocks.join('\n\n'), 1)}
 
});
`;
  }
}