From 07d50c49e14b08699bddc40e2063e01ad88150cc Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Fri, 21 Jun 2019 13:03:33 +0530 Subject: [PATCH 1/3] Add (failing) tests --- .../src/__tests__/gatsby-node.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 packages/gatsby-plugin-create-client-paths/src/__tests__/gatsby-node.js diff --git a/packages/gatsby-plugin-create-client-paths/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-create-client-paths/src/__tests__/gatsby-node.js new file mode 100644 index 0000000000000..c6344c5304b32 --- /dev/null +++ b/packages/gatsby-plugin-create-client-paths/src/__tests__/gatsby-node.js @@ -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) + }) +}) From 73bdbd5f4f4812e6c550e7fe7cc83cb1f6ee08ac Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Fri, 21 Jun 2019 13:08:11 +0530 Subject: [PATCH 2/3] Don't short circuit early --- packages/gatsby-plugin-create-client-paths/src/gatsby-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-create-client-paths/src/gatsby-node.js b/packages/gatsby-plugin-create-client-paths/src/gatsby-node.js index 498367be683f9..ef42df6b59ee4 100644 --- a/packages/gatsby-plugin-create-client-paths/src/gatsby-node.js +++ b/packages/gatsby-plugin-create-client-paths/src/gatsby-node.js @@ -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(/\*$/, ``) From a803602d8d157385e6006e906907ced5756768f4 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Fri, 21 Jun 2019 13:13:26 +0530 Subject: [PATCH 3/3] Fix README --- packages/gatsby-plugin-create-client-paths/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-create-client-paths/README.md b/packages/gatsby-plugin-create-client-paths/README.md index 7dcd633237440..f4b43ec1f6d25 100644 --- a/packages/gatsby-plugin-create-client-paths/README.md +++ b/packages/gatsby-plugin-create-client-paths/README.md @@ -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`.