/
gatsby-node.js
110 lines (101 loc) · 2.73 KB
/
gatsby-node.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const path = require(`path`)
const { onCreateNode, shouldOnCreateNode } = require(`../gatsby-node`)
jest.mock(`asciidoctor`, () => () => {
return {
load: jest.fn(() => {
return {
hasRevisionInfo: jest.fn(),
getAuthor: jest.fn(),
getAttributes: jest.fn(() => {
return {}
}),
getAttribute: jest.fn(),
convert: jest.fn(() => `html generated`),
getDocumentTitle: jest.fn(() => {
return {
getCombined: jest.fn(() => `title`),
hasSubtitle: jest.fn(() => true),
getSubtitle: jest.fn(() => `subtitle`),
getMain: jest.fn(() => `main`),
}
}),
}
}),
}
})
describe(`gatsby-transformer-asciidoc`, () => {
let node
let actions
let loadNodeContent
let createNodeId
let createContentDigest
beforeEach(() => {
node = {
id: `dummy`,
extension: `asciidoc`,
dir: path.resolve(__dirname),
}
actions = {
createNode: jest.fn(),
createParentChildLink: jest.fn(),
}
loadNodeContent = jest.fn(node => node)
createNodeId = jest.fn(node => node)
createContentDigest = jest.fn(() => `digest`)
})
it(`should do nothing when extension is not allowed`, async () => {
node.extension = `foo`
const shouldCreateNode = shouldOnCreateNode({ node }, {})
if (shouldCreateNode) {
await onCreateNode(
{ node, actions, loadNodeContent, createNodeId, createContentDigest },
{}
)
}
expect(actions.createNode).not.toHaveBeenCalled()
})
it(`should enhance available extension`, async () => {
node.extension = `ad`
const shouldCreateNode = shouldOnCreateNode(
{ node },
{ fileExtensions: [`ad`] }
)
if (shouldCreateNode) {
await onCreateNode(
{ node, actions, loadNodeContent, createNodeId, createContentDigest },
{ fileExtensions: [`ad`] }
)
}
expect(actions.createNode).toHaveBeenCalled()
})
it(`should create node based on loaded asciidoc file`, async () => {
const shouldCreateNode = shouldOnCreateNode({ node }, {})
if (shouldCreateNode) {
await onCreateNode(
{
node,
actions,
loadNodeContent,
createNodeId,
createContentDigest,
},
{}
)
}
expect(actions.createNode).toHaveBeenCalledWith({
author: null,
children: [],
document: { main: `main`, subtitle: `subtitle`, title: `title` },
html: `html generated`,
id: `dummy >>> ASCIIDOC`,
internal: {
contentDigest: `digest`,
mediaType: `text/html`,
type: `Asciidoc`,
},
pageAttributes: {},
parent: `dummy`,
revision: null,
})
})
})