Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new image resolvers #27443

Merged
merged 174 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
4814d60
Add static image plugin
ascorbic Sep 16, 2020
5509d90
Parse static image files
ascorbic Sep 16, 2020
6585d84
Fix package.json
ascorbic Sep 16, 2020
83b0321
Better static analysis
ascorbic Sep 17, 2020
b430e5a
Use jsx utils package
ascorbic Sep 18, 2020
96df1b8
Fix typings
ascorbic Sep 18, 2020
f98f56a
Typecheck fix
ascorbic Sep 18, 2020
e48da0a
Fix repo fields
ascorbic Sep 21, 2020
c11c2a4
Helpful warning
ascorbic Sep 21, 2020
7f16e80
Re-enable duotone
ascorbic Sep 22, 2020
146bd6e
Update readme
ascorbic Sep 22, 2020
f46f3e0
Improve typings
ascorbic Sep 22, 2020
65d06a4
Merge branch 'master' into feat/static-image-babel
ascorbic Sep 29, 2020
45a223f
wip fixed image fields for tracedSVG and webP
gillkyle Sep 30, 2020
836fe1d
handle fluid images as well
gillkyle Sep 30, 2020
97a5b77
Use require rather than JSON import
ascorbic Oct 1, 2020
46e5807
Watch files for changes, and use relative paths
ascorbic Oct 1, 2020
0d66f40
Merge branch 'add-missing-static-image-fields' into feat/static-image…
ascorbic Oct 1, 2020
5e41c30
Improve types
ascorbic Oct 1, 2020
0ebbf06
Add type
ascorbic Oct 2, 2020
41a3cce
Merge branch 'master' into feat/static-image-babel
ascorbic Oct 2, 2020
12597fa
Update yarn.lock
ascorbic Oct 2, 2020
4036bb3
Add lots of comments and remove unused stuff
ascorbic Oct 2, 2020
b548429
Create and watch our own nodes
ascorbic Oct 2, 2020
3242599
Update readme
ascorbic Oct 2, 2020
935e91a
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 2, 2020
70616e2
Update deps
ascorbic Oct 2, 2020
67ea9ef
Only watch in develop
ascorbic Oct 2, 2020
4f68363
Rename to gatsby-plugin-image
ascorbic Oct 5, 2020
f5dc9f7
Rearrange, ready for merger
ascorbic Oct 5, 2020
13e1ca8
Import @wardpeet 's gatsby-image-netxtgen
ascorbic Oct 5, 2020
6569d06
Update typings and further merge packages
ascorbic Oct 5, 2020
f3598f0
Build babel plugin
ascorbic Oct 5, 2020
94e4b7e
More merging
ascorbic Oct 5, 2020
7635d59
Add server/browser static image variants
ascorbic Oct 5, 2020
5060df6
include webpack changes
Oct 5, 2020
812ab51
change error message to use gatsby-plugin-image
Oct 5, 2020
80c9155
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 6, 2020
5f1aa5a
Fix compat compilation
ascorbic Oct 6, 2020
4f8824e
Fix SSR
ascorbic Oct 6, 2020
5155374
Merge readmes
ascorbic Oct 6, 2020
e93480f
Build browser bundle
ascorbic Oct 6, 2020
e581396
Export correctly from browser entry point
ascorbic Oct 6, 2020
f6e1156
Remove hook import
ascorbic Oct 6, 2020
24ffaa2
Apply suggestions from code review
ascorbic Oct 6, 2020
ff4d0a9
Merge branch 'feat/static-image-babel' of github.com:gatsbyjs/gatsby …
ascorbic Oct 6, 2020
ea4bf65
Changes from review
ascorbic Oct 6, 2020
2e5912f
add path prefix, static image do e2e test
Oct 6, 2020
aee3dc9
Add prepare script
ascorbic Oct 7, 2020
9ecea93
Apply README suggestions from code review
ascorbic Oct 7, 2020
284d34c
Fix image component in e2e test
ascorbic Oct 7, 2020
8badae4
Better error messages
ascorbic Oct 7, 2020
121e344
Merge branch 'feat/static-image-babel' of github.com:gatsbyjs/gatsby …
ascorbic Oct 7, 2020
618bd75
Prefer svg over base64. Warn for unsupported art direction
ascorbic Oct 7, 2020
e2d84d8
Fix type
ascorbic Oct 7, 2020
f84853f
Use "layout" instead of fixed/fluid
ascorbic Oct 7, 2020
31b8594
add static images to production runtime site
Oct 7, 2020
cc7c571
add path prefix tests
Oct 7, 2020
5426dcf
Reorg types. Change private prop name
ascorbic Oct 7, 2020
a3305a9
Merge branch 'feat/static-image-babel' of github.com:gatsbyjs/gatsby …
ascorbic Oct 7, 2020
a80fa20
initial gatsby static image tests
Oct 7, 2020
3f15544
add test suite to circle ci
Oct 7, 2020
d891b8d
add test suite to circle ci
Oct 7, 2020
0a19484
add test suite to circle ci
Oct 7, 2020
c97041c
remove unused imports, use valid fluid setting
Oct 7, 2020
1c2c89e
Use new fluid props syntax
ascorbic Oct 8, 2020
127840e
Better var name
ascorbic Oct 8, 2020
8e93857
update tests
Oct 8, 2020
8125d34
remove tests that no longer match the expected DOM
Oct 8, 2020
a76ea81
Merge branch 'feat/static-image-babel' of github.com:gatsbyjs/gatsby …
ascorbic Oct 8, 2020
5aa7ec6
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 9, 2020
f999a45
More compat-fixes
ascorbic Oct 9, 2020
81e7ee7
Change classname to match old version
ascorbic Oct 9, 2020
df2e14b
Compat improvements
ascorbic Oct 9, 2020
a4d991e
Update tests to match new classname
ascorbic Oct 9, 2020
2a8d141
Merge remote-tracking branch 'upstream/master' into feat/static-image…
Oct 9, 2020
6d05bc1
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 13, 2020
46f33b7
v0.0.1
ascorbic Oct 13, 2020
b2620c7
Add readme caveat
ascorbic Oct 13, 2020
870ceff
Update version in packages
ascorbic Oct 13, 2020
5db8d30
Remove forcewrapper
ascorbic Oct 13, 2020
c095f4b
wip
ascorbic Oct 13, 2020
02e6495
have static image use gatsbyImageProps function
Oct 13, 2020
4de8330
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 14, 2020
683b57a
Upgrade sharp
ascorbic Oct 14, 2020
559b571
Fix static image type
ascorbic Oct 14, 2020
d52c4a0
First steps to update API
ascorbic Oct 14, 2020
13e3423
Add descriptions
ascorbic Oct 14, 2020
1d440ce
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 14, 2020
03e894a
Merge branch 'feat/static-image-babel' into feat/image-resolvers
ascorbic Oct 14, 2020
60d554f
TypeScript fixes
ascorbic Oct 14, 2020
d5b1f1a
Compile ts
ascorbic Oct 14, 2020
f78bb88
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 15, 2020
6a0c0b0
Add @gillkyle's calculateImageSizes util funciton
ascorbic Oct 15, 2020
86f9af0
remove unused file
Oct 15, 2020
9e1f556
unbump sharp until sharp PR is merged
Oct 15, 2020
ffddd6f
comment out import
Oct 15, 2020
70cdb59
update snapshots
Oct 15, 2020
c1558f2
change JSX to take image prop
Oct 15, 2020
3127a0a
static image uses new image props
Oct 15, 2020
4a31afb
Rename all the things
ascorbic Oct 15, 2020
4b57129
Turns out it wasn't all of them
ascorbic Oct 15, 2020
a1d967d
Update schema
ascorbic Oct 15, 2020
b601e9d
fix intrinsic issue 1px problem, still doesn't seem to reach the corr…
Oct 15, 2020
a5ba190
Fix layout
ascorbic Oct 16, 2020
1e1dba6
Update readme
ascorbic Oct 16, 2020
e1b3b62
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 16, 2020
edb5a7a
Fix dep
ascorbic Oct 16, 2020
8449710
Shouldn;t be in this
ascorbic Oct 16, 2020
1888a2f
Fix sharp function name
ascorbic Oct 16, 2020
8568329
Version
ascorbic Oct 16, 2020
483adb8
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 16, 2020
6abf47d
What is this snapshot out of date?
ascorbic Oct 16, 2020
f30d823
Add a helper funciton
ascorbic Oct 16, 2020
abd9052
Make backgroundColor work
ascorbic Oct 16, 2020
b0e1a39
update layout for images
Oct 16, 2020
dc905ac
no longer using base64 so remove that test
Oct 16, 2020
6307d9b
placeholder not getting passed from static, so this is still busted
Oct 16, 2020
cde4d27
Fix passing of props
ascorbic Oct 16, 2020
267af4d
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
ascorbic Oct 16, 2020
a02fadb
Add TODO comments
ascorbic Oct 16, 2020
03e26e8
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 19, 2020
2a78089
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 19, 2020
087d792
Export batch queue function
ascorbic Oct 19, 2020
48ffac8
Handle the default sizes elsewhere, as it depends on layout
ascorbic Oct 19, 2020
99d5c77
feat(gatsby-plugin-sharp): create image sizes helper (#27554)
gillkyle Oct 20, 2020
dd903e7
Use passed-in reporter
ascorbic Oct 20, 2020
6f96517
Use shared function to handle fit calculation
ascorbic Oct 20, 2020
b048019
Return presentationW/H and aspect ratio from sizes function
ascorbic Oct 20, 2020
0924270
Round sizes
ascorbic Oct 20, 2020
050450d
Use new resizing functions
ascorbic Oct 20, 2020
b49e8c8
default layout wasn't passed to createImageSizes
Oct 20, 2020
0809801
add fixed width default and round calculated height
Oct 20, 2020
f65ed05
reversed logic for aspect ratio calculations
gillkyle Oct 20, 2020
2a08433
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 21, 2020
ee0f51a
Correct description for outputPixelDensities resolver
ascorbic Oct 21, 2020
22f4e8a
Remove log
ascorbic Oct 21, 2020
9523fc3
Handle null image in SSR
ascorbic Oct 21, 2020
d6c0b3b
Version fix
ascorbic Oct 21, 2020
59ee72c
fix(gatsby-plugin-utils): skip libcheck during typegen
ascorbic Oct 21, 2020
046a614
Remove unused func
ascorbic Oct 21, 2020
35df109
Remove dominantColor from fixed and fluid
ascorbic Oct 22, 2020
0108c2c
sizing code for KG to drive refactor
Oct 22, 2020
130ba02
remove isSmaller
gillkyle Oct 22, 2020
8fbca1d
fix tests
gillkyle Oct 22, 2020
3c264eb
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 23, 2020
838b01a
Fix sizes and srcset generation
ascorbic Oct 23, 2020
781af53
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
ascorbic Oct 23, 2020
92768e1
Add object-fit
ascorbic Oct 23, 2020
72645ad
rename placeholder function for consistency
Oct 23, 2020
2f73b31
Update readme
ascorbic Oct 23, 2020
d7d8617
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
ascorbic Oct 23, 2020
abda06a
fix path prefix images
Oct 23, 2020
a086ef7
Merge branch 'feat/image-resolvers' of https://github.com/gatsbyjs/ga…
Oct 23, 2020
2a9b0fe
fix sizing when larger image dimensions are requested, fix warning as…
Oct 23, 2020
f3e114a
rename file to match constrained naming
Oct 23, 2020
b5c546a
Changes from review
ascorbic Oct 26, 2020
89764a8
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 26, 2020
950b131
Add alpha warning
ascorbic Oct 26, 2020
2568f00
Change from review
ascorbic Oct 26, 2020
43bb48b
fix placeholder opacity
Oct 26, 2020
fb616c3
fix placeholder bug
Oct 26, 2020
3508808
only change placeholder size for background color div
Oct 26, 2020
d66f3b2
tests: Add visual regression tests (#27619)
ascorbic Oct 27, 2020
9c3b7cb
Fix e2e test
ascorbic Oct 27, 2020
d0ff2c8
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
ascorbic Oct 27, 2020
f9e36bb
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 27, 2020
4cfc7c3
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 27, 2020
de6c6a1
dont flash placeholder image when removing opacity
gillkyle Oct 27, 2020
b0c27ec
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
gillkyle Oct 27, 2020
d8675ce
Fix dependency
ascorbic Oct 27, 2020
96118ca
add analagous tests for static image
gillkyle Oct 28, 2020
a33d4f6
Add width to constrained images and update snapshots
ascorbic Oct 29, 2020
b4a8e60
Use float
ascorbic Oct 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,17 @@ jobs:
test_path: e2e-tests/gatsby-static-image
test_command: yarn test

e2e_tests_visual-regression:
<<: *e2e-executor
steps:
- e2e-test:
test_path: e2e-tests/visual-regression
test_command: yarn test
- store_artifacts:
path: e2e-tests/visual-regression/__diff_output__
- store_test_results:
path: e2e-tests/visual-regression/cypress/results

starters_validate:
executor: node
steps:
Expand Down Expand Up @@ -582,6 +593,8 @@ workflows:
<<: *e2e-test-workflow
- e2e_tests_gatsby-static-image:
<<: *e2e-test-workflow
- e2e_tests_visual-regression:
<<: *e2e-test-workflow
- e2e_tests_development_runtime:
<<: *e2e-test-workflow
- e2e_tests_production_runtime:
Expand Down
41 changes: 0 additions & 41 deletions e2e-tests/gatsby-static-image/cypress/integration/fixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ describe(`fixed`, () => {
cy.visit(`/fixed`).waitForRouteChange()
})

it(`does not render a spacer div`, () => {
cy.getTestElement(fixedTestId)
.find(`.gatsby-image-wrapper > div`)
.should(`not.exist`)
})

it(`applies height and width to wrapper`, () => {
cy.getTestElement(fixedTestId)
.find(`.gatsby-image-wrapper`)
Expand All @@ -34,39 +28,4 @@ describe(`fixed`, () => {
.should(`exist`)
})

// it(`applies 1x/2x`, () => {
// cy.getTestElement(fixedTestId)
// .find(`picture > source`)
// .should(`have.attr`, `srcset`)
// .and(srcset => {
// ;[`1x`, `2x`].forEach(size => {
// expect(srcset).contains(size)
// })
// })
// })

// it(`does not apply 3x`, () => {
// cy.getTestElement(fixedTestId)
// .find(`picture > source`)
// .should(`have.attr`, `srcset`)
// .and(srcset => {
// expect(srcset).not.contains(`3x`)
// })
// })

// describe(`picture > img sizing`, () => {
// it(`applies height attribute`, () => {
// cy.getTestElement(fixedTestId)
// .find(`picture > img`)
// .should(`have.attr`, `height`)
// .and(`match`, /^\d+$/)
// })

// it(`applies width attribute`, () => {
// cy.getTestElement(fixedTestId)
// .find(`picture > img`)
// .should(`have.attr`, `width`)
// .and(`match`, /^\d+$/)
// })
// })
})
8 changes: 0 additions & 8 deletions e2e-tests/gatsby-static-image/cypress/integration/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,4 @@ describe(`Production gatsby-image`, () => {
})
})

