angular-cli/packages/angular/ssr/test/testing-utils.ts
Alan Agius e9c9e4995e fix(@angular/ssr): resolve circular dependency issue from main.server.js reference in manifest
The issue was addressed by changing the top-level import to a dynamic import.

Closes #28358
2024-09-06 16:11:34 +02:00

60 lines
1.8 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Component, provideExperimentalZonelessChangeDetection } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { provideServerRendering } from '@angular/platform-server';
import { RouterOutlet, Routes, provideRouter } from '@angular/router';
import { setAngularAppManifest } from '../src/manifest';
/**
* Configures the Angular application for testing by setting up the Angular app manifest,
* configuring server-side rendering, and bootstrapping the application with the provided routes.
* This function generates a basic HTML template with a base href and sets up the necessary
* Angular components and providers for testing purposes.
*
* @param routes - An array of route definitions to be used by the Angular Router.
* @param [baseHref=''] - An optional base href to be used in the HTML template.
*/
export function setAngularAppTestingManifest(routes: Routes, baseHref = ''): void {
setAngularAppManifest({
inlineCriticalCss: false,
assets: new Map(
Object.entries({
'index.server.html': async () =>
`
<html>
<head>
<base href="/${baseHref}" />
</head>
<body>
<app-root></app-root>
</body>
</html>`,
}),
),
bootstrap: async () => () => {
@Component({
standalone: true,
selector: 'app-root',
template: '<router-outlet />',
imports: [RouterOutlet],
})
class AppComponent {}
return bootstrapApplication(AppComponent, {
providers: [
provideServerRendering(),
provideExperimentalZonelessChangeDetection(),
provideRouter(routes),
],
});
},
});
}