|
1 | 1 | const { gatsbyConfigSchema } = require(`../joi`)
|
2 | 2 |
|
3 | 3 | describe(`gatsby config`, () => {
|
4 |
| - it(`strips trailing slashes from url fields`, () => { |
| 4 | + it(`returns empty pathPrefix when not set`, async () => { |
| 5 | + const config = {} |
| 6 | + |
| 7 | + const result = await gatsbyConfigSchema.validate(config) |
| 8 | + expect(result).toEqual( |
| 9 | + expect.objectContaining({ |
| 10 | + pathPrefix: ``, |
| 11 | + }) |
| 12 | + ) |
| 13 | + }) |
| 14 | + |
| 15 | + it(`strips trailing slashes from url fields`, async () => { |
5 | 16 | const config = {
|
6 | 17 | pathPrefix: `/blog///`,
|
7 | 18 | assetPrefix: `https://cdn.example.com/`,
|
8 | 19 | }
|
9 | 20 |
|
10 |
| - expect(gatsbyConfigSchema.validate(config)).resolves.toEqual({ |
11 |
| - pathPrefix: `/blog`, |
12 |
| - assetPrefix: `https://cdn.example.com`, |
13 |
| - }) |
| 21 | + const result = await gatsbyConfigSchema.validate(config) |
| 22 | + expect(result).toEqual( |
| 23 | + expect.objectContaining({ |
| 24 | + pathPrefix: `/blog`, |
| 25 | + assetPrefix: `https://cdn.example.com`, |
| 26 | + }) |
| 27 | + ) |
14 | 28 | })
|
15 | 29 |
|
16 |
| - it(`allows assetPrefix to be full URL`, () => { |
| 30 | + it(`allows assetPrefix to be full URL`, async () => { |
17 | 31 | const config = {
|
18 |
| - assetPrefix: `https://cdn.example.com`, |
| 32 | + assetPrefix: `https://cdn.example.com/`, |
19 | 33 | }
|
20 | 34 |
|
21 |
| - expect(gatsbyConfigSchema.validate(config)).resolves.toEqual(config) |
| 35 | + const result = await gatsbyConfigSchema.validate(config) |
| 36 | + expect(result).toEqual( |
| 37 | + expect.objectContaining({ |
| 38 | + assetPrefix: `https://cdn.example.com`, |
| 39 | + }) |
| 40 | + ) |
22 | 41 | })
|
23 | 42 |
|
24 |
| - it(`allows assetPrefix to be a URL with nested paths`, () => { |
| 43 | + it(`allows assetPrefix to be a URL with nested paths`, async () => { |
25 | 44 | const config = {
|
26 | 45 | assetPrefix: `https://cdn.example.com/some/nested/path`,
|
27 | 46 | }
|
28 | 47 |
|
29 |
| - expect(gatsbyConfigSchema.validate(config)).resolves.toEqual(config) |
| 48 | + const result = await gatsbyConfigSchema.validate(config) |
| 49 | + expect(result).toEqual(expect.objectContaining(config)) |
30 | 50 | })
|
31 | 51 |
|
32 |
| - it(`allows relative paths for url fields`, () => { |
| 52 | + it(`allows relative paths for url fields`, async () => { |
33 | 53 | const config = {
|
34 | 54 | pathPrefix: `/blog`,
|
35 | 55 | assetPrefix: `https://cdn.example.com`,
|
36 | 56 | }
|
37 | 57 |
|
38 |
| - expect(gatsbyConfigSchema.validate(config)).resolves.toEqual(config) |
| 58 | + const result = await gatsbyConfigSchema.validate(config) |
| 59 | + expect(result).toEqual(expect.objectContaining(config)) |
39 | 60 | })
|
40 | 61 |
|
41 |
| - it(`does not allow pathPrefix to be full URL`, () => { |
| 62 | + it(`strips trailing slash and add leading slash to pathPrefix`, async () => { |
| 63 | + const config = { |
| 64 | + pathPrefix: `blog/`, |
| 65 | + assetPrefix: `https://cdn.example.com/`, |
| 66 | + } |
| 67 | + |
| 68 | + const result = await gatsbyConfigSchema.validate(config) |
| 69 | + expect(result).toEqual( |
| 70 | + expect.objectContaining({ |
| 71 | + pathPrefix: `/blog`, |
| 72 | + assetPrefix: `https://cdn.example.com`, |
| 73 | + }) |
| 74 | + ) |
| 75 | + }) |
| 76 | + |
| 77 | + it(`does not allow pathPrefix to be full URL`, async () => { |
| 78 | + expect.assertions(1) |
42 | 79 | const config = {
|
43 | 80 | pathPrefix: `https://google.com`,
|
44 | 81 | }
|
45 | 82 |
|
46 |
| - expect( |
47 |
| - gatsbyConfigSchema.validate(config) |
48 |
| - ).rejects.toThrowErrorMatchingSnapshot() |
| 83 | + try { |
| 84 | + await gatsbyConfigSchema.validate(config) |
| 85 | + } catch (err) { |
| 86 | + expect(err.message).toMatchSnapshot() |
| 87 | + } |
49 | 88 | })
|
50 | 89 |
|
51 |
| - it(`throws when relative path used for both assetPrefix and pathPrefix`, () => { |
| 90 | + it(`throws when relative path used for both assetPrefix and pathPrefix`, async () => { |
| 91 | + expect.assertions(1) |
52 | 92 | const config = {
|
53 | 93 | assetPrefix: `/assets`,
|
54 | 94 | pathPrefix: `/blog`,
|
55 | 95 | }
|
56 | 96 |
|
57 |
| - expect( |
58 |
| - gatsbyConfigSchema.validate(config) |
59 |
| - ).rejects.toThrowErrorMatchingSnapshot() |
| 97 | + try { |
| 98 | + await gatsbyConfigSchema.validate(config) |
| 99 | + } catch (err) { |
| 100 | + expect(err.message).toMatchSnapshot() |
| 101 | + } |
60 | 102 | })
|
61 | 103 | })
|
0 commit comments