|
1 | 1 | const path = require(`path`) |
2 | | -const { onCreateNode } = require(`../gatsby-node`) |
| 2 | +const { onCreateNode, shouldOnCreateNode } = require(`../gatsby-node`) |
3 | 3 |
|
4 | 4 | jest.mock(`asciidoctor`, () => () => { |
5 | 5 | return { |
@@ -47,35 +47,50 @@ describe(`gatsby-transformer-asciidoc`, () => { |
47 | 47 | createContentDigest = jest.fn(() => `digest`) |
48 | 48 | }) |
49 | 49 |
|
50 | | - it(`should do nothing when extension is not whitelisted`, async () => { |
| 50 | + it(`should do nothing when extension is not allowed`, async () => { |
51 | 51 | node.extension = `foo` |
52 | | - await onCreateNode( |
53 | | - { node, actions, loadNodeContent, createNodeId, createContentDigest }, |
54 | | - {} |
55 | | - ) |
| 52 | + const shouldCreateNode = shouldOnCreateNode({ node }, {}) |
| 53 | + |
| 54 | + if (shouldCreateNode) { |
| 55 | + await onCreateNode( |
| 56 | + { node, actions, loadNodeContent, createNodeId, createContentDigest }, |
| 57 | + {} |
| 58 | + ) |
| 59 | + } |
56 | 60 | expect(actions.createNode).not.toHaveBeenCalled() |
57 | 61 | }) |
58 | 62 |
|
59 | 63 | it(`should enhance available extension`, async () => { |
60 | 64 | node.extension = `ad` |
61 | | - await onCreateNode( |
62 | | - { node, actions, loadNodeContent, createNodeId, createContentDigest }, |
| 65 | + const shouldCreateNode = shouldOnCreateNode( |
| 66 | + { node }, |
63 | 67 | { fileExtensions: [`ad`] } |
64 | 68 | ) |
| 69 | + |
| 70 | + if (shouldCreateNode) { |
| 71 | + await onCreateNode( |
| 72 | + { node, actions, loadNodeContent, createNodeId, createContentDigest }, |
| 73 | + { fileExtensions: [`ad`] } |
| 74 | + ) |
| 75 | + } |
65 | 76 | expect(actions.createNode).toHaveBeenCalled() |
66 | 77 | }) |
67 | 78 |
|
68 | 79 | it(`should create node based on loaded asciidoc file`, async () => { |
69 | | - await onCreateNode( |
70 | | - { |
71 | | - node, |
72 | | - actions, |
73 | | - loadNodeContent, |
74 | | - createNodeId, |
75 | | - createContentDigest, |
76 | | - }, |
77 | | - {} |
78 | | - ) |
| 80 | + const shouldCreateNode = shouldOnCreateNode({ node }, {}) |
| 81 | + |
| 82 | + if (shouldCreateNode) { |
| 83 | + await onCreateNode( |
| 84 | + { |
| 85 | + node, |
| 86 | + actions, |
| 87 | + loadNodeContent, |
| 88 | + createNodeId, |
| 89 | + createContentDigest, |
| 90 | + }, |
| 91 | + {} |
| 92 | + ) |
| 93 | + } |
79 | 94 | expect(actions.createNode).toHaveBeenCalledWith({ |
80 | 95 | author: null, |
81 | 96 | children: [], |
|
0 commit comments