describe(`fallback image`, () => {
it(`renders base-64 src`, () => {
cy.getTestElement(fluidTestId)
.find(`.gatsby-image-wrapper > img`)
.should(`have.attr`, `src`)
.and(`contains`, `base64`)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ const FluidPage = () => (
<div data-testid="image-fluid">
<StaticImage
src="../images/citrus-fruits.jpg"
layout="intrinsic"
layout="constrained"
alt="Citrus fruits"
/>
</div>
<div data-testid="image-fluid-png">
<StaticImage
src="../images/gatsby-icon.png"
layout="intrinsic"
layout="constrained"
alt="Gatsby icon"
/>
</div>
<div data-testid="image-fluid-relative">
<StaticImage
src="../../content/relative.jpg"
layout="intrinsic"
layout="constrained"
alt="Citrus fruits"
/>
</div>
<div data-testid="invalid-image">
<StaticImage src="./does-not-exist.jpg" layout="intrinsic" />
<StaticImage src="./does-not-exist.jpg" layout="constrained" />
</div>
</Layout>
)
Expand Down
8 changes: 4 additions & 4 deletions e2e-tests/gatsby-static-image/src/pages/fluid.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ const FluidPage = () => (
<div data-testid="image-fluid">
<StaticImage
src="../images/citrus-fruits.jpg"
layout="responsive"
layout="fluid"
alt="Citrus fruits"
/>
</div>
<div data-testid="image-fluid-png">
<StaticImage
src="../images/gatsby-icon.png"
layout="responsive"
layout="fluid"
alt="Gatsby icon"
/>
</div>
<div data-testid="image-fluid-relative">
<StaticImage
src="../../content/relative.jpg"
layout="responsive"
layout="fluid"
alt="Citrus fruits"
/>
</div>
<div data-testid="invalid-image">
<StaticImage src="./does-not-exist.jpg" layout="responsive" />
<StaticImage src="./does-not-exist.jpg" layout="fluid" />
</div>
</Layout>
)
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/gatsby-static-image/src/pages/traced.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ const FluidPage = () => (
<div data-testid="image-traced">
<StaticImage
src="../images/citrus-fruits.jpg"
tracedSVG
placeholder="tracedSVG"
alt="Citrus fruits"
/>
</div>
<div data-testid="image-traced-png">
<StaticImage
src="../images/gatsby-icon.png"
tracedSVG
placeholder="tracedSVG"
alt="Gatsby icon"
/>
</div>
<div data-testid="image-traced-relative">
<StaticImage
src="../../content/relative.jpg"
tracedSVG
placeholder="tracedSVG"
alt="Citrus fruits"
/>
</div>
Expand Down
14 changes: 14 additions & 0 deletions e2e-tests/visual-regression/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Project dependencies
.cache
node_modules
yarn-error.log

# Build directory
/public
.DS_Store

# Cypress output
cypress/videos/
cypress/screenshots/
cypress/results/
__diff_output__
22 changes: 22 additions & 0 deletions e2e-tests/visual-regression/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 gatsbyjs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

23 changes: 23 additions & 0 deletions e2e-tests/visual-regression/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Visual regression tests

This test suite uses [cypress-image-snapshot](https://github.com/jaredpalmer/cypress-image-snapshot)
to compare screenshots of pages or elements with a saved snapshot.

To add a test, add a page to `src/pages`, then add a test to `cypress/integration`, or add to an existing spec.

If tests fail, a comparison image will be written to `__diff_output__`. When running in CircleCI, this is uploaded to artifacts.

## Considerations

Remember that the test will run on Linux in CI, so avoid tests that might change between platforms.
Using default fonts is an example. In general, if you're not testing the text itself then exclude it from your tests. Rather than comparing the full page, a good idea is to compare a wrapper element. There is a component provided for this purpose for images.

Specifying large screen sizes can also cause problems when running locally on a small screen. The image tests use a maximum of 1024x768. The device pixel density is forced to 1, so running tests will look strange on Retina screens. This is to ensure screenshots match, whichever monitor or headless CI the tests rae running on.

## Updating snapshots

Run `yarn cy:update-snapshots` if you need to update them. Please note that unlike Jest, this doesn't delete outdated snapshots, so if you remove a test make sure to remove its snapshots too.

## Credits

Test images of Cornwall by [Benjamin Elliott](https://unsplash.com/photos/lH0_kBu5iyo) and [Red Zeppelin](https://unsplash.com/photos/uJMxXtH-Qso) via Unsplash.
Binary file added e2e-tests/visual-regression/content/relative.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions e2e-tests/visual-regression/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"baseUrl": "http://localhost:9000",
"video": false,
"reporter": "junit",
"reporterOptions": {
"mochaFile": "cypress/results/junit-[hash].xml",
"overwrite": false,
"html": false,
"json": true
}
}
5 changes: 5 additions & 0 deletions e2e-tests/visual-regression/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
50 changes: 50 additions & 0 deletions e2e-tests/visual-regression/cypress/integration/image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const testCases = [
["fixed image", "/images/fixed"],
["fixed image smaller than requested size", "/images/fixed-too-big"],
["fluid image", "/images/fluid"],
["constrained image", "/images/constrained"],
]
const staticImageTestCases = [
["fixed image", "/static-images/fixed"],
["fixed image smaller than requested size", "/static-images/fixed-too-big"],
["fluid image", "/static-images/fluid"],
["constrained image", "/static-images/constrained"],
]

const sizes = [["iphone-6"], ["ipad-2"], [1027, 768]]

describe(`GatsbyImage`, () => {
sizes.forEach(size => {
testCases.forEach(([title, path]) => {
describe(`${title}`, () => {
it(`renders correctly on ${size.join("x")}`, () => {
cy.viewport(...size)
cy.visit(path)
// Wait for main image to load
cy.get("[data-main-image]").should("exist")
// Wait for blur-up
cy.wait(1000)
cy.get("#test-wrapper").matchImageSnapshot()
})
})
})
})
})

describe(`StaticImage`, () => {
sizes.forEach(size => {
staticImageTestCases.forEach(([title, path]) => {
describe(`${title}`, () => {
it(`renders correctly on ${size.join("x")}`, () => {
cy.viewport(...size)
cy.visit(path)
// Wait for main image to load
cy.get("[data-main-image]").should("exist")
// Wait for blur-up
cy.wait(1000)
cy.get("#test-wrapper").matchImageSnapshot()
})
})
})
})
})
24 changes: 24 additions & 0 deletions e2e-tests/visual-regression/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
const { addMatchImageSnapshotPlugin } = require("cypress-image-snapshot/plugin")

module.exports = (on, config) => {
addMatchImageSnapshotPlugin(on, config)
on("before:browser:launch", (browser = {}, launchOptions) => {
if (browser.family === "chromium" || browser.family === "chrome") {
// Make retina screens run at 1x density so they match the versions in CI
launchOptions.push("--force-device-scale-factor=1")
}
return launchOptions
})
}
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
26 changes: 26 additions & 0 deletions e2e-tests/visual-regression/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

import "gatsby-cypress"
import { addMatchImageSnapshotCommand } from "cypress-image-snapshot/command"

addMatchImageSnapshotCommand({
customDiffDir: `/__diff_output__`,
customDiffConfig: {
threshold: 0.1
},
failureThreshold: 0.03,
failureThresholdType: `percent`
})
19 changes: 19 additions & 0 deletions e2e-tests/visual-regression/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const path = require(`path`)

module.exports = {
siteMetadata: {
title: `Gatsby Visual tests`,
},
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
name: `img`,
path: `${__dirname}/src/images/`,
},
},
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
`gatsby-transformer-sharp`,
],
}
Loading