diff --git a/tests/e2e/tests/build/app-shell/app-shell-with-service-worker.ts b/tests/e2e/tests/build/app-shell/app-shell-with-service-worker.ts index b69e28e9ea38..6f8f67c5f5be 100644 --- a/tests/e2e/tests/build/app-shell/app-shell-with-service-worker.ts +++ b/tests/e2e/tests/build/app-shell/app-shell-with-service-worker.ts @@ -1,8 +1,9 @@ import { getGlobalVariable } from '../../../utils/env'; -import { appendToFile, expectFileToMatch, writeFile } from '../../../utils/fs'; +import { appendToFile, expectFileToMatch } from '../../../utils/fs'; import { installPackage } from '../../../utils/packages'; import { ng } from '../../../utils/process'; import { updateJsonFile } from '../../../utils/project'; +import { executeBrowserTest } from '../../../utils/puppeteer'; const snapshots = require('../../../ng-snapshot/package.json'); @@ -31,26 +32,27 @@ export default async function () { } } - await writeFile( - 'e2e/app.e2e-spec.ts', - ` - import { browser, by, element } from 'protractor'; + await ng('build'); + await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/); - it('should have ngsw in normal state', () => { - browser.get('/'); + await executeBrowserTest({ + configuration: 'production', + checkFn: async (page) => { // Wait for service worker to load. - browser.sleep(2000); - browser.waitForAngularEnabled(false); - browser.get('/ngsw/state'); - // Should have updated, and be in normal state. - expect(element(by.css('pre')).getText()).not.toContain('Last update check: never'); - expect(element(by.css('pre')).getText()).toContain('Driver state: NORMAL'); - }); - `, - ); + await new Promise((resolve) => setTimeout(resolve, 2000)); + await page.waitForSelector('h1'); - await ng('build'); - await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/); + const baseUrl = page.url(); + await page.goto(new URL('/ngsw/state', baseUrl).href); - await ng('e2e', '--configuration=production'); + // Should have updated, and be in normal state. + const preText = await page.$eval('pre', (el) => el.textContent); + if (preText?.includes('Last update check: never')) { + throw new Error(`Expected service worker to have checked for updates, but got: ${preText}`); + } + if (!preText?.includes('Driver state: NORMAL')) { + throw new Error(`Expected service worker driver state to be NORMAL, but got: ${preText}`); + } + }, + }); } diff --git a/tests/e2e/tests/build/auto-csp.ts b/tests/e2e/tests/build/auto-csp.ts index 1839b160d549..369f723ce181 100644 --- a/tests/e2e/tests/build/auto-csp.ts +++ b/tests/e2e/tests/build/auto-csp.ts @@ -1,9 +1,11 @@ import assert from 'node:assert'; +import { setTimeout } from 'node:timers/promises'; import { getGlobalVariable } from '../../utils/env'; import { expectFileToMatch, writeFile, writeMultipleFiles } from '../../utils/fs'; import { findFreePort } from '../../utils/network'; import { execAndWaitForOutputToMatch, ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; +import { executeBrowserTest } from '../../utils/puppeteer'; const CSP_META_TAG = / `, - 'e2e/src/app.e2e-spec.ts': ` - import { browser, by, element } from 'protractor'; - import * as webdriver from 'selenium-webdriver'; - - function allConsoleWarnMessagesAndErrors() { - return browser - .manage() - .logs() - .get('browser') - .then(function (browserLog: any[]) { - const warnMessages: any[] = []; - browserLog.filter((logEntry) => { - const msg = logEntry.message; - console.log('>> ' + msg); - if (logEntry.level.value >= webdriver.logging.Level.INFO.value) { - warnMessages.push(msg); - } - }); - return warnMessages; - }); - } - - describe('Hello world E2E Tests', () => { - beforeAll(async () => { - await browser.waitForAngularEnabled(true); - }); - - it('should display: Welcome and run all scripts in order', async () => { - // Load the page without waiting for Angular since it is not bootstrapped automatically. - await browser.driver.get(browser.baseUrl); - - // Test the contents. - expect(await element(by.css('h1')).getText()).toMatch('Hello'); - - // Make sure all scripts ran and there were no client side errors. - const consoleMessages = await allConsoleWarnMessagesAndErrors(); - expect(consoleMessages.length).toEqual(4); // No additional errors - // Extract just the printed messages from the console data. - const printedMessages = consoleMessages.map(m => m.match(/"(.*?)"/)[1]); - expect(printedMessages).toEqual([ - // All messages printed in order because execution order is preserved. - "Inline Script Head", - "Inline Script Body: 1339", - "First External Script: 1338", - "Second External Script: 1337", - ]); - }); - }); - `, }); async function spawnServer(): Promise { @@ -137,7 +90,49 @@ export default async function () { // Make sure if contains the critical CSS inlining CSP code. await expectFileToMatch('dist/test-project/browser/index.html', 'ngCspMedia'); - // Make sure that our e2e protractor tests run to confirm that our angular project runs. + // Make sure that our e2e tests run to confirm that our angular project runs. const port = await spawnServer(); - await ng('e2e', `--base-url=http://localhost:${port}`, '--dev-server-target='); + await executeBrowserTest({ + baseUrl: `http://localhost:${port}/`, + checkFn: async (page) => { + const warnMessages: string[] = []; + page.on('console', (msg) => { + if (msg.type() === 'warning') { + warnMessages.push(msg.text()); + } + }); + + // Reload to ensure we capture messages from the start if needed, + // although executeBrowserTest already navigated. + await page.reload(); + + // Wait for the expected number of warnings + let retries = 50; + while (warnMessages.length < 4 && retries > 0) { + await setTimeout(100); + retries--; + } + + if (warnMessages.length !== 4) { + throw new Error( + `Expected 4 console warnings, but got ${warnMessages.length}:\n${warnMessages.join('\n')}`, + ); + } + + const expectedMessages = [ + 'Inline Script Head', + 'Inline Script Body: 1339', + 'First External Script: 1338', + 'Second External Script: 1337', + ]; + + for (let i = 0; i < expectedMessages.length; i++) { + if (!warnMessages[i].includes(expectedMessages[i])) { + throw new Error( + `Expected warning ${i} to include '${expectedMessages[i]}', but got '${warnMessages[i]}'`, + ); + } + } + }, + }); } diff --git a/tests/e2e/tests/build/server-rendering/express-engine-csp-nonce.ts b/tests/e2e/tests/build/server-rendering/express-engine-csp-nonce.ts index 19e7dcd28b60..3d6335b48465 100644 --- a/tests/e2e/tests/build/server-rendering/express-engine-csp-nonce.ts +++ b/tests/e2e/tests/build/server-rendering/express-engine-csp-nonce.ts @@ -4,6 +4,7 @@ import { findFreePort } from '../../../utils/network'; import { installWorkspacePackages } from '../../../utils/packages'; import { execAndWaitForOutputToMatch, ng } from '../../../utils/process'; import { updateJsonFile, updateServerFileForEsbuild, useSha } from '../../../utils/project'; +import { executeBrowserTest } from '../../../utils/puppeteer'; export default async function () { const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; @@ -46,90 +47,6 @@ export default async function () { `, - 'e2e/src/app.e2e-spec.ts': ` - import { browser, by, element } from 'protractor'; - import * as webdriver from 'selenium-webdriver'; - - function verifyNoBrowserErrors() { - return browser - .manage() - .logs() - .get('browser') - .then(function (browserLog: any[]) { - const errors: any[] = []; - browserLog.filter((logEntry) => { - const msg = logEntry.message; - console.log('>> ' + msg); - if (logEntry.level.value >= webdriver.logging.Level.INFO.value) { - errors.push(msg); - } - }); - expect(errors).toEqual([]); - }); - } - - describe('Hello world E2E Tests', () => { - beforeAll(async () => { - await browser.waitForAngularEnabled(false); - }); - - it('should display: Welcome', async () => { - // Load the page without waiting for Angular since it is not bootstrapped automatically. - await browser.driver.get(browser.baseUrl); - - expect( - await element(by.css('style[ng-app-id="ng"]')).getText() - ).not.toBeNull(); - - // Test the contents from the server. - expect(await element(by.css('h1')).getText()).toMatch('Hello'); - - // Bootstrap the client side app. - await browser.executeScript('doBootstrap()'); - - // Retest the contents after the client bootstraps. - expect(await element(by.css('h1')).getText()).toMatch('Hello'); - - // Make sure the server styles got replaced by client side ones. - expect( - await element(by.css('style[ng-app-id="ng"]')).isPresent() - ).toBeFalsy(); - expect(await element(by.css('style')).getText()).toMatch(''); - - // Make sure there were no client side errors. - await verifyNoBrowserErrors(); - }); - - it('stylesheets should be configured to load asynchronously', async () => { - // Load the page without waiting for Angular since it is not bootstrapped automatically. - await browser.driver.get(browser.baseUrl); - - // Test the contents from the server. - const linkTag = await browser.driver.findElement( - by.css('link[rel="stylesheet"]') - ); - expect(await linkTag.getAttribute('media')).toMatch('all'); - expect(await linkTag.getAttribute('ngCspMedia')).toBeNull(); - expect(await linkTag.getAttribute('onload')).toBeNull(); - - // Make sure there were no client side errors. - await verifyNoBrowserErrors(); - }); - - it('style tags all have a nonce attribute', async () => { - // Load the page without waiting for Angular since it is not bootstrapped automatically. - await browser.driver.get(browser.baseUrl); - - // Test the contents from the server. - for (const s of await browser.driver.findElements(by.css('style'))) { - expect(await s.getAttribute('nonce')).toBe('{% nonce %}'); - } - - // Make sure there were no client side errors. - await verifyNoBrowserErrors(); - }); - }); - `, }); async function spawnServer(): Promise { @@ -158,5 +75,51 @@ export default async function () { } const port = await spawnServer(); - await ng('e2e', `--base-url=http://localhost:${port}`, '--dev-server-target='); + await executeBrowserTest({ + baseUrl: `http://localhost:${port}/`, + checkFn: async (page) => { + // Test the contents from the server. + const h1Text = await page.$eval('h1', (el) => el.textContent); + if (!h1Text?.includes('Hello')) { + throw new Error(`Expected h1 to contain 'Hello', but got '${h1Text}'`); + } + + const serverStylePresent = await page.evaluate( + () => !!(globalThis as any).document.querySelector('style[ng-app-id="ng"]'), + ); + if (!serverStylePresent) { + throw new Error('Expected server-side style to be present'); + } + + // style tags all have a nonce attribute + const nonces = await page.$$eval('style', (styles) => + styles.map((s) => s.getAttribute('nonce')), + ); + for (const nonce of nonces) { + if (nonce !== '{% nonce %}') { + throw new Error(`Expected nonce to be '{% nonce %}', but got '${nonce}'`); + } + } + + // stylesheets should be configured to load asynchronously + const linkMedia = await page.$eval('link[rel="stylesheet"]', (el) => + el.getAttribute('media'), + ); + if (linkMedia !== 'all') { + throw new Error(`Expected link media to be 'all', but got '${linkMedia}'`); + } + + // Bootstrap the client side app. + await page.evaluate('window.doBootstrap()'); + + // Wait for server style to be removed by client + await page.waitForSelector('style[ng-app-id="ng"]', { hidden: true }); + + // Retest the contents after the client bootstraps. + const h1TextPost = await page.$eval('h1', (el) => el.textContent); + if (!h1TextPost?.includes('Hello')) { + throw new Error(`Expected h1 to contain 'Hello' after bootstrap, but got '${h1TextPost}'`); + } + }, + }); } diff --git a/tests/e2e/tests/build/server-rendering/express-engine-ngmodule.ts b/tests/e2e/tests/build/server-rendering/express-engine-ngmodule.ts index f05d2182bbd2..92e34f7ca3e8 100644 --- a/tests/e2e/tests/build/server-rendering/express-engine-ngmodule.ts +++ b/tests/e2e/tests/build/server-rendering/express-engine-ngmodule.ts @@ -3,24 +3,14 @@ import { rimraf, writeMultipleFiles } from '../../../utils/fs'; import { findFreePort } from '../../../utils/network'; import { installWorkspacePackages } from '../../../utils/packages'; import { execAndWaitForOutputToMatch, ng } from '../../../utils/process'; -import { - updateJsonFile, - updateServerFileForEsbuild, - useCIChrome, - useCIDefaults, - useSha, -} from '../../../utils/project'; +import { updateJsonFile, updateServerFileForEsbuild, useSha } from '../../../utils/project'; +import { executeBrowserTest } from '../../../utils/puppeteer'; export default async function () { // forcibly remove in case another test doesn't clean itself up await rimraf('node_modules/@angular/ssr'); await ng('generate', 'app', 'test-project-two', '--no-standalone', '--skip-install'); - await ng('generate', 'private-e2e', '--related-app-name=test-project-two'); - - // Setup testing to use CI Chrome. - await useCIChrome('test-project-two', 'projects/test-project-two/e2e/'); - await useCIDefaults('test-project-two'); const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; @@ -79,71 +69,6 @@ export default async function () { .catch((err) => console.error(err)); }; `, - 'projects/test-project-two/e2e/src/app.e2e-spec.ts': ` - import { browser, by, element } from 'protractor'; - import * as webdriver from 'selenium-webdriver'; - - function verifyNoBrowserErrors() { - return browser - .manage() - .logs() - .get('browser') - .then(function (browserLog: any[]) { - const errors: any[] = []; - browserLog.filter((logEntry) => { - const msg = logEntry.message; - console.log('>> ' + msg); - if (logEntry.level.value >= webdriver.logging.Level.INFO.value) { - errors.push(msg); - } - }); - expect(errors).toEqual([]); - }); - } - - describe('Hello world E2E Tests', () => { - beforeAll(async () => { - await browser.waitForAngularEnabled(false); - }); - - it('should display: Welcome', async () => { - // Load the page without waiting for Angular since it is not bootstrapped automatically. - await browser.driver.get(browser.baseUrl); - - const style = await browser.driver.findElement(by.css('style[ng-app-id="ng"]')); - expect(await style.getText()).not.toBeNull(); - - // Test the contents from the server. - const serverDiv = await browser.driver.findElement(by.css('h1')); - expect(await serverDiv.getText()).toMatch('Hello'); - - // Bootstrap the client side app. - await browser.executeScript('doBootstrap()'); - - // Retest the contents after the client bootstraps. - expect(await element(by.css('h1')).getText()).toMatch('Hello'); - - // Make sure the server styles got replaced by client side ones. - expect(await element(by.css('style[ng-app-id="ng"]')).isPresent()).toBeFalsy(); - expect(await element(by.css('style')).getText()).toMatch(''); - - // Make sure there were no client side errors. - await verifyNoBrowserErrors(); - }); - - it('stylesheets should be configured to load asynchronously', async () => { - // Load the page without waiting for Angular since it is not bootstrapped automatically. - await browser.driver.get(browser.baseUrl); - - // Test the contents from the server. - const styleTag = await browser.driver.findElement(by.css('link[rel="stylesheet"]')); - expect(await styleTag.getAttribute('media')).toMatch('all'); - - // Make sure there were no client side errors. - await verifyNoBrowserErrors(); - }); - }); - `, }); async function spawnServer(): Promise { @@ -172,10 +97,41 @@ export default async function () { } const port = await spawnServer(); - await ng( - 'e2e', - '--project=test-project-two', - `--base-url=http://localhost:${port}`, - '--dev-server-target=', - ); + await executeBrowserTest({ + baseUrl: `http://localhost:${port}/`, + checkFn: async (page) => { + // Test the contents from the server. + const h1Text = await page.$eval('h1', (el) => el.textContent); + if (!h1Text?.includes('Hello')) { + throw new Error(`Expected h1 to contain 'Hello', but got '${h1Text}'`); + } + + const serverStylePresent = await page.evaluate( + `!!document.querySelector('style[ng-app-id="ng"]')`, + ); + if (!serverStylePresent) { + throw new Error('Expected server-side style to be present'); + } + + // stylesheets should be configured to load asynchronously + const linkMedia = await page.$eval('link[rel="stylesheet"]', (el) => + el.getAttribute('media'), + ); + if (linkMedia !== 'all') { + throw new Error(`Expected link media to be 'all', but got '${linkMedia}'`); + } + + // Bootstrap the client side app. + await page.evaluate('window.doBootstrap()'); + + // Wait for server style to be removed by client + await page.waitForSelector('style[ng-app-id="ng"]', { hidden: true }); + + // Retest the contents after the client bootstraps. + const h1TextPost = await page.$eval('h1', (el) => el.textContent); + if (!h1TextPost?.includes('Hello')) { + throw new Error(`Expected h1 to contain 'Hello' after bootstrap, but got '${h1TextPost}'`); + } + }, + }); } diff --git a/tests/e2e/tests/build/server-rendering/express-engine-standalone.ts b/tests/e2e/tests/build/server-rendering/express-engine-standalone.ts index 7c819e67693a..18920e3a5893 100644 --- a/tests/e2e/tests/build/server-rendering/express-engine-standalone.ts +++ b/tests/e2e/tests/build/server-rendering/express-engine-standalone.ts @@ -4,6 +4,7 @@ import { findFreePort } from '../../../utils/network'; import { installWorkspacePackages } from '../../../utils/packages'; import { execAndWaitForOutputToMatch, ng } from '../../../utils/process'; import { updateJsonFile, updateServerFileForEsbuild, useSha } from '../../../utils/project'; +import { executeBrowserTest } from '../../../utils/puppeteer'; export default async function () { // forcibly remove in case another test doesn't clean itself up @@ -36,71 +37,6 @@ export default async function () { bootstrapApplication(App, appConfig).catch((err) => console.error(err)); }; `, - 'e2e/src/app.e2e-spec.ts': ` - import { browser, by, element } from 'protractor'; - import * as webdriver from 'selenium-webdriver'; - - function verifyNoBrowserErrors() { - return browser - .manage() - .logs() - .get('browser') - .then(function (browserLog: any[]) { - const errors: any[] = []; - browserLog.filter((logEntry) => { - const msg = logEntry.message; - console.log('>> ' + msg); - if (logEntry.level.value >= webdriver.logging.Level.INFO.value) { - errors.push(msg); - } - }); - expect(errors).toEqual([]); - }); - } - - describe('Hello world E2E Tests', () => { - beforeAll(async () => { - await browser.waitForAngularEnabled(false); - }); - - it('should display: Welcome', async () => { - // Load the page without waiting for Angular since it is not bootstrapped automatically. - await browser.driver.get(browser.baseUrl); - - const style = await browser.driver.findElement(by.css('style[ng-app-id="ng"]')); - expect(await style.getText()).not.toBeNull(); - - // Test the contents from the server. - const serverDiv = await browser.driver.findElement(by.css('h1')); - expect(await serverDiv.getText()).toMatch('Hello'); - - // Bootstrap the client side app. - await browser.executeScript('doBootstrap()'); - - // Retest the contents after the client bootstraps. - expect(await element(by.css('h1')).getText()).toMatch('Hello'); - - // Make sure the server styles got replaced by client side ones. - expect(await element(by.css('style[ng-app-id="ng"]')).isPresent()).toBeFalsy(); - expect(await element(by.css('style')).getText()).toMatch(''); - - // Make sure there were no client side errors. - await verifyNoBrowserErrors(); - }); - - it('stylesheets should be configured to load asynchronously', async () => { - // Load the page without waiting for Angular since it is not bootstrapped automatically. - await browser.driver.get(browser.baseUrl); - - // Test the contents from the server. - const styleTag = await browser.driver.findElement(by.css('link[rel="stylesheet"]')); - expect(await styleTag.getAttribute('media')).toMatch('all'); - - // Make sure there were no client side errors. - await verifyNoBrowserErrors(); - }); - }); - `, }); async function spawnServer(): Promise { @@ -127,5 +63,41 @@ export default async function () { } const port = await spawnServer(); - await ng('e2e', `--base-url=http://localhost:${port}`, '--dev-server-target='); + await executeBrowserTest({ + baseUrl: `http://localhost:${port}/`, + checkFn: async (page) => { + // Test the contents from the server. + const h1Text = await page.$eval('h1', (el) => el.textContent); + if (!h1Text?.includes('Hello')) { + throw new Error(`Expected h1 to contain 'Hello', but got '${h1Text}'`); + } + + const serverStylePresent = await page.evaluate( + `!!document.querySelector('style[ng-app-id="ng"]')`, + ); + if (!serverStylePresent) { + throw new Error('Expected server-side style to be present'); + } + + // stylesheets should be configured to load asynchronously + const linkMedia = await page.$eval('link[rel="stylesheet"]', (el) => + el.getAttribute('media'), + ); + if (linkMedia !== 'all') { + throw new Error(`Expected link media to be 'all', but got '${linkMedia}'`); + } + + // Bootstrap the client side app. + await page.evaluate('window.doBootstrap()'); + + // Wait for server style to be removed by client + await page.waitForSelector('style[ng-app-id="ng"]', { hidden: true }); + + // Retest the contents after the client bootstraps. + const h1TextPost = await page.$eval('h1', (el) => el.textContent); + if (!h1TextPost?.includes('Hello')) { + throw new Error(`Expected h1 to contain 'Hello' after bootstrap, but got '${h1TextPost}'`); + } + }, + }); } diff --git a/tests/e2e/tests/build/worker.ts b/tests/e2e/tests/build/worker.ts index 53e60aa34772..c5346d6847dc 100644 --- a/tests/e2e/tests/build/worker.ts +++ b/tests/e2e/tests/build/worker.ts @@ -8,10 +8,12 @@ import assert from 'node:assert/strict'; import { readdir } from 'node:fs/promises'; +import { setTimeout } from 'node:timers/promises'; import { getGlobalVariable } from '../../utils/env'; import { expectFileToExist, expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs'; import { ng } from '../../utils/process'; import { expectToFail } from '../../utils/utils'; +import { executeBrowserTest } from '../../utils/puppeteer'; export default async function () { const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; @@ -55,24 +57,34 @@ export default async function () { // https://github.com/angular/protractor/issues/2207 await replaceInFile('src/app/app.ts', 'console.log', 'console.warn'); - await writeFile( - 'e2e/app.e2e-spec.ts', - ` - import { AppPage } from './app.po'; - import { browser, logging } from 'protractor'; - describe('worker bundle', () => { - it('should log worker messages', async () => { - const page = new AppPage();; - page.navigateTo(); - const logs = await browser.manage().logs().get(logging.Type.BROWSER); - expect(logs.length).toEqual(1); - expect(logs[0].message).toContain('page got message: worker response to hello'); + await executeBrowserTest({ + checkFn: async (page) => { + const messages: string[] = []; + page.on('console', (msg) => { + messages.push(msg.text()); }); - }); - `, - ); - await ng('e2e'); + // Reload to ensure we capture messages from the start if needed, + // although executeBrowserTest already navigated. + await page.reload(); + + // Wait for the worker message + let retries = 50; + while ( + !messages.some((m) => m.includes('page got message: worker response to hello')) && + retries > 0 + ) { + await setTimeout(100); + retries--; + } + + if (!messages.some((m) => m.includes('page got message: worker response to hello'))) { + throw new Error( + `Expected worker message not found in console. Got:\n${messages.join('\n')}`, + ); + } + }, + }); } async function getWorkerOutputFile(useWebpackBuilder: boolean): Promise { diff --git a/tests/e2e/tests/misc/trusted-types.ts b/tests/e2e/tests/misc/trusted-types.ts index 325ee521fe6d..e16cb3d404e0 100644 --- a/tests/e2e/tests/misc/trusted-types.ts +++ b/tests/e2e/tests/misc/trusted-types.ts @@ -6,9 +6,10 @@ * found in the LICENSE file at https://angular.dev/license */ -import { replaceInFile, writeFile } from '../../utils/fs'; +import { replaceInFile } from '../../utils/fs'; import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; +import { executeBrowserTest } from '../../utils/puppeteer'; export default async function () { // Add lazy route. @@ -19,29 +20,6 @@ export default async function () { `routes: Routes = [{path: 'lazy', loadComponent: () => import('./lazy/lazy').then(c => c.Lazy)}];`, ); - // Add lazy route e2e - await writeFile( - 'e2e/src/app.e2e-spec.ts', - ` - import { browser, logging, element, by } from 'protractor'; - - describe('workspace-project App', () => { - it('should display lazy route', async () => { - await browser.get(browser.baseUrl + '/lazy'); - expect(await element(by.css('app-lazy p')).getText()).toEqual('lazy works!'); - }); - - afterEach(async () => { - // Assert that there are no errors emitted from the browser - const logs = await browser.manage().logs().get(logging.Type.BROWSER); - expect(logs).not.toContain(jasmine.objectContaining({ - level: logging.Level.SEVERE, - })); - }); - }); - `, - ); - const testCases = [ { aot: false, @@ -64,7 +42,18 @@ export default async function () { }); try { - await ng('e2e'); + await executeBrowserTest({ + checkFn: async (page) => { + const baseUrl = page.url(); + await page.goto(new URL('/lazy', baseUrl).href); + + await page.waitForSelector('app-lazy p'); + const lazyText = await page.$eval('app-lazy p', (el) => el.textContent); + if (lazyText !== 'lazy works!') { + throw new Error(`Expected lazy text to be 'lazy works!', but got '${lazyText}'`); + } + }, + }); } catch (error) { console.error(`Test case AOT ${aot} with CSP header ${csp} failed.`); throw error;