Skip to content

Commit

Permalink
fix(gatsby-plugin-create-client-paths): set matchPath correctly (gats…
Browse files Browse the repository at this point in the history
…byjs#15014)

* Add (failing) tests

* Don't short circuit early

* Fix README
  • Loading branch information
sidharthachatterjee authored and johno committed Jul 17, 2019
1 parent 60d7e33 commit 3319613
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-create-client-paths/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Then configure via `gatsby-config.js`:
```

In this example, all paths prefixed by `/app/` will render the route described
in `src/pages/app/index.js`.
in `src/pages/app.js`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { onCreatePage } = require(`../gatsby-node`)

describe(`onCreatePage`, () => {
let createPage

beforeEach(() => {
createPage = jest.fn()
})

afterEach(() => {
createPage.mockRestore()
})

it(`calls createPage with correct matchPath`, () => {
onCreatePage(
{
page: {
path: `/app/`,
matchPath: undefined,
},
actions: {
createPage,
},
},
{ prefixes: [`/*`, `/app/*`] }
)
expect(createPage).toHaveBeenCalledWith({
matchPath: `/app/*`,
path: `/app/`,
})
})

it(`doesn't set matchPath if already set`, () => {
onCreatePage(
{
page: {
path: `/app/`,
matchPath: `/app/*`,
},
actions: {
createPage,
},
},
{ prefixes: [`/*`, `/app/*`] }
)
expect(createPage).toHaveBeenCalledTimes(0)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports.onCreatePage = ({ page, store, actions }, { prefixes }) => {
return resolve()
}

prefixes.some(prefix => {
prefixes.forEach(prefix => {
if (!re[prefix]) {
// Remove the * from the prefix and memoize
const trimmedPrefix = prefix.replace(/\*$/, ``)
Expand Down

0 comments on commit 3319613

Please sign in to comment.