Skip to content

Commit

Permalink
fix(gatsby-transformer-sharp): create child nodes only for Files (#27992
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pieh committed Nov 12, 2020
1 parent 3fda83b commit 001e045
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ Array [
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"type": "File",
},
},
},
],
]
`;

exports[`Process image nodes correctly doesn't create an ImageSharp node for a .gif file 1`] = `Array []`;

exports[`Process image nodes correctly doesn't create an ImageSharp node for a .gif file 2`] = `Array []`;
30 changes: 28 additions & 2 deletions packages/gatsby-transformer-sharp/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe(`Process image nodes correctly`, () => {
children: [],
internal: {
contentDigest: `whatever`,
type: `File`,
},
}
const createNode = jest.fn()
Expand All @@ -34,6 +35,33 @@ describe(`Process image nodes correctly`, () => {
children: [],
internal: {
contentDigest: `whatever`,
type: `File`,
},
}
const createNode = jest.fn()
const createParentChildLink = jest.fn()
const actions = { createNode, createParentChildLink }
const createNodeId = jest.fn()
createNodeId.mockReturnValue(`uuid-from-gatsby`)

await onCreateNode({
node,
actions,
createNodeId,
}).then(() => {
expect(createNode).toHaveBeenCalledTimes(0)
expect(createParentChildLink).toHaveBeenCalledTimes(0)
})
})

it(`doesn't create an ImageSharp node if parent is not a File`, async () => {
const node = {
extension: `png`,
id: `whatever`,
children: [],
internal: {
contentDigest: `whatever`,
type: `NotAFile`,
},
}
const createNode = jest.fn()
Expand All @@ -47,8 +75,6 @@ describe(`Process image nodes correctly`, () => {
actions,
createNodeId,
}).then(() => {
expect(createNode.mock.calls).toMatchSnapshot()
expect(createParentChildLink.mock.calls).toMatchSnapshot()
expect(createNode).toHaveBeenCalledTimes(0)
expect(createParentChildLink).toHaveBeenCalledTimes(0)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-transformer-sharp/src/on-node-create.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { supportedExtensions } = require(`./supported-extensions`)

function unstable_shouldOnCreateNode({ node }) {
return !!supportedExtensions[node.extension]
return node.internal.type === `File` && !!supportedExtensions[node.extension]
}

module.exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
Expand Down

0 comments on commit 001e045

Please sign in to comment.