-
Notifications
You must be signed in to change notification settings - Fork 67.2k
Expand file tree
/
Copy pathrobots-txt.ts
More file actions
48 lines (40 loc) · 1.58 KB
/
robots-txt.ts
File metadata and controls
48 lines (40 loc) · 1.58 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
import { describe, expect, test, vi } from 'vitest'
import {
SURROGATE_ENUMS,
makeLanguageSurrogateKey,
} from '@/frame/middleware/set-fastly-surrogate-key'
import { get } from '@/tests/helpers/e2etest'
// Type alias for the response from e2etest helper
type TestResponse = {
body: string
statusCode: number
headers: Record<string, string>
url: string
ok: boolean
}
describe('robots.txt', () => {
vi.setConfig({ testTimeout: 60 * 1000 })
test('returns disallow all for localhost (default behavior)', async () => {
const res: TestResponse = await get('/robots.txt')
expect(res.statusCode).toBe(200)
expect(res.body).toEqual('User-agent: *\nDisallow: /')
})
test('does not have duplicate lines', async () => {
const res: TestResponse = await get('/robots.txt')
expect(res.body.split('\n').length).toBe(new Set(res.body.split('\n')).size)
})
test('is cached by headers', async () => {
const res: TestResponse = await get('/robots.txt')
expect(res.headers['cache-control']).toMatch(/public, max-age=/)
const surrogateKeySplit = (res.headers['surrogate-key'] as string).split(/\s/g)
expect(surrogateKeySplit.includes(SURROGATE_ENUMS.DEFAULT)).toBeTruthy()
expect(surrogateKeySplit.includes(makeLanguageSurrogateKey('en'))).toBeTruthy()
})
test('validates robots.txt format', async () => {
const res: TestResponse = await get('/robots.txt')
// Should be valid robots.txt format
expect(res.body).toMatch(/^User-agent: \*/)
expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toMatch(/text\/plain/)
})
})