-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathblog-images.test.ts
More file actions
91 lines (78 loc) · 2.51 KB
/
Copy pathblog-images.test.ts
File metadata and controls
91 lines (78 loc) · 2.51 KB
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
import { describe, expect, it, vi } from 'vitest'
import {
BLOG_PLACEHOLDER_IMAGE,
getAbsoluteBlogSocialImage,
getBlogSocialImage,
getBlogThumbnailImage,
resolveBlogImagePath,
validateBlogFrontmatterImages,
} from './blog-images'
describe('blog image helpers', () => {
it('prefers imgThumb for on-site blog thumbnails', () => {
expect(
getBlogThumbnailImage({
imgThumb: 'example/thumb.png',
imgSocial: 'example/og.png',
})
).toBe('/images/blog/example/thumb.png')
})
it('falls back to imgSocial for on-site blog thumbnails', () => {
expect(
getBlogThumbnailImage({
imgSocial: 'example/og.png',
})
).toBe('/images/blog/example/og.png')
})
it('prefers imgSocial for social metadata', () => {
expect(
getBlogSocialImage({
imgThumb: 'example/thumb.png',
imgSocial: 'example/og.png',
})
).toBe('/images/blog/example/og.png')
})
it('returns absolute URLs unchanged and prefixes relative paths', () => {
expect(resolveBlogImagePath('https://example.com/og.png')).toBe('https://example.com/og.png')
expect(resolveBlogImagePath('/images/blog/example/og.png')).toBe('/images/blog/example/og.png')
expect(resolveBlogImagePath('example/og.png')).toBe('/images/blog/example/og.png')
})
it('builds absolute social image URLs', () => {
expect(
getAbsoluteBlogSocialImage(
{
imgSocial: 'example/og.png',
},
'https://supabase.com'
)
).toBe('https://supabase.com/images/blog/example/og.png')
})
it('uses the placeholder when neither image is present', () => {
expect(getBlogThumbnailImage({})).toBe(BLOG_PLACEHOLDER_IMAGE)
expect(getBlogThumbnailImage({}, { fallbackToPlaceholder: false })).toBeUndefined()
})
it('warns when blog frontmatter is missing one of the image fields', () => {
const warn = vi.fn()
validateBlogFrontmatterImages(
{
imgThumb: 'example/thumb.png',
},
'/tmp/example-post.mdx',
warn
)
expect(warn).toHaveBeenCalledWith(expect.stringContaining('missing "imgSocial"'))
})
it('warns when a blog image uses the prefixed public path', () => {
const warn = vi.fn()
validateBlogFrontmatterImages(
{
imgThumb: '/images/blog/example/thumb.png',
imgSocial: 'example/og.png',
},
'/tmp/example-prefixed-post.mdx',
warn
)
expect(warn).toHaveBeenCalledWith(
expect.stringContaining('should not include the "/images/blog/" prefix')
)
})
})