Class ConfigLoader

java.lang.Object
io.karatelabs.core.ConfigLoader

public final class ConfigLoader extends Object
Config-only evaluation: evaluate a project's karate-base.js + karate-config.js (+ the env-specific karate-config-<env>.js) for a working dir and return the merged config Map without running any features (no SUITE_ENTER/SUITE_EXIT, no scenarios). The config sibling of BootLoader.bootOnly(java.nio.file.Path, java.lang.String) — so a caller that lives OUTSIDE a run (a persistent serve/loop engine that wants a project's config — base URLs, env selection, secrets — resolved the SAME way karate run / Runner.run resolve it) can get the config map on demand and bind it, instead of hand-injecting individual variables.

Evaluation runs through the normal ScenarioRuntime config phase (a minimal top-level runtime over a synthetic empty scenario), so the full karate.* API — including karate.callSingle and karate.properties/karate.env — is live during config, exactly as in a real run. Fail-loud: a present-but-failing config throws (the same discipline as BootLoader.bootOnly(java.nio.file.Path, java.lang.String)); the caller decides whether to degrade.

  • Method Details

    • configOnly

      public static Map<String,Object> configOnly(Path workingDir, String env)
      Evaluate config for workingDir under env (nullable → the ambient karate.env) and return the merged config variables. Returns an empty map when workingDir is null. Throws when a config file is present but its evaluation fails.
    • configOnly

      public static Map<String,Object> configOnly(Path workingDir, String env, Map<String,String> systemProperties)
      As configOnly(Path, String), plus a system-property overlay for this evaluation only — the properties the enclosing run is using, so config resolved on its behalf sees the same karate.sysprop(...) / karate.properties[...] values that run sees.

      Without it, config evaluated inside a run (a nested check that re-resolves the project's config on its own engine) reads the JVM's ambient properties — and therefore the project's DEFAULTS — while the enclosing feature reads the run's overlay. The two then disagree on exactly the values a launch script sets to point a suite elsewhere: a base URL, or the port a just-served SUT is on. Pass the enclosing Suite#getSystemProperties() to keep them in agreement.

      Parameters:
      systemProperties - overlay for this evaluation; null → the ambient JVM properties (unchanged behaviour)