Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

robots-txt.js 1.8 KB

You have to be logged in to leave a comment. Sign In
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
  1. const languages = require('../../lib/languages')
  2. const robotsParser = require('robots-parser')
  3. const robotsMiddleware = require('../../middleware/robots')
  4. const { get } = require('../helpers/supertest')
  5. const MockExpressResponse = require('mock-express-response')
  6. describe('robots.txt', () => {
  7. jest.setTimeout(5 * 60 * 1000)
  8. let res, robots
  9. beforeAll(async (done) => {
  10. res = await get('/robots.txt')
  11. robots = robotsParser('https://docs.github.com/robots.txt', res.text)
  12. done()
  13. })
  14. it('allows indexing of the homepage and English content', async () => {
  15. expect(robots.isAllowed('https://docs.github.com/')).toBe(true)
  16. expect(robots.isAllowed('https://docs.github.com/en')).toBe(true)
  17. expect(robots.isAllowed('https://docs.github.com/en/articles/verifying-your-email-address')).toBe(true)
  18. })
  19. it('allows indexing of generally available localized content', async () => {
  20. Object.values(languages)
  21. .filter(language => !language.wip)
  22. .forEach(language => {
  23. expect(robots.isAllowed(`https://docs.github.com/${language.code}`)).toBe(true)
  24. expect(robots.isAllowed(`https://docs.github.com/${language.code}/articles/verifying-your-email-address`)).toBe(true)
  25. })
  26. })
  27. it('disallows indexing of herokuapp.com domains', async () => {
  28. const req = {
  29. hostname: 'docs-internal-12345--my-branch.herokuapp.com',
  30. path: '/robots.txt'
  31. }
  32. const res = new MockExpressResponse()
  33. const next = () => { /* no op */ }
  34. await robotsMiddleware(req, res, next)
  35. expect(res._getString()).toEqual('User-agent: *\nDisallow: /')
  36. })
  37. it('does not have duplicate lines', () => {
  38. const lines = new Set()
  39. for (const line of res.text.split('\n')) {
  40. if (/^\s*$/.test(line)) continue
  41. expect(lines.has(line)).toBe(false)
  42. lines.add(line)
  43. }
  44. })
  45. })
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...