Utility for creating a valid configuration to use with the JSDOM environment.

Implements

Constructors

  • Create a configuration for use with the JSDOM environment.

    Parameters

    • getFileList: (
          url: string,
          renderAPI: RenderAPI,
          fetchFn: (
              url: string,
          ) => undefined | null | Promise<Buffer<ArrayBufferLike>>,
      ) => Promise<string[]>

      Callback that should return a promise for the list of JavaScript files the environment must execute in order to produce a result for the given render request.

    • getResourceLoader: (url: string, renderAPI: RenderAPI) => CloseableResourceLoader

      Callback that should return a JSDOM resource loader for the given request. We must call this per render so that logging is appropriately channeled for the request being made.

    • OptionalafterEnvSetup: (
          url: string,
          fileURLs: readonly string[],
          renderAPI: RenderAPI,
          vmContext?: any,
      ) => Promise<undefined | null | ICloseable>

      Callback to perform additional environment setup before the render occurs. This can optionally return an object that can add extra fields to the environment context for rendering code to access. This is useful if your render server wants to add some specific configuration, such as setting up some versions of Apollo for server-side rendering. Be careful; any functions you attach can be executed by the rendering code.

    • OptionalregistrationCallbackName: string = "__jsdom_env_register"

      The name of the function that the environment should expose for client code to register for rendering. This defaults to __jsdom_env_register.

    Returns Configuration

Properties

afterEnvSetup: (
    url: string,
    fileURLs: readonly string[],
    renderAPI: RenderAPI,
    vmContext?: any,
) => Promise<undefined | null | ICloseable>

Perform any additional environment setup.

This method gets access to the actual environment in which code will execute. Be careful what you do.

Type declaration

    • (
          url: string,
          fileURLs: readonly string[],
          renderAPI: RenderAPI,
          vmContext?: any,
      ): Promise<undefined | null | ICloseable>
    • Parameters

      • url: string

        The URL that is to be rendered.

      • fileURLs: readonly string[]
      • renderAPI: RenderAPI

        An API of utilities for assisting with the render operation.

      • OptionalvmContext: any

        The actual environment that is being setup.

      Returns Promise<undefined | null | ICloseable>

      A promise that the additional setup is done.

getFileList: (
    url: string,
    renderAPI: RenderAPI,
    fetchFn: (
        url: string,
    ) => undefined | null | Promise<Buffer<ArrayBufferLike>>,
) => Promise<string[]>

Get the list of file URLs to retrieve and execute for the given request.

Type declaration

    • (
          url: string,
          renderAPI: RenderAPI,
          fetchFn: (
              url: string,
          ) => undefined | null | Promise<Buffer<ArrayBufferLike>>,
      ): Promise<string[]>
    • Parameters

      • url: string

        The URL that is to be rendered.

      • renderAPI: RenderAPI

        An API of utilities for assisting with the render operation.

      • fetchFn: (url: string) => undefined | null | Promise<Buffer<ArrayBufferLike>>

        Function to fetch a URL. Using this ensures proper tidy-up of associated sockets and agents.

      Returns Promise<string[]>

      An ordered array of absolute URLs for the JavaScript files that are to be executed. These are exectued in the same order as the array.

getResourceLoader: (
    url: string,
    renderAPI: RenderAPI,
) => CloseableResourceLoader

Get a JSDOM resource loader for the given render request.

Type declaration

    • (url: string, renderAPI: RenderAPI): CloseableResourceLoader
    • Parameters

      • url: string

        The URL that is to be rendered.

      • renderAPI: RenderAPI

        An API of utilities for assisting with the render operation.

      Returns CloseableResourceLoader

      A ResourceLoader instance for use with JSDOM that can optionally have a close() method, which will be invoked when the render completes.

registrationCallbackName: string

The name of the callback function that should be exposed by the environment for renderable code to use when registering for rendering.