forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
49 lines (39 loc) 路 1.29 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
import * as path from "path"
import { testPluginOptionsSchema } from "gatsby-plugin-utils"
import { onCreateBabelConfig, pluginOptionsSchema } from "../gatsby-node"
describe(`onCreateBabelConfig`, () => {
it(`sets the correct babel preset`, () => {
const actions = { setBabelPreset: jest.fn() }
onCreateBabelConfig({ actions })
expect(actions.setBabelPreset).toHaveBeenCalledTimes(1)
expect(actions.setBabelPreset).toHaveBeenCalledWith({
name: expect.stringContaining(path.join(`@babel`, `preset-flow`)),
})
})
})
describe(`pluginOptionsSchema`, () => {
it(`should provide meaningful errors when fields are invalid`, async () => {
const expectedWarnings = [`"optionA" is not allowed`]
const { isValid, warnings, hasWarnings } = await testPluginOptionsSchema(
pluginOptionsSchema,
{
optionA: `This option shouldn't exist`,
}
)
expect(isValid).toBe(true)
expect(hasWarnings).toBe(true)
expect(warnings).toEqual(expectedWarnings)
})
it.each`
options
${undefined}
${{}}
`(`should validate the schema: $options`, async ({ options }) => {
const { isValid, errors } = await testPluginOptionsSchema(
pluginOptionsSchema,
options
)
expect(isValid).toBe(true)
expect(errors).toEqual([])
})
})