2020-09-27 15:10:11 +03:00
|
|
|
const languages = require('../../lib/languages')
|
|
|
|
const robotsParser = require('robots-parser')
|
|
|
|
const robotsMiddleware = require('../../middleware/robots')
|
2020-11-24 23:42:11 +03:00
|
|
|
const { get } = require('../helpers/supertest')
|
2020-09-27 15:10:11 +03:00
|
|
|
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')
|
2020-10-22 17:07:20 +03:00
|
|
|
robots = robotsParser('https://docs.github.com/robots.txt', res.text)
|
2020-09-27 15:10:11 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('allows indexing of the homepage and English content', async () => {
|
2020-10-22 17:07:20 +03:00
|
|
|
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)
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('allows indexing of generally available localized content', async () => {
|
|
|
|
Object.values(languages)
|
|
|
|
.filter(language => !language.wip)
|
|
|
|
.forEach(language => {
|
2020-10-22 17:07:20 +03:00
|
|
|
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)
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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: /')
|
|
|
|
})
|
|
|
|
|
2020-12-02 22:45:22 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|