Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common): warn if rendered size is much smaller than intrinsic (#…
…47082) This commit adds a console warning in development mode if the ultimate rendered size of the image is much smaller than the dimensions of the requested image. In this case, the warning recommends adjusting the size of the source image or using the `rawSrcset` attribute to implement responsive sizing. PR Close #47082
- Loading branch information
Showing
12 changed files
with
131 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.3 KB
(85%)
packages/core/test/bundling/image-directive/e2e/logo-500w.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions
31
packages/core/test/bundling/image-directive/e2e/oversized-image/oversized-image.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @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 | ||
*/ | ||
|
||
/* tslint:disable:no-console */ | ||
import {browser, by, element, ExpectedConditions} from 'protractor'; | ||
import {logging} from 'selenium-webdriver'; | ||
|
||
import {collectBrowserLogs} from '../util'; | ||
|
||
describe('NgOptimizedImage directive', () => { | ||
it('should not warn if there is no oversized image', async () => { | ||
await browser.get('/e2e/oversized-image-passing'); | ||
const logs = await collectBrowserLogs(logging.Level.WARNING); | ||
expect(logs.length).toEqual(0); | ||
}); | ||
|
||
it('should warn if rendered image size is much smaller than intrinsic size', async () => { | ||
await browser.get('/e2e/oversized-image-failing'); | ||
const logs = await collectBrowserLogs(logging.Level.WARNING); | ||
|
||
expect(logs.length).toEqual(1); | ||
|
||
const expectedMessageRegex = /the intrinsic image is significantly larger than necessary\./; | ||
expect(expectedMessageRegex.test(logs[0].message)).toBeTruthy(); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
packages/core/test/bundling/image-directive/e2e/oversized-image/oversized-image.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @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 {NgOptimizedImage} from '@angular/common'; | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'oversized-image-passing', | ||
standalone: true, | ||
imports: [NgOptimizedImage], | ||
template: ` | ||
<!-- Image is rendered within threshold range--> | ||
<div style="width: 500px; height: 500px"> | ||
<img rawSrc="/e2e/logo-500w.jpg" width="200" height="200" priority> | ||
</div> | ||
<!-- Image is rendered too small but rawSrcset set--> | ||
<div style="width: 300px; height: 300px"> | ||
<img rawSrc="/e2e/logo-1500w.jpg" width="100" height="100" priority | ||
rawSrcset="100w, 200w"> | ||
</div> | ||
`, | ||
}) | ||
export class OversizedImageComponentPassing { | ||
} | ||
|
||
|
||
@Component({ | ||
selector: 'oversized-image-failing', | ||
standalone: true, | ||
imports: [NgOptimizedImage], | ||
template: ` | ||
<!-- Image is rendered too small --> | ||
<div style="width: 300px; height: 300px"> | ||
<img rawSrc="/e2e/logo-1500w.jpg" width="100" height="100" priority> | ||
</div> | ||
`, | ||
}) | ||
export class OversizedImageComponentFailing { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters