-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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): correctly inject static query in theme components #10786
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4f3e050
fix(gatsby): correctly replace static query content in themes
DSchau 2ec498c
chore: add a scoped package test
DSchau 90419a4
refactor(gatsby): just use the resolved path, don't make relative
DSchau 3b65605
fix: hopefully fix windows issues (fingers crossed emoji)
DSchau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
packages/gatsby/src/internal-plugins/query-runner/__tests__/query-compiler.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
jest.mock(`glob`, () => { | ||
const sync = jest.fn().mockImplementation(() => []) | ||
return { | ||
sync, | ||
} | ||
}) | ||
const path = require(`path`) | ||
const glob = require(`glob`) | ||
const { resolveThemes, Runner } = require(`../query-compiler`) | ||
|
||
const base = path.resolve(``) | ||
|
||
describe(`Runner`, () => { | ||
beforeEach(() => { | ||
glob.sync.mockClear() | ||
}) | ||
|
||
it(`returns a file parser instance`, async () => { | ||
const runner = new Runner(base, [], {}) | ||
|
||
const parser = await runner.parseEverything() | ||
|
||
expect(parser).toEqual(new Map()) | ||
}) | ||
|
||
describe(`expected directories`, () => { | ||
it(`compiles src directory`, async () => { | ||
const runner = new Runner(base, [], {}) | ||
|
||
await runner.parseEverything() | ||
|
||
expect(glob.sync).toHaveBeenCalledWith( | ||
expect.stringContaining(path.join(base, `src`)), | ||
expect.any(Object) | ||
) | ||
}) | ||
|
||
it(`compiles fragments directory`, async () => { | ||
const runner = new Runner(base, [], {}) | ||
|
||
await runner.parseEverything() | ||
|
||
expect(glob.sync).toHaveBeenCalledWith( | ||
expect.stringContaining(path.join(base, `src`)), | ||
expect.any(Object) | ||
) | ||
}) | ||
|
||
it(`compiles themes directory(s)`, async () => { | ||
const theme = `gatsby-theme-whatever` | ||
const runner = new Runner( | ||
base, | ||
[path.join(base, `node_modules`, theme)], | ||
{} | ||
) | ||
|
||
await runner.parseEverything() | ||
|
||
expect(glob.sync).toHaveBeenCalledWith( | ||
expect.stringContaining(path.join(base, `node_modules`, theme)), | ||
expect.any(Object) | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
describe(`resolveThemes`, () => { | ||
it(`returns empty array if zero themes detected`, () => { | ||
;[ | ||
[], | ||
[{ resolve: path.join(base, `gatsby-plugin-whatever`) }], | ||
undefined, | ||
].forEach(testRun => { | ||
expect(resolveThemes(testRun)).toEqual([]) | ||
}) | ||
}) | ||
|
||
it(`returns plugins matching gatsby-theme prefix`, () => { | ||
const theme = `gatsby-theme-example` | ||
expect( | ||
resolveThemes([ | ||
{ | ||
resolve: path.join(base, `gatsby-theme-example`), | ||
}, | ||
]) | ||
).toEqual([expect.stringContaining(theme)]) | ||
}) | ||
|
||
it(`handles scoped packages`, () => { | ||
const theme = `@dschau/gatsby-theme-example` | ||
|
||
expect( | ||
resolveThemes([ | ||
{ | ||
resolve: path.join(base, theme), | ||
}, | ||
]) | ||
).toEqual([expect.stringContaining(theme.split(`/`).join(path.sep))]) | ||
}) | ||
}) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @ChristopherBiscardi once #10787 lands I can swap to
themes
from the redux state.I don't really consider it a blocker for this PR though. We can get this one merged and then tweak later, removing the
gatsby-theme
test which will be 👌There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm