diff --git a/packages/platform-server/test/BUILD.bazel b/packages/platform-server/test/BUILD.bazel index 010228b96f5a1..32e504e579d8d 100644 --- a/packages/platform-server/test/BUILD.bazel +++ b/packages/platform-server/test/BUILD.bazel @@ -73,6 +73,9 @@ ts_library( jasmine_node_test( name = "test", bootstrap = ["//tools/testing:node"], + data = [ + "//packages/core/primitives/event-dispatch:contract_bundle_min", + ], deps = [ ":test_lib", ], diff --git a/packages/platform-server/test/dom_utils.ts b/packages/platform-server/test/dom_utils.ts index f1715be906775..ef83752550482 100644 --- a/packages/platform-server/test/dom_utils.ts +++ b/packages/platform-server/test/dom_utils.ts @@ -111,7 +111,7 @@ export function hydrate( return bootstrapApplication(component, {providers}); } -export function render(doc: Document, html: string) { +export function insertDomInDocument(doc: Document, html: string) { // Get HTML contents of the ``, create a DOM element and append it into the body. const container = convertHtmlToDom(html, doc); @@ -125,6 +125,24 @@ export function render(doc: Document, html: string) { Array.from(container.childNodes).forEach((node) => doc.body.appendChild(node)); } +/** + * This prepares the environment before hydration begins. + * + * @param doc the document object + * @param html the server side rendered DOM string to be hydrated + * @returns a promise with the application ref + */ +export function prepareEnvironment(doc: Document, html: string) { + insertDomInDocument(doc, html); + globalThis.document = doc; + const scripts = doc.getElementsByTagName('script'); + for (const script of Array.from(scripts)) { + if (script?.textContent?.startsWith('window.__jsaction_bootstrap')) { + eval(script.textContent); + } + } +} + /** * This bootstraps an application with existing html and enables hydration support * causing hydration to be invoked. @@ -134,7 +152,7 @@ export function render(doc: Document, html: string) { * @param envProviders the environment providers * @returns a promise with the application ref */ -export async function renderAndHydrate( +export async function prepareEnvironmentAndHydrate( doc: Document, html: string, component: Type, @@ -143,7 +161,7 @@ export async function renderAndHydrate( hydrationFeatures?: HydrationFeature[]; }, ): Promise { - render(doc, html); + prepareEnvironment(doc, html); return hydrate(doc, component, options); } diff --git a/packages/platform-server/test/event_replay_spec.ts b/packages/platform-server/test/event_replay_spec.ts index d235b5cfd634a..c7e3ffa6772c7 100644 --- a/packages/platform-server/test/event_replay_spec.ts +++ b/packages/platform-server/test/event_replay_spec.ts @@ -29,10 +29,12 @@ import {EventPhase} from '@angular/core/primitives/event-dispatch'; import { getAppContents, hydrate, - renderAndHydrate, - render as renderHtml, + prepareEnvironment, + prepareEnvironmentAndHydrate, resetTViewsFor, } from './dom_utils'; +import {getDocument} from '@angular/core/src/render3/interfaces/document'; +import {serializeDocument} from '../src/domino_adapter'; /** * Represents the `; +export const DEFAULT_DOCUMENT = `${EVENT_DISPATCH_SCRIPT}`; + +export function getComponentRef(appRef: ApplicationRef): ComponentRef { + return appRef.components[0]; +} + +export function stripSsrIntegrityMarker(input: string): string { + return input.replace(``, ''); +} + +export function stripTransferDataScript(input: string): string { + return input.replace(/