-
Notifications
You must be signed in to change notification settings - Fork 253
/
providers.test.ts
189 lines (164 loc) · 5.62 KB
/
providers.test.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { images } from '../providers'
import { cleanDoubleSlashes } from '~/runtime/utils'
import * as ipx from '~/runtime/providers/ipx'
import * as cloudinary from '~/runtime/providers/cloudinary'
import * as twicpics from '~/runtime/providers/twicpics'
import * as fastly from '~/runtime/providers/fastly'
import * as glide from '~/runtime/providers/glide'
import * as imgix from '~/runtime/providers/imgix'
import * as imagekit from '~/runtime/providers/imagekit'
import * as netlify from '~/runtime/providers/netlify'
import * as prismic from '~/runtime/providers/prismic'
import * as sanity from '~/runtime/providers/sanity'
const emptyContext = { options: {} } as any
describe('Providers', () => {
test('ipx', () => {
const providerOptions = {}
for (const image of images) {
const [src, modifiers] = image.args
const generated = ipx.getImage(src, { modifiers: { ...modifiers }, ...providerOptions }, emptyContext)
generated.url = cleanDoubleSlashes(generated.url)
expect(generated).toMatchObject(image.ipx)
}
})
test('ipx router base', () => {
const context = { ...emptyContext, nuxtContext: { base: '/app/' } }
const src = '/images/test.png'
const generated = ipx.getImage(src, { modifiers: {} }, context)
generated.url = cleanDoubleSlashes(generated.url)
expect(generated).toMatchObject({
url: '/app/_ipx/images/test.png'
})
})
test('cloudinary', () => {
const providerOptions = {
baseURL: '/'
}
for (const image of images) {
const [src, modifiers] = image.args
const generated = cloudinary.getImage(src, { modifiers, ...providerOptions }, emptyContext)
expect(generated).toMatchObject(image.cloudinary)
}
})
test('cloudinary fetch', () => {
const providerOptions = {
baseURL: 'https://res.cloudinary.com/demo/image/fetch/'
}
// see: https://cloudinary.com/documentation/fetch_remote_images#remote_image_fetch_url
const remoteUrl = 'https://upload.wikimedia.org/wikipedia/commons/1/13/Benedict_Cumberbatch_2011.png'
const generated = cloudinary.getImage(
remoteUrl,
{
modifiers: {
width: 300,
height: 300
},
...providerOptions
}, emptyContext
)
expect(generated).toMatchObject({
url: `https://res.cloudinary.com/demo/image/fetch/f_auto,q_auto,w_300,h_300/${remoteUrl}`
})
})
test('cloudinary upload', () => {
const providerOptions = {
baseURL: 'https://res.cloudinary.com/demo/image/upload/remote'
}
const generated = cloudinary.getImage(
'/1/13/Benedict_Cumberbatch_2011.png',
{
modifiers: {
width: 300,
height: 300
},
...providerOptions
}, emptyContext
)
expect(generated).toMatchObject({
url: 'https://res.cloudinary.com/demo/image/upload/f_auto,q_auto,w_300,h_300/remote/1/13/Benedict_Cumberbatch_2011.png'
})
})
test('twicpics', () => {
const providerOptions = {
baseURL: ''
}
for (const image of images) {
const [src, modifiers] = image.args
const generated = twicpics.getImage(src, { modifiers, ...providerOptions }, emptyContext)
expect(generated).toMatchObject(image.twicpics)
}
})
test('glide', () => {
const providerOptions = {
baseURL: ''
}
for (const image of images) {
const [src, modifiers] = image.args
const generated = glide.getImage(src, { modifiers, ...providerOptions }, emptyContext)
expect(generated).toMatchObject(image.glide)
}
})
test('fastly', () => {
const providerOptions = {
baseURL: ''
}
for (const image of images) {
const [src, modifiers] = image.args
const generated = fastly.getImage(src, { modifiers, ...providerOptions }, emptyContext)
expect(generated).toMatchObject(image.fastly)
}
})
test('imgix', () => {
const providerOptions = {
baseURL: ''
}
for (const image of images) {
const [src, modifiers] = image.args
const generated = imgix.getImage(src, { modifiers, ...providerOptions }, emptyContext)
expect(generated).toMatchObject(image.imgix)
}
})
test('imagekit', () => {
const providerOptions = {
baseURL: ''
}
for (const image of images) {
const [src, modifiers] = image.args
const generated = imagekit.getImage(src, { modifiers, ...providerOptions }, emptyContext)
expect(generated).toMatchObject(image.imagekit)
}
})
test('netlify', () => {
const providerOptions = {
baseURL: ''
}
for (const image of images) {
const [src, modifiers] = image.args
const generated = netlify.getImage(src, { modifiers: { ...modifiers }, ...providerOptions }, emptyContext)
expect(generated).toMatchObject(image.netlify)
}
})
test('prismic', () => {
const providerOptions = {
baseURL: '' // Use empty base URL for the sake of simplicity
}
const EXISTING_QUERY_PARAMETERS =
'?auto=compress,format&rect=0,0,200,200&w=100&h=100'
for (const image of images) {
const [src, modifiers] = image.args
const generated = prismic.getImage(`${src}${EXISTING_QUERY_PARAMETERS}`, { modifiers, ...providerOptions }, emptyContext)
expect(generated).toMatchObject(image.prismic)
}
})
test('sanity', () => {
const providerOptions = {
baseURL: '',
projectId: 'projectid'
}
for (const image of images) {
const [, modifiers] = image.args
const generated = sanity.getImage('image-test-300x450-png', { modifiers: { ...modifiers }, ...providerOptions }, emptyContext)
expect(generated).toMatchObject(image.sanity)
}
})
})