diff --git a/gatsby-node.js b/gatsby-node.js index e98bbf7..b31bdb1 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -59,7 +59,7 @@ exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }, opt for (const _path of paths) { let githubPath = path.join(root, _path.replace(process.cwd(), '')) - if (githubPath.charAt(0) === '/') githubPath = githubPath.substr(1) + if (githubPath.charAt(0) === path.sep) githubPath = githubPath.substr(1) let contributors = [] if (token) { diff --git a/test/gatsby-node.test.js b/test/gatsby-node.test.js index e593374..a14eff8 100644 --- a/test/gatsby-node.test.js +++ b/test/gatsby-node.test.js @@ -10,6 +10,7 @@ * governing permissions and limitations under the License. */ +const path = require('path') const mockGithubFetchContributors = jest.fn() const mockGithubFetch = jest.fn() jest.mock('../src/gql', () => ({ @@ -108,14 +109,16 @@ describe('gatsby-node', () => { .mockResolvedValueOnce(contributors[1]) const root = 'my-root' - options.root = `/${root}` // coverage - await expect(gatsbyNode.sourceNodes(gatsbyHelpers, options)).resolves.toEqual(undefined) + const _options = Object.assign({}, options) + _options.root = `/${root}` // coverage + await expect(gatsbyNode.sourceNodes(gatsbyHelpers, _options)).resolves.toEqual(undefined) expect(gatsbyHelpers.actions.createNode).toHaveBeenCalledTimes(pages.length + 1) expect(mockGithubFetchContributors).toHaveBeenCalledTimes(pages.length) pages.forEach((page, index) => { - const { owner, name, branch, token } = options.repo - expect(mockGithubFetchContributors).toHaveBeenNthCalledWith(index + 1, owner, name, branch, `${root}/${page}`, token) + const { owner, name, branch, token } = _options.repo + const pagePath = path.join(root, page) + expect(mockGithubFetchContributors).toHaveBeenNthCalledWith(index + 1, owner, name, branch, pagePath, token) // skip the very first createNode, which is a Github object expect(gatsbyHelpers.actions.createNode).toHaveBeenNthCalledWith(index + 2, expect.objectContaining({ contributors: contributors[index],