Member Junction
    Preparing search index...

    Generic, abstract base class for any scenario where we want to use a Singleton pattern. This base class abstracts away the complexity of ensuring a truly global singleton instance across multiple code paths in a deployed application. It uses a Global Object Store to ensure that only one instance of the class exists in the application even if the class has code imported into multiple execution paths (which is not optimal, of course, but can occur in some situations).

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    RotateAfterUses: number = 20

    Maximum number of tests a recycled context can serve before being automatically rotated (closed and recreated). Long-lived contexts accumulate localStorage entries, dirty SPA state, and memory pressure which leads to load failures after ~25 reuses.

    Accessors

    • get GlobalKey(): string

      Returns string

    Methods

    • The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.

      Returns GlobalObjectStore | null

    • Get an isolated adapter — a fresh BrowserContext seeded with the cached storageState (cookies + localStorage) for the given worker key, if any. Every call returns a NEW context, even within the same worker, so test mutations cannot leak forward.

      Pair every GetIsolated(key) with ReleaseIsolated(adapter) after the test completes — that's when the context's storage is captured back into _workerStorageState[key] for the next test in the worker to replay. Without the matching release, the cache won't update and subsequent tests will start from the previous cached state (or empty).

      Parameters

      • workerKey: string

        Stable identifier for the worker (e.g. worker-0). All tests run by this worker share the same cached storage state.

      • Optionalconfig: BrowserConfig

        Browser config used when constructing the context.

      Returns Promise<SharedContextBrowserAdapter>

    • Launch or attach to the shared Chromium browser. Safe to call multiple times — subsequent calls are no-ops if the browser is already running.

      Parameters

      • headless: boolean = true

        Run launched browser without a visible window. Ignored when connect is set (the external browser already decided).

      • Optionalconnect: string

        Optional. Endpoint of an already-running browser to attach to instead of launching one. http(s)://… uses Chrome DevTools Protocol; ws(s)://… uses a Playwright browser server. When set, Shutdown() will NOT close the browser — the caller owns its lifecycle.

      • OptionalconnectType: "cdp" | "server" | "auto"

        Force the connect method. Defaults to 'auto' (scheme-based detection). Ignored when connect is unset.

        Note: this is a process-wide singleton. When the test driver runs parallel workers and one of them passes connect, every worker that subsequently calls Initialize (or hits ensureBrowser via GetNew / GetRecycled / GetIsolated) will share the same attached browser — the first call wins. Callers should ensure all workers agree on the connect endpoint.

      Returns Promise<void>

    • Forget the cached storage state for a worker — the next GetIsolated call for the same key will create a context with no auth seed, forcing the AuthHandler to run from scratch. Use when a token has expired mid-suite or when an opt-out is desired.

      Parameters

      • workerKey: string

      Returns void

    • Release a single recycled key — closes the adapter's page and the underlying BrowserContext. The key can be reused after release (a new context will be created on next GetRecycled call).

      Parameters

      • key: string

      Returns Promise<void>

    • Full shutdown: close all fresh adapters, release all recycled contexts, close the browser. Safe to call multiple times.

      When attached to an external browser (_connected === true), the browser itself is NOT closed — the caller owns its lifecycle. All contexts WE created (recycled, fresh, isolated) ARE closed.

      Returns Promise<void>

    • Returns the singleton instance of the class. If the instance does not exist, it is created and stored in the Global Object Store. If className is provided it will be used as part of the key in the Global Object Store, otherwise the actual class name will be used. NOTE: the class name used by default is the lowest level of the object hierarchy, so if you have a class that extends another class, the lowest level class name will be used.

      Type Parameters

      Parameters

      • this: new () => T
      • OptionalclassName: string

      Returns T