Class BootLoader

java.lang.Object
io.karatelabs.core.BootLoader

public final class BootLoader extends Object
Discovers karate-boot.js (workdir root, then classpath root) and evaluates it once per Suite. The boot file is ext-scripting only — its JS scope is discarded after evaluation; the side effects (exts registered on Suite) are the only output. See AGENT_KARATE.md K43.
  • Field Details

  • Method Details

    • evalIfPresent

      public static BootBinding evalIfPresent(Suite suite, Path bootstrapWorkingDir, String env)
      Discover + evaluate karate-boot.js for a Suite under construction — called from the Suite constructor, before config discovery and feature resolution, because boot.classpath(dir) is what both of those honour. Returns the BootBinding so the Suite can read the declared mapping and later surface registered exts on SUITE_ENTER. Returns null when no boot file is present (the common case — boot is opt-in).

      The boot file lives at the project root — and discovery only ever looks where the USER named the project: bootstrapWorkingDir (the explicitly-set working dir, else the explicitly-set config dir, else the process CWD), then the real classpath. It deliberately does NOT follow the classloader-probed Suite.getRoot(): a Java project's root is target/test-classes, and booting a file that landed there as a copied resource would change behaviour for a project that never asked for it. It also cannot depend on suite.getWorkingDir() — that is assigned after boot, precisely because boot may re-anchor it.

      Parameters:
      suite - the Suite being constructed — getRoot() is already final
      bootstrapWorkingDir - where to look for the boot file
      env - the karate.env value, exposed as boot.env
      Throws:
      RuntimeException - when boot is present but evaluation fails (Suite must fail loud per K43).
    • bootOnly

      public static BootBinding bootOnly(Path workingDir, String env)
      Boot-only evaluation: run karate-boot.js for a project working dir and return the BootBinding without running any features (no SUITE_ENTER/SUITE_EXIT, no scenarios). The boot side effects — exts constructed + configured via boot.ext(name) + .putMember(...) during the JS eval — are the whole point, so a caller that lives outside a run (e.g. a persistent serve engine re-deriving a project's per-run cov.* config) can reach the booted, configured exts on demand.

      Constructs the minimal Suite the boot phase needs (this package owns the package-private Suite construction, so callers don't have to) anchored at workingDir, and returns the binding the Suite constructor already evaluated. Returns null when workingDir is null or no karate-boot.js is present (the no-ext zero-cost path is preserved).

      Throws:
      RuntimeException - when a boot file IS present but its evaluation fails (fail-loud per K43).