Skip to content

Commit

Permalink
chore(gatsby-source-contentful): download assets via gatsby-core-utils (
Browse files Browse the repository at this point in the history
gatsbyjs#33482)

Co-authored-by: Ward Peeters <ward@coding-tech.com>
  • Loading branch information
axe312ger and wardpeet committed Oct 29, 2021
1 parent 010e3ce commit e416f21
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 329 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
jest.mock(`gatsby-core-utils`)
jest.mock(`fs-extra`)
const {
createUrl,
resolveFixed,
Expand All @@ -7,6 +9,9 @@ const {
getBase64Image,
} = require(`../extend-node-type`)

const { fetchRemoteFile } = require(`gatsby-core-utils`)
const fs = require(`fs-extra`)

describe(`contentful extend node type`, () => {
describe(`createUrl`, () => {
it(`allows you to create URls`, () => {
Expand Down Expand Up @@ -102,6 +107,11 @@ describe(`contentful extend node type`, () => {
})

describe(`getBase64Image`, () => {
beforeEach(() => {
fetchRemoteFile.mockClear()
fs.readFile.mockResolvedValue(Buffer.from(`test`))
})

const imageProps = {
aspectRatio: 4.8698224852071,
baseUrl: `//images.ctfassets.net/k8iqpp6u0ior/3ljGfnpegOnBTFGhV07iC1/94257340bda15ad4ca8462da3a8afa07/347966-contentful-logo-wordmark-dark__1_-4cd185-original-1582664935__1_.png`,
Expand All @@ -128,16 +138,18 @@ describe(`contentful extend node type`, () => {
}
test(`keeps image format`, async () => {
const result = await getBase64Image(imageProps)
const regex = /data:image\/png;base64,[a-zA-Z0-9/+]+=*/g
expect(result.match(regex)).not.toBe(null)

expect(fetchRemoteFile).toHaveBeenCalled()
expect(result).toMatchInlineSnapshot(`"data:image/png;base64,dGVzdA=="`)
})
test(`uses given image format`, async () => {
const result = await getBase64Image({
...imageProps,
options: { ...imageProps.options, toFormat: `jpg` },
})
const regex = /data:image\/jpg;base64,[a-zA-Z0-9/+]+=*/g
expect(result.match(regex)).not.toBe(null)

expect(fetchRemoteFile).toHaveBeenCalled()
expect(result).toMatchInlineSnapshot(`"data:image/jpg;base64,dGVzdA=="`)
})
})

Expand Down
85 changes: 0 additions & 85 deletions packages/gatsby-source-contentful/src/cache-image.js

This file was deleted.

51 changes: 0 additions & 51 deletions packages/gatsby-source-contentful/src/download-with-retry.js

This file was deleted.

Loading

0 comments on commit e416f21

Please sign in to comment.