Skip to content

Commit

Permalink
fix: windows tests (path separators)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron committed Sep 14, 2020
1 parent 7a33670 commit fd46adb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions test/gatsby-node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit fd46adb

Please sign in to comment.