2021-07-14 23:49:18 +03:00
|
|
|
import languages from '../../lib/languages.js'
|
|
|
|
import robotsParser from 'robots-parser'
|
2022-03-19 00:06:12 +03:00
|
|
|
import { get } from '../helpers/e2etest.js'
|
2021-07-14 23:49:18 +03:00
|
|
|
import { jest } from '@jest/globals'
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
describe('robots.txt', () => {
|
|
|
|
jest.setTimeout(5 * 60 * 1000)
|
|
|
|
|
|
|
|
let res, robots
|
2021-07-14 23:49:18 +03:00
|
|
|
beforeAll(async () => {
|
2022-03-19 00:06:12 +03:00
|
|
|
res = await get('/robots.txt', {
|
|
|
|
headers: {
|
|
|
|
Host: 'docs.github.com',
|
|
|
|
},
|
|
|
|
})
|
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
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
2021-07-15 00:35:01 +03:00
|
|
|
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)
|
2021-07-15 00:35:01 +03:00
|
|
|
.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)
|
2021-07-15 00:35:01 +03:00
|
|
|
expect(
|
|
|
|
robots.isAllowed(
|
|
|
|
`https://docs.github.com/${language.code}/articles/verifying-your-email-address`
|
|
|
|
)
|
|
|
|
).toBe(true)
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-02-11 02:36:07 +03:00
|
|
|
it('disallows indexing of azurecontainer.io domains', async () => {
|
2022-03-09 04:08:49 +03:00
|
|
|
const res = await get('/robots.txt', {
|
|
|
|
headers: {
|
|
|
|
host: 'docs-internal-preview-12345-asdfz.azurecontainer.io',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(res.text).toEqual('User-agent: *\nDisallow: /')
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
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
|
|
|
})
|