(
component: Type<unknown>,
options: {
doc?: string;
envProviders?: Provider[];
hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[];
enableHydration?: boolean;
} = {},
)
| 244 | * @returns a promise containing the server rendered app as a string |
| 245 | */ |
| 246 | export async function ssr( |
| 247 | component: Type<unknown>, |
| 248 | options: { |
| 249 | doc?: string; |
| 250 | envProviders?: Provider[]; |
| 251 | hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[]; |
| 252 | enableHydration?: boolean; |
| 253 | } = {}, |
| 254 | ): Promise<string> { |
| 255 | try { |
| 256 | // Enter server mode for the duration of this function. |
| 257 | globalThis['ngServerMode'] = true; |
| 258 | |
| 259 | const defaultHtml = DEFAULT_DOCUMENT; |
| 260 | const {enableHydration = true, envProviders = [], hydrationFeatures = () => []} = options; |
| 261 | const providers = [ |
| 262 | ...envProviders, |
| 263 | provideServerRendering(), |
| 264 | enableHydration ? provideClientHydration(...hydrationFeatures()) : [], |
| 265 | ]; |
| 266 | |
| 267 | const bootstrap = (context: BootstrapContext) => |
| 268 | bootstrapApplication(component, {providers}, context); |
| 269 | |
| 270 | return await renderApplication(bootstrap, { |
| 271 | document: options?.doc ?? defaultHtml, |
| 272 | }); |
| 273 | } finally { |
| 274 | // Leave server mode so the remaining test is back in "client mode". |
| 275 | globalThis['ngServerMode'] = undefined; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Verifies that there are no messages in a console. |
no test coverage detected