1
1
import { gatsbyConfigSchema , nodeSchema } from "../joi"
2
2
3
3
describe ( `gatsby config` , ( ) => {
4
- it ( `returns empty pathPrefix when not set` , async ( ) => {
4
+ it ( `returns empty pathPrefix when not set` , ( ) => {
5
5
const config = { }
6
6
7
- const result = await gatsbyConfigSchema . validate ( config )
8
- expect ( result ) . toEqual (
7
+ const result = gatsbyConfigSchema . validate ( config )
8
+ expect ( result . value ) . toEqual (
9
9
expect . objectContaining ( {
10
10
pathPrefix : `` ,
11
11
} )
12
12
)
13
13
} )
14
14
15
- it ( `strips trailing slashes from url fields` , async ( ) => {
15
+ it ( `throws when linkPrefix is set` , ( ) => {
16
+ const config = {
17
+ linkPrefix : `/blog/` ,
18
+ }
19
+
20
+ const result = gatsbyConfigSchema . validate ( config )
21
+ expect ( result . error ) . toMatchInlineSnapshot (
22
+ `[Error: "linkPrefix" should be changed to "pathPrefix"]`
23
+ )
24
+ } )
25
+
26
+ it ( `strips trailing slashes from url fields` , ( ) => {
16
27
const config = {
17
28
pathPrefix : `/blog///` ,
18
29
assetPrefix : `https://cdn.example.com/` ,
19
30
}
20
31
21
- const result = await gatsbyConfigSchema . validate ( config )
22
- expect ( result ) . toEqual (
32
+ const result = gatsbyConfigSchema . validate ( config )
33
+ expect ( result . value ) . toEqual (
23
34
expect . objectContaining ( {
24
35
pathPrefix : `/blog` ,
25
36
assetPrefix : `https://cdn.example.com` ,
26
37
} )
27
38
)
28
39
} )
29
40
30
- it ( `allows assetPrefix to be full URL` , async ( ) => {
41
+ it ( `allows assetPrefix to be full URL` , ( ) => {
31
42
const config = {
32
43
assetPrefix : `https://cdn.example.com/` ,
33
44
}
34
45
35
- const result = await gatsbyConfigSchema . validate ( config )
36
- expect ( result ) . toEqual (
46
+ const result = gatsbyConfigSchema . validate ( config )
47
+ expect ( result . value ) . toEqual (
37
48
expect . objectContaining ( {
38
49
assetPrefix : `https://cdn.example.com` ,
39
50
} )
40
51
)
41
52
} )
42
53
43
- it ( `allows assetPrefix to be a URL with nested paths` , async ( ) => {
54
+ it ( `allows assetPrefix to be a URL with nested paths` , ( ) => {
44
55
const config = {
45
56
assetPrefix : `https://cdn.example.com/some/nested/path` ,
46
57
}
47
58
48
- const result = await gatsbyConfigSchema . validate ( config )
49
- expect ( result ) . toEqual ( expect . objectContaining ( config ) )
59
+ const result = gatsbyConfigSchema . validate ( config )
60
+ expect ( result . value ) . toEqual ( expect . objectContaining ( config ) )
50
61
} )
51
62
52
- it ( `allows relative paths for url fields` , async ( ) => {
63
+ it ( `allows relative paths for url fields` , ( ) => {
53
64
const config = {
54
65
pathPrefix : `/blog` ,
55
66
assetPrefix : `https://cdn.example.com` ,
56
67
}
57
68
58
- const result = await gatsbyConfigSchema . validate ( config )
59
- expect ( result ) . toEqual ( expect . objectContaining ( config ) )
69
+ const result = gatsbyConfigSchema . validate ( config )
70
+ expect ( result . value ) . toEqual ( expect . objectContaining ( config ) )
60
71
} )
61
72
62
- it ( `strips trailing slash and add leading slash to pathPrefix` , async ( ) => {
73
+ it ( `strips trailing slash and add leading slash to pathPrefix` , ( ) => {
63
74
const config = {
64
75
pathPrefix : `blog/` ,
65
76
assetPrefix : `https://cdn.example.com/` ,
66
77
}
67
78
68
- const result = await gatsbyConfigSchema . validate ( config )
69
- expect ( result ) . toEqual (
79
+ const result = gatsbyConfigSchema . validate ( config )
80
+ expect ( result . value ) . toEqual (
70
81
expect . objectContaining ( {
71
82
pathPrefix : `/blog` ,
72
83
assetPrefix : `https://cdn.example.com` ,
73
84
} )
74
85
)
75
86
} )
76
87
77
- it ( `does not allow pathPrefix to be full URL` , async ( ) => {
78
- expect . assertions ( 1 )
88
+ it ( `does not allow pathPrefix to be full URL` , ( ) => {
79
89
const config = {
80
90
pathPrefix : `https://google.com` ,
81
91
}
82
92
83
- try {
84
- await gatsbyConfigSchema . validate ( config )
85
- } catch ( err ) {
86
- expect ( err . message ) . toMatchSnapshot ( )
87
- }
93
+ const result = gatsbyConfigSchema . validate ( config )
94
+ expect ( result . error ) . toMatchInlineSnapshot (
95
+ `[ValidationError: "pathPrefix" must be a valid relative uri]`
96
+ )
88
97
} )
89
98
90
- it ( `throws when relative path used for both assetPrefix and pathPrefix` , async ( ) => {
91
- expect . assertions ( 1 )
99
+ it ( `throws when relative path used for both assetPrefix and pathPrefix` , ( ) => {
92
100
const config = {
93
101
assetPrefix : `/assets` ,
94
102
pathPrefix : `/blog` ,
95
103
}
96
104
97
- try {
98
- await gatsbyConfigSchema . validate ( config )
99
- } catch ( err ) {
100
- expect ( err . message ) . toMatchSnapshot ( )
101
- }
105
+ const result = gatsbyConfigSchema . validate ( config )
106
+ expect ( result . error ) . toMatchInlineSnapshot (
107
+ `[Error: assetPrefix must be an absolute URI when used with pathPrefix]`
108
+ )
102
109
} )
103
110
} )
104
111
105
112
describe ( `node schema` , ( ) => {
106
- it ( `allows correct nodes` , async ( ) => {
113
+ it ( `allows correct nodes` , ( ) => {
107
114
const node = {
108
115
id : `foo` ,
109
116
internal : {
@@ -119,7 +126,7 @@ describe(`node schema`, () => {
119
126
expect ( error ) . toBeFalsy ( )
120
127
} )
121
128
122
- it ( `force id type` , async ( ) => {
129
+ it ( `force id type` , ( ) => {
123
130
const node = {
124
131
id : 5 ,
125
132
internal : {
@@ -134,10 +141,10 @@ describe(`node schema`, () => {
134
141
const { error } = nodeSchema . validate ( node )
135
142
expect ( error ) . toBeTruthy ( )
136
143
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
137
- expect ( error ! . message ) . toMatchSnapshot ( )
144
+ expect ( error ! . message ) . toMatchInlineSnapshot ( `"\\"id\\" must be a string"` )
138
145
} )
139
146
140
- it ( `doesn't allow unknown internal fields` , async ( ) => {
147
+ it ( `doesn't allow unknown internal fields` , ( ) => {
141
148
const node = {
142
149
id : `foo` ,
143
150
internal : {
@@ -154,6 +161,8 @@ describe(`node schema`, () => {
154
161
const { error } = nodeSchema . validate ( node )
155
162
expect ( error ) . toBeTruthy ( )
156
163
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
157
- expect ( error ! . message ) . toMatchSnapshot ( )
164
+ expect ( error ! . message ) . toMatchInlineSnapshot (
165
+ `"\\"internal.customField\\" is not allowed"`
166
+ )
158
167
} )
159
168
} )
0 commit comments