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-plugin-create-client-paths): set matchPath correctly #15014

Merged
merged 3 commits into from
Jun 21, 2019
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
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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github commmenting is dumb 💤

can you also remove the return true & return false from this function as forEach doesn't care.

I'm also thinking if we should drop the promise. What use has it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise shouldn't be necessary since createPage is an action creator and therefore not async

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