55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.dev/license
77 */
8- import { setTimeout } from 'node:timers/promises' ;
9- import { replaceInFile , writeFile } from '../../utils/fs' ;
8+
9+ import { replaceInFile } from '../../utils/fs' ;
1010import { ng } from '../../utils/process' ;
1111import { updateJsonFile } from '../../utils/project' ;
12+ import { executeBrowserTest } from '../../utils/puppeteer' ;
1213
1314export default async function ( ) {
1415 // Add lazy route.
@@ -22,29 +23,6 @@ export default async function () {
2223 }];` ,
2324 ) ;
2425
25- // Add lazy route e2e
26- await writeFile (
27- 'e2e/src/app.e2e-spec.ts' ,
28- `
29- import { browser, logging, element, by } from 'protractor';
30-
31- describe('workspace-project App', () => {
32- it('should display lazy route', async () => {
33- await browser.get(browser.baseUrl + '/lazy');
34- expect(await element(by.css('app-lazy-comp p')).getText()).toEqual('lazy-comp works!');
35- });
36-
37- afterEach(async () => {
38- // Assert that there are no errors emitted from the browser
39- const logs = await browser.manage().logs().get(logging.Type.BROWSER);
40- expect(logs).not.toContain(jasmine.objectContaining({
41- level: logging.Level.SEVERE,
42- }));
43- });
44- });
45- ` ,
46- ) ;
47-
4826 // Convert the default config to use JIT and prod to just do AOT.
4927 // This way we can use `ng e2e` to test JIT and `ng e2e --configuration=production` to test AOT.
5028 await updateJsonFile ( 'angular.json' , ( json ) => {
@@ -53,7 +31,17 @@ export default async function () {
5331 buildTarget [ 'configurations' ] [ 'development' ] [ 'aot' ] = false ;
5432 } ) ;
5533
56- await ng ( 'e2e' ) ;
57- await setTimeout ( 500 ) ;
58- await ng ( 'e2e' , '--configuration=production' ) ;
34+ const checkFn = async ( page : any ) => {
35+ await page . goto ( page . url ( ) + 'lazy' ) ;
36+ await page . waitForFunction (
37+ ( ) =>
38+ ! ! ( globalThis as any ) . document
39+ . querySelector ( 'app-lazy-comp p' )
40+ ?. textContent ?. includes ( 'lazy-comp works!' ) ,
41+ { timeout : 10000 } ,
42+ ) ;
43+ } ;
44+
45+ await executeBrowserTest ( { checkFn } ) ;
46+ await executeBrowserTest ( { configuration : 'production' , checkFn } ) ;
5947}
0 commit comments