-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
gen-mdx.js
63 lines (58 loc) · 1.55 KB
/
gen-mdx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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 testPluginModulePath = path.join(__dirname, `fixtures`, `test-plugin`)
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: testPluginModulePath,
module: require(testPluginModulePath),
},
],
},
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`],
})
})
})