|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + * |
| 8 | + * @fileoverview |
| 9 | + * Tests the minimal conversion of a newly generated application |
| 10 | + * to use a single standalone component. |
| 11 | + */ |
| 12 | + |
| 13 | +import { writeFile } from '../../utils/fs'; |
| 14 | +import { ng } from '../../utils/process'; |
| 15 | + |
| 16 | +/** |
| 17 | + * An application main file that uses a standalone component with |
| 18 | + * bootstrapApplication to start the application. `ng-template` and |
| 19 | + * `ngIf` are used to ensure that `CommonModule` and `imports` are |
| 20 | + * working in standalone mode. |
| 21 | + */ |
| 22 | +const STANDALONE_MAIN_CONTENT = ` |
| 23 | +import { Component } from '@angular/core'; |
| 24 | +import { CommonModule } from '@angular/common'; |
| 25 | +import { bootstrapApplication } from '@angular/platform-browser'; |
| 26 | +
|
| 27 | +@Component({ |
| 28 | + selector: 'app-root', |
| 29 | + standalone: true, |
| 30 | + template: \` |
| 31 | + <ng-template [ngIf]="isVisible"> |
| 32 | + <div class="content"> |
| 33 | + <span>{{name}} app is running!</span> |
| 34 | + </div> |
| 35 | + </ng-template> |
| 36 | + \`, |
| 37 | + imports: [CommonModule], |
| 38 | +}) |
| 39 | +export class AppComponent { |
| 40 | + name = 'test-project'; |
| 41 | + isVisible = true; |
| 42 | +} |
| 43 | +
|
| 44 | +bootstrapApplication(AppComponent); |
| 45 | +`; |
| 46 | + |
| 47 | +export default async function () { |
| 48 | + // Update to a standalone application |
| 49 | + await writeFile('src/main.ts', STANDALONE_MAIN_CONTENT); |
| 50 | + |
| 51 | + // Execute a production build |
| 52 | + await ng('build'); |
| 53 | + |
| 54 | + // Perform the default E2E tests |
| 55 | + await ng('e2e', 'test-project'); |
| 56 | +} |
0 commit comments