Skip to content

Commit

Permalink
fix(gatsby-transformer-react-docgen): always create description nodes (
Browse files Browse the repository at this point in the history
…#14876)

* fix: always create description nodes

* Update on-node-create.js

* fix tests
  • Loading branch information
jquense authored and DSchau committed Jun 18, 2019
1 parent 75a9e19 commit 48a9e10
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ const readFile = file =>
describe(`transformer-react-doc-gen: onCreateNode`, () => {
let loadNodeContent, actions, node, createdNodes, updatedNodes
const createNodeId = jest.fn()
let i

beforeAll(() => {
i = 0
createNodeId.mockImplementation(() => i++)
})

createNodeId.mockReturnValue(`uuid-from-gatsby`)
let run = (node, opts = {}) => {
const createContentDigest = jest.fn().mockReturnValue(`contentDigest`)
return onCreateNode(
Expand Down Expand Up @@ -124,7 +129,19 @@ describe(`transformer-react-doc-gen: onCreateNode`, () => {

await run(node)

expect(createdNodes[0].displayName).toEqual(`Unnamed`)
expect(
groupBy(createdNodes, `internal.type`).ComponentMetadata[0].displayName
).toEqual(`Unnamed`)
})

it(`should create a description node when there is no description`, async () => {
node.__fixture = `unnamed.js`

await run(node)

expect(
groupBy(createdNodes, `internal.type`).ComponentDescription
).toHaveLength(1)
})

it(`should extract all propTypes`, async () => {
Expand All @@ -138,13 +155,17 @@ describe(`transformer-react-doc-gen: onCreateNode`, () => {
await run(node)

let types = groupBy(createdNodes, `internal.type`)
expect(types.ComponentProp[0].description).toEqual(
`An object hash of field (fix this @mention?) errors for the form.`
)

const id = types.ComponentProp[0].id

expect(types.ComponentProp[0].doclets).toEqual([
{ tag: `type`, value: `{Foo}` },
{ tag: `default`, value: `blue` },
])

expect(types.ComponentDescription.find(d => d.parent === id).text).toEqual(
`An object hash of field (fix this @mention?) errors for the form.`
)
})

it(`should extract create description nodes with markdown types`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ function createDescriptionNode(
createNodeId,
createContentDigest
) {
if (!entry.description) return node
const { createNode } = actions

delete node.description

const descriptionNode = {
id: createNodeId(descId(node.id)),
parent: node.id,
Expand Down

0 comments on commit 48a9e10

Please sign in to comment.