-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-source-contentful): enable image-cdn (#34831)
Co-authored-by: veryspry <ehlinger.matt@gmail.com> Co-authored-by: Tyler Barnes <tylerdbarnes@gmail.com>
- Loading branch information
1 parent
29b236b
commit 46fe418
Showing
11 changed files
with
174 additions
and
37 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
e2e-tests/contentful/cypress/integration/gatsby-image-cdn.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,42 @@ | ||
import { parseSrcset } from "srcset" | ||
|
||
const testConfig = { | ||
retries: { | ||
runMode: 2, | ||
openMode: 0, | ||
}, | ||
} | ||
|
||
describe(`gatsby-image-cdn urls`, () => { | ||
beforeEach(() => { | ||
cy.visit("/gatsby-image-cdn").waitForRouteChange() | ||
}) | ||
|
||
it(`creates a proper gatsby image cdn url`, testConfig, () => { | ||
const type = "gatsby-image-cdn" | ||
|
||
cy.get(`[data-cy="${type}"]`) | ||
.find(".gatsby-image-wrapper > picture > img") | ||
.each(($el, i) => { | ||
cy.wrap($el).should("be.visible") | ||
cy.wrap($el) | ||
.should("have.attr", "srcset") | ||
.and(srcset => { | ||
expect(srcset).to.match(/_gatsby\/image/) | ||
|
||
parseSrcset(srcset).forEach(({ url }) => { | ||
const [, , , sourceUrl64, _args64, filename] = url.split(`/`) | ||
const sourceUrl = window.atob(sourceUrl64) | ||
expect(sourceUrl).to.equal( | ||
"https://images.ctfassets.net/k8iqpp6u0ior/3BSI9CgDdAn1JchXmY5IJi/f97a2185b3395591b98008647ad6fd3c/camylla-battani-AoqgGAqrLpU-unsplash.jpg" | ||
) | ||
expect(filename).to.equal( | ||
"camylla-battani-AoqgGAqrLpU-unsplash.jpg" | ||
) | ||
}) | ||
}) | ||
|
||
cy.wrap($el).matchImageSnapshot(`${type}-${i}`) | ||
}) | ||
}) | ||
}) |
Binary file added
BIN
+44.8 KB
...ts/contentful/cypress/snapshots/gatsby-image-cdn.js/gatsby-image-cdn-0.snap.png
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
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,37 @@ | ||
import { graphql } from "gatsby" | ||
import { GatsbyImage } from "gatsby-plugin-image" | ||
import * as React from "react" | ||
|
||
import Layout from "../components/layout" | ||
import Grid from "../components/grid" | ||
|
||
const GatsbyPluginImagePage = ({ data }) => { | ||
return ( | ||
<Layout> | ||
<h1>Test Gatsby Image CDN</h1> | ||
<h2>Gatsby Image CDN:</h2> | ||
<Grid data-cy="gatsby-image-cdn"> | ||
<GatsbyImage image={data.default.gatsbyImage} alt="" /> | ||
</Grid> | ||
</Layout> | ||
) | ||
} | ||
|
||
export default GatsbyPluginImagePage | ||
|
||
export const pageQuery = graphql` | ||
query GatsbyImageCDNQuery { | ||
default: contentfulAsset( | ||
contentful_id: { eq: "3BSI9CgDdAn1JchXmY5IJi" } | ||
node_locale: { eq: "en-US" } | ||
) { | ||
title | ||
description | ||
file { | ||
fileName | ||
url | ||
} | ||
gatsbyImage(width: 420) | ||
} | ||
} | ||
` |
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
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