forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobots-txt.js
More file actions
52 lines (45 loc) · 1.81 KB
/
robots-txt.js
File metadata and controls
52 lines (45 loc) · 1.81 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
const languages = require('../../lib/languages')
const robotsParser = require('robots-parser')
const robotsMiddleware = require('../../middleware/robots')
const { get } = require('../helpers/supertest')
const MockExpressResponse = require('mock-express-response')
describe('robots.txt', () => {
jest.setTimeout(5 * 60 * 1000)
let res, robots
beforeAll(async (done) => {
res = await get('/robots.txt')
robots = robotsParser('https://docs.github.com/robots.txt', res.text)
done()
})
it('allows indexing of the homepage and English content', async () => {
expect(robots.isAllowed('https://docs.github.com/')).toBe(true)
expect(robots.isAllowed('https://docs.github.com/en')).toBe(true)
expect(robots.isAllowed('https://docs.github.com/en/articles/verifying-your-email-address')).toBe(true)
})
it('allows indexing of generally available localized content', async () => {
Object.values(languages)
.filter(language => !language.wip)
.forEach(language => {
expect(robots.isAllowed(`https://docs.github.com/${language.code}`)).toBe(true)
expect(robots.isAllowed(`https://docs.github.com/${language.code}/articles/verifying-your-email-address`)).toBe(true)
})
})
it('disallows indexing of herokuapp.com domains', async () => {
const req = {
hostname: 'docs-internal-12345--my-branch.herokuapp.com',
path: '/robots.txt'
}
const res = new MockExpressResponse()
const next = () => { /* no op */ }
await robotsMiddleware(req, res, next)
expect(res._getString()).toEqual('User-agent: *\nDisallow: /')
})
it('does not have duplicate lines', () => {
const lines = new Set()
for (const line of res.text.split('\n')) {
if (/^\s*$/.test(line)) continue
expect(lines.has(line)).toBe(false)
lines.add(line)
}
})
})