forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby-plugin-filesystem): throw meaningful errors on bad inputs (g…
…atsbyjs#10123) fixes gatsbyjs#6643 I also fell for this error before, sinc the original errors are swallowed (and fairly unclear too, because of the indirection). Adding validation was suggested in linked issue, so I went for this, since I didn't see any already used object validation like "ow" in use here. <!-- Q. Which branch should I use for my pull request? A. Use `master` branch (probably). Q. Which branch if my change is a bug fix for Gatsby v1? A. In this case, you should use the `v1` branch Q. Which branch if I'm still not sure? A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :) Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2. Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/ -->
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/gatsby-source-filesystem/src/__tests__/create-remote-file-node.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,55 @@ | ||
const createRemoteFileNode = require(`../create-remote-file-node`) | ||
|
||
describe(`create-remote-file-node`, () => { | ||
const defaultArgs = { | ||
url: ``, | ||
store: {}, | ||
cache: {}, | ||
createNode: jest.fn(), | ||
createNodeId: jest.fn(), | ||
} | ||
|
||
it(`throws on invalid inputs: createNode`, () => { | ||
expect(() => { | ||
createRemoteFileNode({ | ||
...defaultArgs, | ||
createNode: undefined, | ||
}) | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
`"createNode must be a function, was undefined"` | ||
) | ||
}) | ||
|
||
it(`throws on invalid inputs: createNodeId`, () => { | ||
expect(() => { | ||
createRemoteFileNode({ | ||
...defaultArgs, | ||
createNodeId: undefined, | ||
}) | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
`"createNodeId must be a function, was undefined"` | ||
) | ||
}) | ||
|
||
it(`throws on invalid inputs: cache`, () => { | ||
expect(() => { | ||
createRemoteFileNode({ | ||
...defaultArgs, | ||
cache: undefined, | ||
}) | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
`"cache must be the Gatsby cache, was undefined"` | ||
) | ||
}) | ||
|
||
it(`throws on invalid inputs: store`, () => { | ||
expect(() => { | ||
createRemoteFileNode({ | ||
...defaultArgs, | ||
store: undefined, | ||
}) | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
`"store must be the redux store, was undefined"` | ||
) | ||
}) | ||
}) |
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