diff --git a/packages/core/test/bundling/image-directive/BUILD.bazel b/packages/core/test/bundling/image-directive/BUILD.bazel index 40624828795..6b9d310fb7f 100644 --- a/packages/core/test/bundling/image-directive/BUILD.bazel +++ b/packages/core/test/bundling/image-directive/BUILD.bazel @@ -1,14 +1,14 @@ load("//tools:defaults.bzl", "app_bundle", "ng_module", "protractor_web_test_suite", "ts_devserver", "ts_library") -load("@npm//http-server:index.bzl", "http_server") package(default_visibility = ["//visibility:public"]) ng_module( name = "image-directive", srcs = [ - "basic/basic.ts", + "e2e/basic/basic.ts", + "e2e/lcp-check/lcp-check.ts", "index.ts", - "lcp-check/lcp-check.ts", + "playground.ts", ], deps = [ "//packages/common", @@ -54,26 +54,19 @@ ts_devserver( static_files = [ "index.html", ":tslib", + "e2e/a.png", + "e2e/b.png", ], deps = [":image-directive"], ) -http_server( - name = "prodserver", - data = [ - "index.html", - ":bundle.debug.min.js", - ":bundle.min.js", - ], -) - ts_library( name = "img_dir_e2e_tests_lib", testonly = True, - srcs = ["e2e-util/util.ts"] + glob([ - "**/*.e2e-spec.ts", + srcs = ["e2e/util.ts"] + glob([ + "e2e/**/*.e2e-spec.ts", ]), - tsconfig = ":e2e-util/tsconfig-e2e.json", + tsconfig = ":e2e/tsconfig-e2e.json", deps = [ "//packages/private/testing", "@npm//@types/selenium-webdriver", @@ -83,7 +76,7 @@ ts_library( protractor_web_test_suite( name = "protractor_tests", - on_prepare = ":e2e-util/start-server.js", + on_prepare = ":e2e/start-server.js", server = ":devserver", deps = [ ":img_dir_e2e_tests_lib", diff --git a/packages/core/test/bundling/image-directive/e2e/a.png b/packages/core/test/bundling/image-directive/e2e/a.png new file mode 100644 index 00000000000..c5102939182 Binary files /dev/null and b/packages/core/test/bundling/image-directive/e2e/a.png differ diff --git a/packages/core/test/bundling/image-directive/e2e/b.png b/packages/core/test/bundling/image-directive/e2e/b.png new file mode 100644 index 00000000000..c5102939182 Binary files /dev/null and b/packages/core/test/bundling/image-directive/e2e/b.png differ diff --git a/packages/core/test/bundling/image-directive/basic/basic.e2e-spec.ts b/packages/core/test/bundling/image-directive/e2e/basic/basic.e2e-spec.ts similarity index 80% rename from packages/core/test/bundling/image-directive/basic/basic.e2e-spec.ts rename to packages/core/test/bundling/image-directive/e2e/basic/basic.e2e-spec.ts index 727f7059ac6..f45a6203cf4 100644 --- a/packages/core/test/bundling/image-directive/basic/basic.e2e-spec.ts +++ b/packages/core/test/bundling/image-directive/e2e/basic/basic.e2e-spec.ts @@ -8,15 +8,15 @@ import {browser, by, element} from 'protractor'; -import {verifyNoBrowserErrors} from '../e2e-util/util'; +import {verifyNoBrowserErrors} from '../util'; describe('NgOptimizedImage directive', () => { afterEach(verifyNoBrowserErrors); it('should render an image with an updated `src`', async () => { - await browser.get('/'); + await browser.get('/e2e/basic'); const imgs = element.all(by.css('img')); const src = await imgs.get(0).getAttribute('src'); - expect(/a\.png/.test(src)).toBe(true); + expect(/b\.png/.test(src)).toBe(true); }); }); diff --git a/packages/core/test/bundling/image-directive/e2e/basic/basic.ts b/packages/core/test/bundling/image-directive/e2e/basic/basic.ts new file mode 100644 index 00000000000..c8026d366ed --- /dev/null +++ b/packages/core/test/bundling/image-directive/e2e/basic/basic.ts @@ -0,0 +1,20 @@ +/** + * @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 + */ + +import {ɵIMAGE_LOADER as IMAGE_LOADER, ɵNgOptimizedImage as NgOptimizedImage} from '@angular/common'; +import {Component} from '@angular/core'; + +@Component({ + selector: 'basic', + standalone: true, + imports: [NgOptimizedImage], + template: ``, + providers: [{provide: IMAGE_LOADER, useValue: () => '/e2e/b.png'}], +}) +export class BasicComponent { +} diff --git a/packages/core/test/bundling/image-directive/lcp-check/lcp-check.e2e-spec.ts b/packages/core/test/bundling/image-directive/e2e/lcp-check/lcp-check.e2e-spec.ts similarity index 93% rename from packages/core/test/bundling/image-directive/lcp-check/lcp-check.e2e-spec.ts rename to packages/core/test/bundling/image-directive/e2e/lcp-check/lcp-check.e2e-spec.ts index 8b22bdfc554..440adb36998 100644 --- a/packages/core/test/bundling/image-directive/lcp-check/lcp-check.e2e-spec.ts +++ b/packages/core/test/bundling/image-directive/e2e/lcp-check/lcp-check.e2e-spec.ts @@ -10,11 +10,11 @@ import {browser, by, element} from 'protractor'; import {logging} from 'selenium-webdriver'; -import {collectBrowserLogs} from '../e2e-util/util'; +import {collectBrowserLogs} from '../util'; describe('NgOptimizedImage directive', () => { it('should log a warning when a `priority` is missing on an LCP image', async () => { - await browser.get('/lcp-check'); + await browser.get('/e2e/lcp-check'); // Verify that both images were rendered. const imgs = element.all(by.css('img')); diff --git a/packages/core/test/bundling/image-directive/lcp-check/lcp-check.ts b/packages/core/test/bundling/image-directive/e2e/lcp-check/lcp-check.ts similarity index 82% rename from packages/core/test/bundling/image-directive/lcp-check/lcp-check.ts rename to packages/core/test/bundling/image-directive/e2e/lcp-check/lcp-check.ts index 0c49e059748..86333851ef9 100644 --- a/packages/core/test/bundling/image-directive/lcp-check/lcp-check.ts +++ b/packages/core/test/bundling/image-directive/e2e/lcp-check/lcp-check.ts @@ -18,12 +18,12 @@ import {Component} from '@angular/core'; 'b.png' should *not* be treated as an LCP element, since there is a bigger one right below it --> - +
- +
@@ -31,7 +31,7 @@ import {Component} from '@angular/core'; 'b.png' should *not* be treated as an LCP element here as well, since it's below the fold --> - + `, }) export class LcpCheckComponent { diff --git a/packages/core/test/bundling/image-directive/e2e-util/start-server.js b/packages/core/test/bundling/image-directive/e2e/start-server.js similarity index 100% rename from packages/core/test/bundling/image-directive/e2e-util/start-server.js rename to packages/core/test/bundling/image-directive/e2e/start-server.js diff --git a/packages/core/test/bundling/image-directive/e2e-util/tsconfig-e2e.json b/packages/core/test/bundling/image-directive/e2e/tsconfig-e2e.json similarity index 100% rename from packages/core/test/bundling/image-directive/e2e-util/tsconfig-e2e.json rename to packages/core/test/bundling/image-directive/e2e/tsconfig-e2e.json diff --git a/packages/core/test/bundling/image-directive/e2e-util/util.ts b/packages/core/test/bundling/image-directive/e2e/util.ts similarity index 100% rename from packages/core/test/bundling/image-directive/e2e-util/util.ts rename to packages/core/test/bundling/image-directive/e2e/util.ts diff --git a/packages/core/test/bundling/image-directive/index.ts b/packages/core/test/bundling/image-directive/index.ts index 680d653a6a4..899414423e9 100644 --- a/packages/core/test/bundling/image-directive/index.ts +++ b/packages/core/test/bundling/image-directive/index.ts @@ -10,8 +10,9 @@ import {Component, importProvidersFrom} from '@angular/core'; import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {RouterModule} from '@angular/router'; -import {BasicComponent} from './basic/basic'; -import {LcpCheckComponent} from './lcp-check/lcp-check'; +import {BasicComponent} from './e2e/basic/basic'; +import {LcpCheckComponent} from './e2e/lcp-check/lcp-check'; +import {PlaygroundComponent} from './playground'; @Component({ selector: 'app-root', @@ -24,8 +25,12 @@ export class RootComponent { } const ROUTES = [ - {path: '', component: BasicComponent}, // - {path: 'lcp-check', component: LcpCheckComponent} + // Paths that contain components for test/demo purposes: + {path: '', component: PlaygroundComponent}, + + // Paths below are used for e2e testing: + {path: 'e2e/basic', component: BasicComponent}, + {path: 'e2e/lcp-check', component: LcpCheckComponent} ]; bootstrapApplication(RootComponent, { diff --git a/packages/core/test/bundling/image-directive/basic/basic.ts b/packages/core/test/bundling/image-directive/playground.ts similarity index 97% rename from packages/core/test/bundling/image-directive/basic/basic.ts rename to packages/core/test/bundling/image-directive/playground.ts index 57296592a20..0aec56b7ed0 100644 --- a/packages/core/test/bundling/image-directive/basic/basic.ts +++ b/packages/core/test/bundling/image-directive/playground.ts @@ -14,7 +14,6 @@ const CUSTOM_IMGIX_LOADER = (config: ImageLoaderConfig) => { return `https://aurora-project.imgix.net/${config.src}${widthStr}`; }; - @Component({ selector: 'basic', styles: [` @@ -52,5 +51,5 @@ const CUSTOM_IMGIX_LOADER = (config: ImageLoaderConfig) => { imports: [NgOptimizedImage], providers: [{provide: IMAGE_LOADER, useValue: CUSTOM_IMGIX_LOADER}], }) -export class BasicComponent { +export class PlaygroundComponent { }