Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: gatsby-plugin-mdx's findImports not running plugins (#26191)
- Loading branch information
1 parent
70cd249
commit ae5f581
Showing
3 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
packages/gatsby-plugin-mdx/utils/__tests__/fixtures/test-plugin.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,14 @@ | ||
function createImportAST(name, filePath) { | ||
return { | ||
type: `import`, | ||
value: `import ${name} from '${filePath}'`, | ||
} | ||
} | ||
|
||
module.exports = ({ markdownAST }) => { | ||
markdownAST.children = [ | ||
createImportAST(`* as testInjection`, `@private/test-inject`), | ||
...markdownAST.children, | ||
] | ||
return markdownAST | ||
} |
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,59 @@ | ||
const path = require(`path`) | ||
const { findImports } = require(`../gen-mdx`) | ||
|
||
const markdownContent = `--- | ||
title: Introduction | ||
--- | ||
# Header 1 | ||
## Header 2 | ||
### Header 3 | ||
\`\`\`js | ||
console.log('hello world') | ||
\`\`\` | ||
` | ||
|
||
describe(`find imports`, () => { | ||
it(`allows injecting imports via plugins`, async () => { | ||
const results = await findImports({ | ||
node: { | ||
id: `bbffffbb-bfff-bfff-bfff-dededededede`, | ||
children: [], | ||
parent: `bbffffbb-bfff-bfff-bfff-dededededebb`, | ||
internal: { | ||
content: markdownContent, | ||
type: `Mdx`, | ||
contentDigest: `6433c536b5eb922ad01f8d420bcabf6d`, | ||
counter: 38, | ||
owner: `gatsby-plugin-mdx`, | ||
}, | ||
frontmatter: { title: `Introduction` }, | ||
excerpt: undefined, | ||
exports: {}, | ||
rawBody: markdownContent, | ||
fileAbsolutePath: `/path/to/getting-started.mdx`, | ||
}, | ||
options: { | ||
remarkPlugins: [], | ||
gatsbyRemarkPlugins: [ | ||
{ resolve: path.join(__dirname, `fixtures`, `test-plugin`) }, | ||
], | ||
}, | ||
getNode: () => null, | ||
getNodes: () => [], | ||
getNodesByType: () => [], | ||
repoter: () => {}, | ||
cache: () => {}, | ||
pathPrefix: ``, | ||
}) | ||
|
||
expect(results).toEqual({ | ||
scopeImports: [ | ||
`import * as testInjection from '@private/test-inject'`, | ||
`import * as React from 'react'`, | ||
], | ||
scopeIdentifiers: [`testInjection`, `React`], | ||
}) | ||
}) | ||
}) |
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