Skip to content

Commit

Permalink
fix(gatsby-transformer-remark): wait for cache promises before return…
Browse files Browse the repository at this point in the history
…ing (#27871)

* chore(gatsby-transformer-remark): refactor async logic to allow serial mode

* Refactor the rest while we are here

* Move addSlugToUrl out of the inner-inner function

* arrow -> nfe

* fix: fake/placeholder cache get/set should be async too

* Be explicit and greppable about GatsbyCache

* Refactor more cases to proper async/await

* Make test not assume a non-async response

* await promise like all the others
  • Loading branch information
pvdz authored Nov 10, 2020
1 parent e546e9a commit 071d50d
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 173 deletions.
32 changes: 17 additions & 15 deletions packages/gatsby-transformer-remark/src/__tests__/extend-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ async function queryResult(
{
type: { name: `MarkdownRemark` },
cache: {
get: () => null,
set: () => null,
// GatsbyCache
get: async () => null,
set: async () => null,
},
getNodesByType: type => [],
...additionalParameters,
Expand Down Expand Up @@ -104,23 +105,24 @@ const bootstrapTest = (

it(label, async done => {
node.content = content
const createNode = markdownNode => {
queryResult([markdownNode], query, {
async function createNode(markdownNode) {
const result = await queryResult([markdownNode], query, {
additionalParameters,
pluginOptions,
}).then(result => {
if (result.errors) {
done.fail(result.errors)
}

try {
test(result.data.listNode[0])
done()
} catch (err) {
done.fail(err)
}
})

if (result.errors) {
done.fail(result.errors)
}

try {
test(result.data.listNode[0])
done()
} catch (err) {
done.fail(err)
}
}

const createParentChildLink = jest.fn()
const actions = { createNode, createParentChildLink }
const createNodeId = jest.fn()
Expand Down
Loading

0 comments on commit 071d50d

Please sign in to comment.