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

fix(gatsby-transformer-sharp): create child nodes only for Files (#27992) #27994

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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