-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add example with responsive image * add new ci job * add new recipe to the root readme
- Loading branch information
Showing
20 changed files
with
269 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Responsive image | ||
> Testing how the browser loads images depending on viewport | ||
The test in [cypress/integration/spec.js](./cypress/integration/spec.js) observes the images loaded by the `<picture>` element to confirm that the mobile version is requested for mobile viewport. The desktop viewport causes the page to request the desktop image version. | ||
|
||
 | ||
|
||
The loaded image resolution is confirmed using `naturalWidth` property. | ||
|
||
```js | ||
cy.intercept('elva-480w-close-portrait.jpg').as('mobileImage') | ||
cy.visit('responsive-images/picture.html') | ||
// the mobile image was loaded | ||
cy.wait('@mobileImage') | ||
// check the native resolution of the loaded image | ||
cy.get('img').should('have.prop', 'naturalWidth', 480) | ||
``` | ||
|
||
The folder [responsive-images](./responsive-images) copied from [mdn/learning-area](https://github.com/mdn/learning-area). The responsive HTML markup is described at [MDN: Responsive images](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images) |
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,5 @@ | ||
{ | ||
"fixturesFolder": false, | ||
"supportFile": false, | ||
"pluginsFile": false | ||
} |
38 changes: 38 additions & 0 deletions
38
examples/testing-dom__responsive-image/cypress/integration/spec.js
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,38 @@ | ||
/// <reference types="cypress" /> | ||
|
||
describe('Responsive image', () => { | ||
it('loads the mobile image', { viewportWidth: 400 }, () => { | ||
cy.intercept('elva-480w-close-portrait.jpg').as('mobileImage') | ||
cy.visit('responsive-images/picture.html') | ||
|
||
// the mobile image was loaded | ||
cy.wait('@mobileImage') | ||
// check the native resolution of the loaded image | ||
cy.get('img').should('have.prop', 'naturalWidth', 480) | ||
}) | ||
|
||
it('loads the desktop image', { viewportWidth: 1000 }, () => { | ||
cy.intercept('elva-800w.jpg').as('desktopImage') | ||
cy.visit('responsive-images/picture.html') | ||
// the desktop image was loaded | ||
cy.wait('@desktopImage') | ||
// check the native resolution of the loaded image | ||
cy.get('img').should('have.prop', 'naturalWidth', 800) | ||
}) | ||
|
||
it('asks for mobile image on resize', { viewportWidth: 1000 }, () => { | ||
cy.intercept('elva-480w-close-portrait.jpg').as('mobileImage') | ||
cy.intercept('elva-800w.jpg').as('desktopImage') | ||
|
||
cy.visit('responsive-images/picture.html') | ||
|
||
// the desktop image was loaded | ||
cy.wait('@desktopImage') | ||
.wait(1000) // just for demo purposes | ||
.log('resizing to mobile') | ||
|
||
cy.viewport('iphone-3') | ||
// the mobile image was loaded | ||
cy.wait('@mobileImage') | ||
}) | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,12 @@ | ||
{ | ||
"name": "responsive-image", | ||
"version": "1.0.0", | ||
"description": "Testing how the browser loads images depending on viewport", | ||
"private": true, | ||
"scripts": { | ||
"cypress:open": "../../node_modules/.bin/cypress open", | ||
"cypress:run": "../../node_modules/.bin/cypress run", | ||
"start": "echo nothing to start", | ||
"test:ci": "npm run cypress:run" | ||
} | ||
} |
Binary file added
BIN
+81.5 KB
...es/testing-dom__responsive-image/responsive-images/elva-480w-close-portrait.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+111 KB
examples/testing-dom__responsive-image/responsive-images/elva-800w.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38.3 KB
examples/testing-dom__responsive-image/responsive-images/elva-fairy-320w.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+62 KB
examples/testing-dom__responsive-image/responsive-images/elva-fairy-480w.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+90.9 KB
examples/testing-dom__responsive-image/responsive-images/elva-fairy-640w.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+125 KB
examples/testing-dom__responsive-image/responsive-images/elva-fairy-800w.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+690 KB
examples/testing-dom__responsive-image/responsive-images/elva-fairy-original.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.08 MB
examples/testing-dom__responsive-image/responsive-images/elva-original.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions
56
examples/testing-dom__responsive-image/responsive-images/img-srcset.html
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,56 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Responsive HTML images demo</title> | ||
<style> | ||
html { | ||
font-family: sans-serif; | ||
background-color: gray; | ||
} | ||
|
||
body { | ||
max-width: 1200px; | ||
margin: 0 auto; | ||
background-color: white; | ||
} | ||
|
||
header { | ||
background: url(header.jpg) no-repeat center; | ||
height: 200px; | ||
} | ||
|
||
section { | ||
padding: 20px; | ||
} | ||
|
||
p { | ||
line-height: 1.5; | ||
} | ||
|
||
img { | ||
display: block; | ||
margin: 0 auto; | ||
max-width: 100%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<header> | ||
|
||
</header> | ||
|
||
<main> | ||
<section> | ||
<h1>My website</h1> | ||
|
||
<img srcset="elva-fairy-480w.jpg 480w, | ||
elva-fairy-800w.jpg 800w" | ||
sizes="(max-width: 600px) 480px, | ||
800px" | ||
src="elva-fairy-800w.jpg" alt="Elva dressed as a fairy"> | ||
</section> | ||
</main> | ||
</body> | ||
</html> |
60 changes: 60 additions & 0 deletions
60
examples/testing-dom__responsive-image/responsive-images/not-responsive.html
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,60 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Not responsive demo</title> | ||
<style> | ||
html { | ||
font-family: sans-serif; | ||
background-color: gray; | ||
} | ||
|
||
body { | ||
width: 100%; | ||
max-width: 1200px; | ||
margin: 0 auto; | ||
background-color: white; | ||
} | ||
|
||
header { | ||
background: url(header.jpg) no-repeat center; | ||
height: 200px; | ||
} | ||
|
||
section { | ||
padding: 20px; | ||
} | ||
|
||
p { | ||
line-height: 1.5; | ||
} | ||
|
||
img { | ||
display: block; | ||
margin: 0 auto; | ||
max-width: 100%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<header> | ||
|
||
</header> | ||
|
||
<main> | ||
<section> | ||
<h1>My website</h1> | ||
|
||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eget venenatis ligula. Ut lacinia at dolor vitae pulvinar. Aliquam pretium dignissim eros. Integer faucibus, dui non aliquet bibendum, lectus orci lobortis odio, ornare porttitor est tellus eget velit. Nulla eros elit, malesuada id neque vel, viverra vehicula neque. Nullam auctor turpis non leo iaculis finibus. Quisque blandit arcu venenatis libero tempor, ac pulvinar ligula dapibus.</p> | ||
|
||
<img src="elva-800w.jpg" alt="Chris standing up holding his daughter Elva"> | ||
|
||
<p>Suspendisse potenti. Ut in luctus eros. Mauris pulvinar vehicula aliquet. Etiam imperdiet eleifend luctus. Duis ut justo nec eros ornare consectetur. Vestibulum convallis condimentum varius. Maecenas rutrum porta varius. Phasellus volutpat sem id sagittis luctus. Morbi vitae quam vitae nisi iaculis dignissim.</p> | ||
|
||
<img src="elva-fairy-800w.jpg" alt="Elva dressed as a fairy"> | ||
|
||
<p>Header image originally by <a href="https://www.flickr.com/photos/miwok/17086751527/">Miwok</a>.</p> | ||
</section> | ||
</main> | ||
</body> | ||
</html> |
47 changes: 47 additions & 0 deletions
47
examples/testing-dom__responsive-image/responsive-images/picture.html
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,47 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Responsive HTML images demo</title> | ||
<style> | ||
html { | ||
font-family: sans-serif; | ||
background-color: gray; | ||
} | ||
|
||
body { | ||
max-width: 1200px; | ||
margin: 0 auto; | ||
background-color: white; | ||
} | ||
|
||
section { | ||
padding: 20px; | ||
} | ||
|
||
p { | ||
line-height: 1.5; | ||
} | ||
|
||
img { | ||
display: block; | ||
margin: 0 auto; | ||
max-width: 100%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<main> | ||
<section> | ||
<h1>My website</h1> | ||
|
||
<picture> | ||
<source media="(max-width: 799px)" srcset="elva-480w-close-portrait.jpg"> | ||
<source media="(min-width: 800px)" srcset="elva-800w.jpg"> | ||
<img src="elva-800w.jpg" alt="Chris standing up holding his daughter Elva"> | ||
</picture> | ||
</section> | ||
</main> | ||
</body> | ||
</html> |
25 changes: 25 additions & 0 deletions
25
examples/testing-dom__responsive-image/responsive-images/srcset-resolutions.html
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,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Responsive HTML images demo</title> | ||
<style> | ||
|
||
img { | ||
width: 320px; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
|
||
|
||
<img srcset="elva-fairy-320w.jpg, | ||
elva-fairy-480w.jpg 1.5x, | ||
elva-fairy-640w.jpg 2x" | ||
src="elva-fairy-640w.jpg" alt="Elva dressed as a fairy"> | ||
|
||
|
||
</body> | ||
</html> |