Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/legacy-cli/e2e/tests/basic/standalone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @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.io/license
*
* @fileoverview
* Tests the minimal conversion of a newly generated application
* to use a single standalone component.
*/

import { writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';

/**
* An application main file that uses a standalone component with
* bootstrapApplication to start the application. `ng-template` and
* `ngIf` are used to ensure that `CommonModule` and `imports` are
* working in standalone mode.
*/
const STANDALONE_MAIN_CONTENT = `
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { bootstrapApplication } from '@angular/platform-browser';

@Component({
selector: 'app-root',
standalone: true,
template: \`
<ng-template [ngIf]="isVisible">
<div class="content">
<span>{{name}} app is running!</span>
</div>
</ng-template>
\`,
imports: [CommonModule],
})
export class AppComponent {
name = 'test-project';
isVisible = true;
}

bootstrapApplication(AppComponent);
`;

export default async function () {
// Update to a standalone application
await writeFile('src/main.ts', STANDALONE_MAIN_CONTENT);

// Execute a production build
await ng('build');

// Perform the default E2E tests
await ng('e2e', 'test-project');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also consider adding a unit test for standalone and verifying that that works, but we can follow up with and expand this test later, so not a blocking issue for this PR.

}