-
Notifications
You must be signed in to change notification settings - Fork 26k
/
resolve-route-data.test.ts
89 lines (81 loc) · 2.17 KB
/
resolve-route-data.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
import type { MetadataRoute } from '../../../../lib/metadata/types/metadata-interface'
import { resolveRobots, resolveSitemap } from './resolve-route-data'
describe('resolveRouteData', () => {
describe('resolveRobots', () => {
it('should resolve robots.txt', () => {
const data = {
host: 'https://example.com',
sitemap: 'https://example.com/sitemap.xml',
rules: [
{
userAgent: 'Googlebot',
allow: '/',
disallow: '/admin',
crawlDelay: 2,
},
],
}
const content = resolveRobots(data)
expect(content).toMatchInlineSnapshot(`
"User-Agent: Googlebot
Allow: /
Disallow: /admin
Crawl-delay: 2
Host: https://example.com
Sitemap: https://example.com/sitemap.xml
"
`)
})
it('should error with ts when specify both wildcard userAgent and specific userAgent', () => {
const data1: MetadataRoute.Robots = {
rules: [
// @ts-expect-error userAgent is required for Array<Robots>
{
allow: '/',
},
{
userAgent: 'Googlebot',
allow: '/bot',
},
],
}
const data2: MetadataRoute.Robots = {
rules: {
// Can skip userAgent for single Robots
allow: '/',
},
}
const data3: MetadataRoute.Robots = {
rules: { allow: '/' },
}
resolveRobots(data1)
resolveRobots(data2)
expect(resolveRobots(data3)).toMatchInlineSnapshot(`
"User-Agent: *
Allow: /
"
`)
})
})
describe('resolveSitemap', () => {
it('should resolve sitemap.xml', () => {
expect(
resolveSitemap([
{
url: 'https://example.com',
lastModified: '2021-01-01',
},
])
).toMatchInlineSnapshot(`
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\">
<url>
<loc>https://example.com</loc>
<lastmod>2021-01-01</lastmod>
</url>
</urlset>
"
`)
})
})
})