-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f8f5f2
commit f31db82
Showing
11 changed files
with
293 additions
and
293 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
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
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
138 changes: 69 additions & 69 deletions
138
packages/gatsby-transformer-remark/src/__tests__/extend-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 |
---|---|---|
@@ -1,100 +1,100 @@ | ||
const _ = require(`lodash`) | ||
const { | ||
graphql, | ||
GraphQLObjectType, | ||
GraphQLList, | ||
GraphQLSchema, | ||
} = require(`graphql`) | ||
graphql, | ||
GraphQLObjectType, | ||
GraphQLList, | ||
GraphQLSchema, | ||
} = require(`graphql`) | ||
const { onCreateNode } = require(`../gatsby-node`) | ||
const { inferObjectStructureFromNodes } = require(`../../../gatsby/src/schema/infer-graphql-type`) | ||
const { | ||
inferObjectStructureFromNodes, | ||
} = require(`../../../gatsby/src/schema/infer-graphql-type`) | ||
|
||
// given a set of nodes and a query, return the result of the query | ||
async function queryResult(nodes, fragment, { types = [] } = {}) { | ||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: `RootQueryType`, | ||
fields: () => { | ||
return { | ||
listNode: { | ||
name: `LISTNODE`, | ||
type: new GraphQLList( | ||
new GraphQLObjectType({ | ||
name: `MarkdownRemark`, | ||
fields: inferObjectStructureFromNodes({ | ||
nodes, | ||
types: [...types], | ||
}), | ||
}) | ||
), | ||
resolve() { | ||
return nodes | ||
}, | ||
}, | ||
} | ||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: `RootQueryType`, | ||
fields: () => { | ||
return { | ||
listNode: { | ||
name: `LISTNODE`, | ||
type: new GraphQLList( | ||
new GraphQLObjectType({ | ||
name: `MarkdownRemark`, | ||
fields: inferObjectStructureFromNodes({ | ||
nodes, | ||
types: [...types], | ||
}), | ||
}) | ||
), | ||
resolve() { | ||
return nodes | ||
}, | ||
}), | ||
}) | ||
}, | ||
} | ||
}, | ||
}), | ||
}) | ||
|
||
const result = await graphql( | ||
schema, | ||
`query { | ||
const result = await graphql( | ||
schema, | ||
`query { | ||
listNode { | ||
${fragment} | ||
} | ||
} | ||
`, | ||
) | ||
return result | ||
` | ||
) | ||
return result | ||
} | ||
|
||
describe(`Excerpt is generated correctly from schema`, () => { | ||
|
||
const node = { | ||
id: `whatever`, | ||
children: [], | ||
internal: { | ||
contentDigest: `whatever`, | ||
mediaType: `text/markdown`, | ||
}, | ||
} | ||
|
||
// Make some fake functions its expecting. | ||
const loadNodeContent = node => Promise.resolve(node.content) | ||
const node = { | ||
id: `whatever`, | ||
children: [], | ||
internal: { | ||
contentDigest: `whatever`, | ||
mediaType: `text/markdown`, | ||
}, | ||
} | ||
|
||
// Make some fake functions its expecting. | ||
const loadNodeContent = node => Promise.resolve(node.content) | ||
|
||
|
||
it(`correctly loads a default excerpt`, async () => { | ||
const content = `--- | ||
it(`correctly loads a default excerpt`, async () => { | ||
const content = `--- | ||
title: "my little pony" | ||
date: "2017-09-18T23:19:51.246Z" | ||
--- | ||
Where oh where is my little pony? | ||
` | ||
|
||
node.content = content | ||
|
||
const createNode = markdownNode => { | ||
queryResult([ markdownNode ], | ||
` | ||
node.content = content | ||
|
||
const createNode = markdownNode => { | ||
queryResult( | ||
[markdownNode], | ||
` | ||
excerpt | ||
frontmatter { | ||
title | ||
} | ||
`, | ||
{ | ||
types: [ { name: `MarkdownRemark` } ], | ||
}).then(result => { | ||
expect(_.isString(result.data.listNode.excerpt)) | ||
}) | ||
{ | ||
types: [{ name: `MarkdownRemark` }], | ||
} | ||
const createParentChildLink = jest.fn() | ||
const boundActionCreators = { createNode, createParentChildLink } | ||
).then(result => { | ||
expect(_.isString(result.data.listNode.excerpt)) | ||
}) | ||
} | ||
const createParentChildLink = jest.fn() | ||
const boundActionCreators = { createNode, createParentChildLink } | ||
|
||
await onCreateNode({ | ||
node, | ||
loadNodeContent, | ||
boundActionCreators, | ||
}) | ||
await onCreateNode({ | ||
node, | ||
loadNodeContent, | ||
boundActionCreators, | ||
}) | ||
|
||
}) | ||
}) |
Oops, something went wrong.