Class ReportAssets

java.lang.Object
io.karatelabs.core.ReportAssets

public final class ReportAssets extends Object
Imperative spec for one ext's report-asset contribution, built fluently inside Ext.onBoot(Suite) and handed to Suite.registerReportAssets(ReportAssets, ClassLoader) (see EXT.md § Report assets).

There is deliberately no manifest.json — the ext object is already live at onBoot, so asset wiring is declared in one place (Java), type-safe, with no JSON-vs-file drift. getManifest() on Ext still carries the SUITE_ENTER metadata; this type carries only what the report writer needs.

 suite.registerReportAssets(
     ReportAssets.named("image")
         .js("static/ext.js")
         .css("static/ext.css")
         .page("nav.pages", "Image diffs", "pages/image-comparison.html"),
     getClass().getClassLoader());
 

There is no core-version guard here yet (D8's strict-match) — exts ship in lockstep with core for now; revisit if independently-versioned drop-in JARs make a mismatch likely.

Asset paths are resolved against BASE on the ext's classloader, so a .js("static/ext.js") reads META-INF/karate-ext/static/ext.js and is copied to target/karate-reports/ext/<name>/ext.js (the static/ prefix is stripped for the web path; pages/ is kept).

  • Field Details

    • BASE

      public static final String BASE
      Resource root inside an ext JAR for all asset paths in this spec.
      See Also:
  • Method Details

    • named

      public static ReportAssets named(String name)
      Start a spec for the ext registered under name.
    • js

      public ReportAssets js(String path)
      The JS entry registered in alpine:init (D5). Required.
    • css

      public ReportAssets css(String path)
      Optional stylesheet, loaded if set.
    • page

      public ReportAssets page(String slot, String title, String href)
      Add a slot page contribution (e.g. nav.pages).
    • cta

      public ReportAssets cta(String label, String href)
      Override the report's top-bar call-to-action. Core pages ship a default "Try Karate Enterprise" upsell; an ext (e.g. a licensed product) can replace it with its own subtle link — the report then signals which product produced it rather than pitching an upgrade. The first ext to register a CTA wins (HtmlReportWriter.buildCtaHtml); label is the button text, href its target.
    • asset

      public ReportAssets asset(String path)
      Add an extra static file copied verbatim to ext/<name>/ (e.g. a vendored library the JS loads at runtime, like static/resemble.js). Not auto-injected into the page — the ext's own JS references it by its report-relative URL.
    • name

      public String name()
    • pages

      public List<ReportAssets.Page> pages()
    • jsHref

      public String jsHref()
      Web-relative path of the JS entry, static/ stripped.
    • cssHref

      public String cssHref()
      Web-relative path of the CSS, static/ stripped; null when no CSS.
    • ctaLabel

      public String ctaLabel()
      The ext-supplied CTA label, or null if this ext registered none.
    • ctaHref

      public String ctaHref()
      The ext-supplied CTA href, or null if this ext registered none.
    • copyTo

      public void copyTo(Path extDir) throws IOException
      Copy the declared assets (JS, optional CSS, page HTML) into extDir (target/karate-reports/ext/<name>/). static/ prefixes are stripped so static/ext.js lands at <extDir>/ext.js; pages keep their pages/ prefix.
      Throws:
      IOException