-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
merge-gatsby-config.js
113 lines (103 loc) · 2.57 KB
/
merge-gatsby-config.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
111
112
113
const mergeGatsbyConfig = require(`../merge-gatsby-config`)
describe(`Merge gatsby config`, () => {
it(`Merging empty config is an identity operation`, () => {
const emptyConfig = {}
const basicConfig = {
plugins: [`gatsby-mdx`],
}
expect(mergeGatsbyConfig(basicConfig, emptyConfig)).toEqual(basicConfig)
expect(mergeGatsbyConfig(emptyConfig, basicConfig)).toEqual(basicConfig)
})
it(`Merging plugins concatenates them`, () => {
const basicConfig = {
plugins: [`gatsby-mdx`],
}
const morePlugins = {
plugins: [`a-plugin`, `b-plugin`, { resolve: `c-plugin`, options: {} }],
}
expect(mergeGatsbyConfig(basicConfig, morePlugins)).toEqual({
plugins: [
`gatsby-mdx`,
`a-plugin`,
`b-plugin`,
{ resolve: `c-plugin`, options: {} },
],
})
expect(mergeGatsbyConfig(morePlugins, basicConfig)).toEqual({
plugins: [
`a-plugin`,
`b-plugin`,
{ resolve: `c-plugin`, options: {} },
`gatsby-mdx`,
],
})
})
it(`Merging plugins uniqs them, keeping the first occurrence`, () => {
const basicConfig = {
plugins: [`gatsby-mdx`],
}
const morePlugins = {
plugins: [
`a-plugin`,
`gatsby-mdx`,
`b-plugin`,
{ resolve: `c-plugin`, options: {} },
],
}
expect(mergeGatsbyConfig(basicConfig, morePlugins)).toEqual({
plugins: [
`gatsby-mdx`,
`a-plugin`,
`b-plugin`,
{ resolve: `c-plugin`, options: {} },
],
})
expect(mergeGatsbyConfig(morePlugins, basicConfig)).toEqual({
plugins: [
`a-plugin`,
`gatsby-mdx`,
`b-plugin`,
{ resolve: `c-plugin`, options: {} },
],
})
})
it(`Merging siteMetadata is recursive`, () => {
const a = {
siteMetadata: {
title: `my site`,
something: { else: 1 },
},
}
const b = {
siteMetadata: {
something: { nested: 2 },
},
}
expect(mergeGatsbyConfig(a, b)).toEqual({
siteMetadata: {
title: `my site`,
something: { else: 1, nested: 2 },
},
})
})
it(`Merging proxy is overriden`, () => {
const a = {
proxy: {
prefix: `/something-not/api`,
url: `http://examplesite.com/api/`,
},
}
const b = {
proxy: {
prefix: `/api`,
url: `http://examplesite.com/api/`,
},
}
expect(mergeGatsbyConfig(a, b)).toEqual({
proxy: {
prefix: `/api`,
url: `http://examplesite.com/api/`,
},
})
})
})