test(common): reorg e2e folders for the NgOptimizedImage directive tests

This commit updates the e2e folder to separate e2e tests and playground scripts (so it's clear where files are used).
This commit is contained in:
Andrew Kushnir
2022-06-06 17:24:07 -07:00
parent 808a33902b
commit fa2e30e92c
12 changed files with 47 additions and 30 deletions
@@ -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",
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

@@ -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);
});
});
@@ -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: `<img rawSrc="/e2e/a.png" width="150" height="150" priority>`,
providers: [{provide: IMAGE_LOADER, useValue: () => '/e2e/b.png'}],
})
export class BasicComponent {
}
@@ -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'));
@@ -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
-->
<img rawSrc="./b.png" width="5" height="5">
<img rawSrc="/e2e/b.png" width="5" height="5">
<br>
<!-- 'a.png' should be treated as an LCP element -->
<img rawSrc="./a.png" width="1500" height="2500">
<img rawSrc="/e2e/a.png" width="1500" height="2500">
<br>
@@ -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
-->
<img rawSrc="./b.png" width="10" height="10">
<img rawSrc="/e2e/b.png" width="10" height="10">
`,
})
export class LcpCheckComponent {
@@ -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, {
@@ -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 {
}