|
| 1 | +import assert from 'node:assert'; |
| 2 | + |
| 3 | +import { killAllProcesses, ng } from '../../../utils/process'; |
| 4 | +import { rimraf, writeMultipleFiles } from '../../../utils/fs'; |
| 5 | +import { installWorkspacePackages } from '../../../utils/packages'; |
| 6 | +import { ngServe, useSha } from '../../../utils/project'; |
| 7 | + |
| 8 | +export default async function () { |
| 9 | + // Forcibly remove in case another test doesn't clean itself up. |
| 10 | + await rimraf('node_modules/@angular/ssr'); |
| 11 | + await ng('add', '@angular/ssr', '--skip-confirmation'); |
| 12 | + await useSha(); |
| 13 | + await installWorkspacePackages(); |
| 14 | + |
| 15 | + await writeMultipleFiles({ |
| 16 | + // Add http client and route |
| 17 | + 'src/app/app.config.ts': ` |
| 18 | + import { ApplicationConfig } from '@angular/core'; |
| 19 | + import { provideRouter } from '@angular/router'; |
| 20 | +
|
| 21 | + import { HomeComponent } from './home/home.component'; |
| 22 | + import { provideClientHydration } from '@angular/platform-browser'; |
| 23 | + import { provideHttpClient, withFetch } from '@angular/common/http'; |
| 24 | +
|
| 25 | + export const appConfig: ApplicationConfig = { |
| 26 | + providers: [ |
| 27 | + provideRouter([{ |
| 28 | + path: '', |
| 29 | + component: HomeComponent, |
| 30 | + }]), |
| 31 | + provideClientHydration(), |
| 32 | + provideHttpClient(withFetch()), |
| 33 | + ], |
| 34 | + }; |
| 35 | + `, |
| 36 | + // Add asset |
| 37 | + 'src/assets/media.json': JSON.stringify({ dataFromAssets: true }), |
| 38 | + // Update component to do an HTTP call to asset. |
| 39 | + 'src/app/app.component.ts': ` |
| 40 | + import { Component, inject } from '@angular/core'; |
| 41 | + import { CommonModule } from '@angular/common'; |
| 42 | + import { RouterOutlet } from '@angular/router'; |
| 43 | + import { HttpClient } from '@angular/common/http'; |
| 44 | +
|
| 45 | + @Component({ |
| 46 | + selector: 'app-root', |
| 47 | + standalone: true, |
| 48 | + imports: [CommonModule, RouterOutlet], |
| 49 | + template: \` |
| 50 | + <p>{{ data | json }}</p> |
| 51 | + <router-outlet></router-outlet> |
| 52 | + \`, |
| 53 | + }) |
| 54 | + export class AppComponent { |
| 55 | + data: any; |
| 56 | + constructor() { |
| 57 | + const http = inject(HttpClient); |
| 58 | + http.get('/assets/media.json').toPromise().then((d) => { |
| 59 | + this.data = d; |
| 60 | + }); |
| 61 | + } |
| 62 | + } |
| 63 | + `, |
| 64 | + }); |
| 65 | + |
| 66 | + await ng('generate', 'component', 'home'); |
| 67 | + const match = /<p>{[\S\s]*"dataFromAssets":[\s\S]*true[\S\s]*}<\/p>/; |
| 68 | + const port = await ngServe('--no-ssl'); |
| 69 | + assert.match(await (await fetch(`http://localhost:${port}/`)).text(), match); |
| 70 | + |
| 71 | + await killAllProcesses(); |
| 72 | + |
| 73 | + try { |
| 74 | + process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; |
| 75 | + const sslPort = await ngServe('--ssl'); |
| 76 | + assert.match(await (await fetch(`https://localhost:${sslPort}/`)).text(), match); |
| 77 | + } finally { |
| 78 | + process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'; |
| 79 | + } |
| 80 | +} |
0 commit comments