Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby-transformer-remark): correctly pass cache to sub plugins (#…
- Loading branch information
Showing
11 changed files
with
70 additions
and
10 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
16 changes: 16 additions & 0 deletions
16
e2e-tests/development-runtime/cypress/integration/functionality/sub-plugin-caching.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,16 @@ | ||
/* | ||
* This e2e test validates that the cache structure | ||
* is unique per plugin (even sub-plugins) | ||
* and can interact between Gatsby lifecycles and a plugin | ||
*/ | ||
describe(`sub-plugin caching`, () => { | ||
beforeEach(() => { | ||
cy.visit(`/2018-12-14-hello-world/`).waitForAPI(`onRouteUpdate`) | ||
}) | ||
|
||
it(`has access to custom sub-plugin cache`, () => { | ||
cy.getTestElement(`gatsby-remark-subcache-value`) | ||
.invoke(`text`) | ||
.should(`eq`, `Hello World`) | ||
}) | ||
}) |
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
1 change: 1 addition & 0 deletions
1
e2e-tests/development-runtime/plugins/gatsby-remark-subcache/constants.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 @@ | ||
exports.id = `gatsby-remark-subcache-value` |
5 changes: 5 additions & 0 deletions
5
e2e-tests/development-runtime/plugins/gatsby-remark-subcache/gatsby-node.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,5 @@ | ||
const { id } = require(`./constants`) | ||
|
||
exports.onPreBootstrap = async ({ cache }) => { | ||
await cache.set(id, `Hello World`) | ||
} |
11 changes: 11 additions & 0 deletions
11
e2e-tests/development-runtime/plugins/gatsby-remark-subcache/index.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,11 @@ | ||
const visit = require(`unist-util-visit`) | ||
const { id } = require(`./constants`) | ||
|
||
module.exports = function remarkPlugin({ cache, markdownAST }) { | ||
visit(markdownAST, `html`, async node => { | ||
if (node.value.match(id)) { | ||
const value = await cache.get(id) | ||
node.value = node.value.replace(/%SUBCACHE_VALUE%/, value) | ||
} | ||
}) | ||
} |
3 changes: 3 additions & 0 deletions
3
e2e-tests/development-runtime/plugins/gatsby-remark-subcache/package.json
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,3 @@ | ||
{ | ||
"name": "gatsby-remark-subcache" | ||
} |
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