Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(gatsby): remove parsePath from gatsby core, and move to gats…
…by-link (#9957) * refactor: remove parsePath from gatsby core, and move to gatsby-link Moving a utility function (that was not used!) in gatsby core into where it belongs, gatsby-link. This was discovered via a community member (@travi), as he was attempting to use storybook to test a Link component (outside of Gatsby), e.g. `import Link from 'gatsby-link'`, which was then requiring `gatsby` core. This also generally solves some weirdness that the cyclical require was kinda weird, e.g. gatsby -> gatsby-link -> gatsby I do not believe this is a breaking change, since the version required of gatsby-link will just be bumped by gatsby, and the export is still exported from the top level gatsby module * test(gatsby-link): add additional unit tests for parse path * chore: use test blocks * chore: fix crlf * chore: import parsePath from gatsby-link * chore: export parsePath (whooops) * chore: remove compiled file
- Loading branch information
1 parent
4a13026
commit 3d77520
Showing
6 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/index.js | ||
/*.js | ||
/__tests__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { parsePath } from "../parse-path" | ||
|
||
test(`it defaults to root if undefined`, () => { | ||
expect(parsePath()).toEqual({ | ||
pathname: `/`, | ||
search: ``, | ||
hash: ``, | ||
}) | ||
}) | ||
|
||
test(`it uses passed path, if defined`, () => { | ||
const path = `/admin` | ||
expect(parsePath(path)).toEqual({ | ||
pathname: path, | ||
search: ``, | ||
hash: ``, | ||
}) | ||
}) | ||
|
||
test(`it returns query string`, () => { | ||
const search = `?some-thing=true&other-thing=false` | ||
const pathname = `/admin` | ||
const path = `${pathname}${search}` | ||
|
||
expect(parsePath(path)).toEqual({ | ||
pathname, | ||
search, | ||
hash: ``, | ||
}) | ||
}) | ||
|
||
test(`it returns hash`, () => { | ||
const hash = `#some-id` | ||
const pathname = `/admin` | ||
const path = `${pathname}${hash}` | ||
|
||
expect(parsePath(path)).toEqual({ | ||
pathname, | ||
hash, | ||
search: ``, | ||
}) | ||
}) | ||
|
||
test(`it returns hash, search, and pathname if all defined`, () => { | ||
const hash = `#some-id` | ||
const pathname = `/admin` | ||
const search = `?this-thing=true&other-thing=false` | ||
const path = `${pathname}${search}${hash}` | ||
|
||
expect(parsePath(path)).toEqual({ | ||
pathname, | ||
search, | ||
hash, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/gatsby/cache-dir/parse-path.js → packages/gatsby-link/src/parse-path.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters