-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathutils.spec.ts
96 lines (82 loc) · 2.52 KB
/
utils.spec.ts
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
import Chance from 'chance'
import { ExperimentalConfig } from 'next/dist/server/config-shared'
import { getCustomImageResponseHeaders, getRemotePatterns, ImagesConfig } from '../../packages/runtime/src/helpers/utils'
const chance = new Chance()
describe('getCustomImageResponseHeaders', () => {
it('returns null when no custom image response headers are found', () => {
const mockHeaders = [{
for: '/test',
values: {
'X-Foo': chance.string()
}
}]
expect(getCustomImageResponseHeaders(mockHeaders)).toBe(null)
})
it('returns header values when custom image response headers are found', () => {
const mockFooValue = chance.string()
const mockHeaders = [{
for: '/_next/image/',
values: {
'X-Foo': mockFooValue
}
}]
const result = getCustomImageResponseHeaders(mockHeaders)
expect(result).toStrictEqual({
'X-Foo': mockFooValue,
})
})
})
describe('getRemotePatterns', () => {
let mockExperimentalConfig
let mockImages
beforeEach(() => {
mockExperimentalConfig = {
images: {}
} as ExperimentalConfig
mockImages = {
deviceSizes: [
640, 750, 828,
1080, 1200, 1920,
2048, 3840
],
imageSizes: [
16, 32, 48, 64,
96, 128, 256, 384
],
path: '/_next/image',
loader: 'default',
domains: [],
disableStaticImages: false,
minimumCacheTTL: 60,
formats: [ 'image/avif', 'image/webp' ],
dangerouslyAllowSVG: false,
contentSecurityPolicy: "script-src 'none'; frame-src 'none'; sandbox;",
unoptimized: false,
remotePatterns: []
} as ImagesConfig
})
it('returns the remote patterns found under experimental.images', () => {
mockExperimentalConfig.images.remotePatterns = [
{
protocol: 'https',
hostname: '*.githubusercontent.com',
},
]
const result = getRemotePatterns(mockExperimentalConfig, mockImages)
expect(result).toStrictEqual(mockExperimentalConfig.images?.remotePatterns)
})
it('returns the remote patterns found under images', () => {
mockImages.remotePatterns = [
{
protocol: 'https',
hostname: '*.githubusercontent.com',
},
]
const result = getRemotePatterns(mockExperimentalConfig, mockImages)
expect(result).toStrictEqual(mockImages.remotePatterns)
})
it('returns an empty array', () => {
const result = getRemotePatterns(mockExperimentalConfig, mockImages)
expect(result).toStrictEqual([])
})
})