1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/tests/rendering/robots-txt.js
Mike Surowiec 624581e527 Remove most of Heroku references (#25208)
* remove most of heroku references

* remove more stuff

* update codeowners
2022-02-10 17:36:07 -06:00

61 lines
1.9 KiB
JavaScript

import languages from '../../lib/languages.js'
import robotsParser from 'robots-parser'
import robotsMiddleware from '../../middleware/robots.js'
import { get } from '../helpers/supertest.js'
import MockExpressResponse from 'mock-express-response'
import { jest } from '@jest/globals'
describe('robots.txt', () => {
jest.setTimeout(5 * 60 * 1000)
let res, robots
beforeAll(async () => {
res = await get('/robots.txt')
robots = robotsParser('https://docs.github.com/robots.txt', res.text)
})
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 azurecontainer.io domains', async () => {
const req = {
hostname: 'docs-internal-preview-12345-asdfz.azurecontainer.io',
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)
}
})
})