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

server.js 35 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
  1. const lodash = require('lodash')
  2. const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
  3. const { get, getDOM, head, post } = require('../helpers/supertest')
  4. const { describeViaActionsOnly } = require('../helpers/conditional-runs')
  5. const path = require('path')
  6. const { loadPages } = require('../../lib/pages')
  7. const builtAssets = require('../../lib/built-asset-urls')
  8. const AZURE_STORAGE_URL = 'githubdocs.azureedge.net'
  9. describe('server', () => {
  10. jest.setTimeout(60 * 1000)
  11. beforeAll(async () => {
  12. // The first page load takes a long time so let's get it out of the way in
  13. // advance to call out that problem specifically rather than misleadingly
  14. // attributing it to the first test
  15. await get('/en')
  16. })
  17. test('supports HEAD requests', async () => {
  18. const res = await head('/en')
  19. expect(res.statusCode).toBe(200)
  20. expect(res.headers).not.toHaveProperty('content-length')
  21. expect(res.text).toBeUndefined()
  22. })
  23. test('renders the homepage', async () => {
  24. const res = await get('/en')
  25. expect(res.statusCode).toBe(200)
  26. })
  27. test('uses gzip compression', async () => {
  28. const res = await get('/en')
  29. expect(res.headers['content-encoding']).toBe('gzip')
  30. expect(res.headers['transfer-encoding']).toBe('chunked')
  31. })
  32. test('sets Content Security Policy (CSP) headers', async () => {
  33. const res = await get('/en')
  34. expect('content-security-policy' in res.headers).toBe(true)
  35. expect('x-content-security-policy' in res.headers).toBe(true)
  36. expect('x-webkit-csp' in res.headers).toBe(true)
  37. const csp = new (require('csp-parse'))(res.headers['content-security-policy'])
  38. expect(csp.get('default-src')).toBe("'none'")
  39. expect(csp.get('font-src').includes("'self'")).toBe(true)
  40. expect(csp.get('font-src').includes(AZURE_STORAGE_URL)).toBe(true)
  41. expect(csp.get('connect-src').includes("'self'")).toBe(true)
  42. expect(csp.get('connect-src').includes('*.algolia.net')).toBe(true)
  43. expect(csp.get('connect-src').includes('*.algolianet.com')).toBe(true)
  44. expect(csp.get('img-src').includes("'self'")).toBe(true)
  45. expect(csp.get('img-src').includes(AZURE_STORAGE_URL)).toBe(true)
  46. expect(csp.get('script-src').includes("'self'")).toBe(true)
  47. expect(csp.get('style-src').includes("'self'")).toBe(true)
  48. expect(csp.get('style-src').includes("'unsafe-inline'")).toBe(true)
  49. })
  50. test('sets Fastly cache control headers to bypass pages', async () => {
  51. const res = await get('/en')
  52. expect(res.headers['cache-control']).toBe('private, no-store')
  53. expect(res.headers['surrogate-control']).toBe('private, no-store')
  54. expect(res.headers['surrogate-key']).toBe('all-the-things')
  55. })
  56. test('does not render duplicate <html> or <body> tags', async () => {
  57. const $ = await getDOM('/en')
  58. expect($('html').length).toBe(1)
  59. expect($('body').length).toBe(1)
  60. })
  61. test('sets `lang` attribute on <html> attribute', async () => {
  62. expect((await getDOM('/en'))('html').attr('lang')).toBe('en')
  63. expect((await getDOM('/en/articles/set-up-git'))('html').attr('lang')).toBe('en')
  64. expect((await getDOM('/ja'))('html').attr('lang')).toBe('ja')
  65. })
  66. test('renders a 404 page', async () => {
  67. const $ = await getDOM('/not-a-real-page')
  68. expect($('h1').text()).toBe('Ooops!')
  69. expect($.text().includes("It looks like this page doesn't exist.")).toBe(true)
  70. expect($.text().includes('Still need help?')).toBe(true)
  71. expect($.res.statusCode).toBe(404)
  72. })
  73. test('renders a 400 for invalid paths', async () => {
  74. const $ = await getDOM('/en/%7B%')
  75. expect($.res.statusCode).toBe(400)
  76. })
  77. // see issue 12427
  78. test('renders a 404 for leading slashes', async () => {
  79. let $ = await getDOM('//foo.com/enterprise')
  80. expect($('h1').text()).toBe('Ooops!')
  81. expect($.res.statusCode).toBe(404)
  82. $ = await getDOM('///foo.com/enterprise')
  83. expect($('h1').text()).toBe('Ooops!')
  84. expect($.res.statusCode).toBe(404)
  85. })
  86. test('renders a 500 page when errors are thrown', async () => {
  87. const $ = await getDOM('/_500')
  88. expect($('h1').text()).toBe('Ooops!')
  89. expect($('code').text().startsWith('Error: Intentional error')).toBe(true)
  90. expect($('code').text().includes(path.join('node_modules', 'express', 'lib', 'router'))).toBe(true)
  91. expect($.text().includes('Still need help?')).toBe(true)
  92. expect($.res.statusCode).toBe(500)
  93. })
  94. test('returns a 400 when POST-ed invalid JSON', async () => {
  95. const res = await post('/')
  96. .send('not real JSON')
  97. .set('Content-Type', 'application/json')
  98. expect(res.statusCode).toBe(400)
  99. })
  100. test('converts Markdown in intros', async () => {
  101. // example from markdown source in intro:
  102. // The `git rebase` command
  103. const $ = await getDOM('/en/articles/about-git-rebase')
  104. expect($.html()).toContain('The <code>git rebase</code> command')
  105. })
  106. test('injects site variables into rendered intros', async () => {
  107. // example from markdown source in intro:
  108. // You can follow people on {{ site.data.variables.product.product_name }}
  109. const $ = await getDOM('/en/github/getting-started-with-github/following-people')
  110. expect($.text()).toContain('You can follow people on GitHub')
  111. })
  112. test('injects site variables into rendered permissions statements frontmatter', async () => {
  113. // markdown source: {% data variables.product.prodname_pages %} site
  114. const $ = await getDOM('/en/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site')
  115. expect($('div.permissions-statement').text()).toContain('GitHub Pages site')
  116. })
  117. // see issue 9678
  118. test('does not use cached intros in map topics', async () => {
  119. let $ = await getDOM('/en/github/importing-your-projects-to-github/importing-a-git-repository-using-the-command-line')
  120. const articleIntro = $('.lead-mktg').text()
  121. $ = await getDOM('/en/enterprise/2.16/user/importing-your-projects-to-github/importing-source-code-to-github')
  122. const mapTopicIntro = $('.map-topic').first().next().text()
  123. expect(articleIntro).not.toEqual(mapTopicIntro)
  124. })
  125. test('injects site variables into rendered pages', async () => {
  126. // example from markdown source in page body:
  127. // {{ site.data.variables.product.product_name }} may recommend
  128. const $ = await getDOM('/en/github/getting-started-with-github/following-people')
  129. expect($.text()).toContain('GitHub may recommend')
  130. })
  131. test('serves /categories.json for support team usage', async () => {
  132. const res = await get('/categories.json')
  133. // check for CORS header
  134. expect(res.headers['access-control-allow-origin']).toBe('*')
  135. const categories = JSON.parse(res.text)
  136. expect(Array.isArray(categories)).toBe(true)
  137. expect(categories.length).toBeGreaterThan(1)
  138. categories.forEach(category => {
  139. expect('name' in category).toBe(true)
  140. expect('published_articles' in category).toBe(true)
  141. })
  142. })
  143. test('renders Markdown links that have Liquid hrefs', async () => {
  144. // example from markdown source:
  145. // 1. Go to {{ site.data.variables.product.product_name }}'s [Pricing]({{ site.data.variables.dotcom_billing.plans_url }}) page.
  146. const $ = await getDOM('/en/github/getting-started-with-github/signing-up-for-a-new-github-account')
  147. expect($.text()).toContain("Go to GitHub's Pricing page.")
  148. expect($('a[href="https://github.com/pricing"]').first().text()).toBe('Pricing')
  149. })
  150. test('renders liquid within liquid within liquid in body text', async () => {
  151. const $ = await getDOM('/en/github/administering-a-repository/enabling-required-status-checks')
  152. expect($('ol li').first().text().trim()).toBe('On GitHub, navigate to the main page of the repository.')
  153. })
  154. test('renders liquid within liquid within liquid in intros', async () => {
  155. const $ = await getDOM('/en/github/administering-a-repository/about-merge-methods-on-github')
  156. expect($('div.lead-mktg').first().text().includes('merge their pull requests on GitHub')).toBe(true)
  157. })
  158. test('renders product frontmatter callouts', async () => {
  159. const $ = await getDOM('/en/articles/about-branch-restrictions')
  160. const note = $('.product-callout').eq(0)
  161. expect(note.hasClass('color-border-info')).toBe(true)
  162. expect(note.hasClass('color-bg-info')).toBe(true)
  163. })
  164. test('renders liquid within liquid within product frontmatter callouts', async () => {
  165. const $ = await getDOM('/en/articles/about-branch-restrictions')
  166. const note = $('.product-callout').eq(0)
  167. expect(note.first().text().trim().startsWith('Protected branches are available in public repositories with GitHub Free')).toBe(true)
  168. })
  169. test('handles whitespace control in liquid tags', async () => {
  170. // example from markdown source of index:
  171. // Liquid tags with {%- in lists should not result in newlines
  172. // that convert to <p>s in <li>s
  173. const $ = await getDOM('/')
  174. expect($('li > p').length).toBe(0)
  175. })
  176. test('renders liquid within liquid within liquid', async () => {
  177. const $ = await getDOM('/en/articles/enabling-required-status-checks')
  178. expect($('ol li').first().text().trim()).toBe('On GitHub, navigate to the main page of the repository.')
  179. })
  180. test('preserves liquid statements with liquid raw tags in page output', async () => {
  181. const $ = await getDOM('/en/pages/setting-up-a-github-pages-site-with-jekyll/troubleshooting-jekyll-build-errors-for-github-pages-sites')
  182. expect($.text().includes('{{ page.title }}')).toBe(true)
  183. })
  184. test('displays links to categories on product TOCs', async () => {
  185. const $ = await getDOM('/en/github')
  186. expect($('article a[href="/en/github/getting-started-with-github"]')).toHaveLength(1)
  187. })
  188. describe('autogenerated mini TOCs', () => {
  189. // TODO disable the mini TOC tests when we replace it with sticky TOC header
  190. test('renders mini TOC in articles with more than one heading', async () => {
  191. const $ = await getDOM('/en/github/getting-started-with-github/githubs-products')
  192. expect($('h2#in-this-article').length).toBe(1)
  193. expect($('h2#in-this-article + ul li a').length).toBeGreaterThan(1)
  194. })
  195. test('renders mini TOC in articles that includes h4s when specified by frontmatter', async () => {
  196. const $ = await getDOM('/en/github/setting-up-and-managing-your-enterprise/enforcing-security-settings-in-your-enterprise-account')
  197. expect($('h2#in-this-article').length).toBe(1)
  198. expect($('h2#in-this-article + ul li.ml-0').length).toBeGreaterThan(0) // non-indented items
  199. expect($('h2#in-this-article + ul li.ml-3').length).toBeGreaterThan(0) // indented items
  200. })
  201. test('does not render mini TOC in articles with only one heading', async () => {
  202. const $ = await getDOM('/en/github/visualizing-repository-data-with-graphs/about-repository-graphs')
  203. expect($('h2#in-this-article').length).toBe(0)
  204. })
  205. test('does not render mini TOC in articles with no headings', async () => {
  206. const $ = await getDOM('/en/github/authenticating-to-github/reviewing-your-deploy-keys')
  207. expect($('h2#in-this-article').length).toBe(0)
  208. })
  209. test('does not render mini TOC in non-articles', async () => {
  210. const $ = await getDOM('/github/getting-started-with-github')
  211. expect($('h2#in-this-article').length).toBe(0)
  212. })
  213. })
  214. describe('image asset paths', () => {
  215. const localImageBasePath = '/assets/images'
  216. const legacyImageBasePath = '/assets/enterprise'
  217. const latestEnterprisePath = `/en/enterprise/${enterpriseServerReleases.latest}`
  218. const oldestEnterprisePath = `/en/enterprise/${enterpriseServerReleases.oldestSupported}`
  219. test('github articles on dotcom have images that point to local assets dir', async () => {
  220. const $ = await getDOM('/en/github/authenticating-to-github/configuring-two-factor-authentication')
  221. expect($('img').first().attr('src').startsWith(localImageBasePath)).toBe(true)
  222. })
  223. test('github articles on GHE have images that point to local assets dir', async () => {
  224. const $ = await getDOM(`${latestEnterprisePath}/user/github/authenticating-to-github/configuring-two-factor-authentication`)
  225. const imageSrc = $('img').first().attr('src')
  226. expect(imageSrc.startsWith(localImageBasePath) || imageSrc.startsWith(legacyImageBasePath)).toBe(true)
  227. })
  228. test('admin articles on latest version of GHE have images that point to local assets dir', async () => {
  229. const $ = await getDOM(`${latestEnterprisePath}/admin/user-management/using-built-in-authentication`)
  230. const imageSrc = $('img').first().attr('src')
  231. expect(imageSrc.startsWith(localImageBasePath) || imageSrc.startsWith(legacyImageBasePath)).toBe(true)
  232. })
  233. test('admin articles on older GHE versions have images that point to local assets dir', async () => {
  234. const $ = await getDOM(`${oldestEnterprisePath}/admin/user-management/using-built-in-authentication`)
  235. const imageSrc = $('img').first().attr('src')
  236. expect(imageSrc.startsWith(localImageBasePath) || imageSrc.startsWith(legacyImageBasePath)).toBe(true)
  237. })
  238. test('links that point to /assets are not rewritten with a language code', async () => {
  239. const $ = await getDOM('/en/github/site-policy/github-privacy-statement')
  240. expect($('#french').next().children('a').attr('href').startsWith(localImageBasePath)).toBe(true)
  241. })
  242. test('github articles on GHAE have images that point to local assets dir', async () => {
  243. const $ = await getDOM('/en/github-ae@latest/github/administering-a-repository/changing-the-default-branch')
  244. const imageSrc = $('img').first().attr('src')
  245. expect(imageSrc.startsWith(localImageBasePath) || imageSrc.startsWith(legacyImageBasePath)).toBe(true)
  246. })
  247. test('admin articles on GHAE have images that point to local assets dir', async () => {
  248. const $ = await getDOM('/en/github-ae@latest/admin/user-management/managing-dormant-users')
  249. expect($('img').first().attr('src').startsWith(localImageBasePath)).toBe(true)
  250. })
  251. })
  252. describe('English local links', () => {
  253. const latestEnterprisePath = `/en/enterprise-server@${enterpriseServerReleases.latest}`
  254. test('dotcom articles on dotcom have links that include "en"', async () => {
  255. const $ = await getDOM('/en/articles/set-up-git')
  256. expect($('a[href="/en/articles/managing-files-on-github"]').length).toBe(1)
  257. })
  258. test('dotcom articles on dotcom have Enterprise Admin links with latest GHE version', async () => {
  259. const $ = await getDOM('/en/articles/setting-up-a-trial-of-github-enterprise-server')
  260. expect($(`a[href="${latestEnterprisePath}/admin/installation/setting-up-a-github-enterprise-server-instance"]`).length).toBe(2)
  261. })
  262. test('dotcom articles on GHE have Enterprise user links', async () => {
  263. const $ = await getDOM(`${latestEnterprisePath}/github/getting-started-with-github/set-up-git`)
  264. expect($(`a[href="${latestEnterprisePath}/articles/managing-files-on-github"]`).length).toBe(1)
  265. })
  266. test('dotcom categories on GHE have Enterprise user links', async () => {
  267. const $ = await getDOM(`${latestEnterprisePath}/github/managing-large-files`)
  268. expect($(`article a[href="${latestEnterprisePath}/github/managing-large-files/conditions-for-large-files"]`).length).toBe(1)
  269. })
  270. test('dotcom-only links on GHE are dotcom-only', async () => {
  271. const $ = await getDOM(`${latestEnterprisePath}/github/setting-up-and-managing-your-github-profile/sending-your-github-enterprise-server-contributions-to-your-githubcom-profile`)
  272. expect($('article a[href="/en/articles/github-privacy-statement"]').length).toBe(1)
  273. })
  274. test('desktop links on GHE are dotcom-only', async () => {
  275. const $ = await getDOM(`${latestEnterprisePath}/github/getting-started-with-github/set-up-git`)
  276. expect($('article a[href="/en/desktop/installing-and-configuring-github-desktop"]').length).toBe(1)
  277. })
  278. test('admin articles that link to non-admin articles have Enterprise user links', async () => {
  279. const $ = await getDOM(`${latestEnterprisePath}/admin/installation/configuring-the-default-visibility-of-new-repositories-on-your-appliance`)
  280. expect($(`article a[href="${latestEnterprisePath}/github/creating-cloning-and-archiving-repositories/about-repository-visibility"]`).length).toBeGreaterThan(0)
  281. })
  282. test('admin articles that link to Enterprise user articles have Enterprise user links', async () => {
  283. const $ = await getDOM(`${latestEnterprisePath}/admin/user-management/customizing-user-messages-for-your-enterprise`)
  284. expect($('article a[href*="about-writing-and-formatting-on-github"]').length).toBe(1)
  285. })
  286. test('articles that link to external links that contain /articles/ are not rewritten', async () => {
  287. const $ = await getDOM(`${latestEnterprisePath}/admin/installation/upgrading-github-enterprise-server`)
  288. expect($('article a[href="https://docs.microsoft.com/azure/backup/backup-azure-vms-first-look-arm"]').length).toBe(1)
  289. })
  290. })
  291. describe('article versions', () => {
  292. test('includes links to all versions of each article', async () => {
  293. const articlePath = 'github/setting-up-and-managing-your-github-user-account/about-your-personal-dashboard'
  294. const $ = await getDOM(`/en/enterprise-server@${enterpriseServerReleases.latest}/${articlePath}`)
  295. expect($(`.article-versions a.active[href="/en/enterprise-server@${enterpriseServerReleases.latest}/${articlePath}"]`).length).toBe(2)
  296. expect($(`.article-versions a.active[href="/en/${articlePath}"]`).length).toBe(0)
  297. // 2.13 predates this feature, so it should be excluded:
  298. expect($(`.article-versions a[href="/en/enterprise/2.13/user/${articlePath}"]`).length).toBe(0)
  299. })
  300. test('is not displayed if article has only one version', async () => {
  301. const $ = await getDOM('/en/articles/signing-up-for-a-new-github-account')
  302. expect($('.article-versions').length).toBe(0)
  303. })
  304. })
  305. describeViaActionsOnly('Early Access articles', () => {
  306. let hiddenPageHrefs, hiddenPages
  307. beforeAll(async (done) => {
  308. const $ = await getDOM('/early-access')
  309. hiddenPageHrefs = $('#article-contents ul > li > a').map((i, el) => $(el).attr('href')).get()
  310. const allPages = await loadPages()
  311. hiddenPages = allPages.filter(page => page.languageCode === 'en' && page.hidden)
  312. done()
  313. })
  314. test('exist in the set of English pages', async () => {
  315. expect(hiddenPages.length).toBeGreaterThan(0)
  316. })
  317. test('are listed at /early-access', async () => {
  318. expect(hiddenPageHrefs.length).toBeGreaterThan(0)
  319. })
  320. test('are not listed at /early-access in production', async () => {
  321. const oldNodeEnv = process.env.NODE_ENV
  322. process.env.NODE_ENV = 'production'
  323. const res = await get('/early-access', { followRedirects: true })
  324. process.env.NODE_ENV = oldNodeEnv
  325. expect(res.statusCode).toBe(404)
  326. })
  327. test('have noindex meta tags', async () => {
  328. const $ = await getDOM(hiddenPageHrefs[0])
  329. expect($('meta[content="noindex"]').length).toBe(1)
  330. })
  331. test('public articles do not have noindex meta tags', async () => {
  332. const $ = await getDOM('/en/articles/set-up-git')
  333. expect($('meta[content="noindex"]').length).toBe(0)
  334. })
  335. })
  336. describe('redirects', () => {
  337. test('redirects old articles to their English URL', async () => {
  338. const res = await get('/articles/deleting-a-team')
  339. expect(res.statusCode).toBe(301)
  340. })
  341. test('redirects old articles to their slugified URL', async () => {
  342. const res = await get('/articles/about-github-s-ip-addresses')
  343. expect(res.text).toBe('Moved Permanently. Redirecting to /en/github/authenticating-to-github/about-githubs-ip-addresses')
  344. })
  345. test('redirects / to /en', async () => {
  346. const res = await get('/')
  347. expect(res.statusCode).toBe(301)
  348. expect(res.headers.location).toBe('/en')
  349. })
  350. test('adds English prefix to old article URLs', async () => {
  351. const res = await get('/articles/deleting-a-team')
  352. expect(res.statusCode).toBe(301)
  353. expect(res.headers.location.startsWith('/en/')).toBe(true)
  354. })
  355. test('redirects Desktop Classic paths to desktop.github.com', async () => {
  356. const res = await get('/desktop-classic')
  357. expect(res.statusCode).toBe(301)
  358. expect(res.headers.location).toBe('https://desktop.github.com')
  359. })
  360. test('redirects /insights/foo paths to /enterprise/user/insights/foo', async () => {
  361. const res = await get('/en/insights/installing-and-configuring-github-insights/about-github-insights')
  362. expect(res.statusCode).toBe(301)
  363. expect(res.headers.location).toBe(`/en/enterprise-server@${enterpriseServerReleases.latest}/insights/installing-and-configuring-github-insights/about-github-insights`)
  364. })
  365. // this oneoff redirect is temporarily disabled because it introduces too much complexity
  366. // we can reenable it down the road if needed
  367. test.skip('redirects versioned category page', async () => {
  368. const res = await get('/en/github/receiving-notifications-about-activity-on-github')
  369. expect(res.statusCode).toBe(301)
  370. expect(res.headers.location).toBe('/en/github/managing-subscriptions-and-notifications-on-github')
  371. })
  372. })
  373. describe('categories and map topics', () => {
  374. test('adds links to categories on the dotcom homepage', async () => {
  375. const $ = await getDOM('/en/github')
  376. expect($('article a[href="/en/github/managing-large-files"]').length).toBe(1)
  377. expect($('article a[href="#managing-large-files"]').length).toBe(0)
  378. })
  379. test('adds links to map topics on a category homepage', async () => {
  380. const $ = await getDOM('/en/github/setting-up-and-managing-your-github-user-account')
  381. expect($('article a[href="/en/github/setting-up-and-managing-your-github-user-account/managing-user-account-settings"]').length).toBe(1)
  382. expect($('article a[href="#managing-user-account-settings"]').length).toBe(0)
  383. })
  384. test('category page renders with TOC', async () => {
  385. const $ = await getDOM('/en/github/managing-large-files')
  386. expect($('.markdown-body ul li a').length).toBeGreaterThan(5)
  387. })
  388. test('map topic renders with h2 links to articles', async () => {
  389. const $ = await getDOM('/en/github/setting-up-and-managing-your-github-user-account/managing-user-account-settings')
  390. expect($('a[href="/en/github/setting-up-and-managing-your-github-user-account/changing-your-github-username"] h2').length).toBe(1)
  391. })
  392. test('map topic renders with one intro for every h2', async () => {
  393. const $ = await getDOM('/en/github/setting-up-and-managing-your-github-user-account/managing-user-account-settings')
  394. const $h2s = $('article a.link-with-intro')
  395. expect($h2s.length).toBeGreaterThan(3)
  396. $h2s.each((i, el) => {
  397. expect($(el).next()[0].name).toBe('p')
  398. })
  399. })
  400. test('map topic intros are parsed', async () => {
  401. const $ = await getDOM('/en/github/setting-up-and-managing-your-github-user-account/managing-user-account-settings')
  402. const $intro = $('a.link-with-intro[href*="what-does-the-available-for-hire-checkbox-do"] + p')
  403. expect($intro.length).toBe(1)
  404. expect($intro.html()).toContain('Use the <strong>Available for hire</strong>')
  405. })
  406. })
  407. })
  408. describe('URLs by language', () => {
  409. // TODO re-enable this test once TOCs are auto-generated (after PR 11731 has landed)
  410. test('heading IDs and links on translated pages are in English', async () => {
  411. const $ = await getDOM('/ja/github/getting-started-with-github/verifying-your-email-address')
  412. expect($.res.statusCode).toBe(200)
  413. expect($('h3[id="further-reading"]').length).toBe(1)
  414. expect($('h3[id="参考リンク"]').length).toBe(0)
  415. expect($('h3 a[href="#further-reading"]').length).toBe(1)
  416. })
  417. })
  418. describe('GitHub Enterprise URLs', () => {
  419. test('renders the GHE user docs homepage', async () => {
  420. const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}/user/github`)
  421. expect($(`article a[href="/en/enterprise-server@${enterpriseServerReleases.latest}/github/getting-started-with-github"]`).length).toBe(1)
  422. })
  423. test('renders the Enterprise Server homepage with correct links', async () => {
  424. const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}`)
  425. expect($(`section.container-xl a[href="/en/enterprise-server@${enterpriseServerReleases.latest}/admin"]`).length).toBe(1)
  426. expect($(`section.container-xl a[href="/en/enterprise-server@${enterpriseServerReleases.latest}/github"]`).length).toBe(1)
  427. })
  428. test('renders the Enterprise Admin category homepage', async () => {
  429. const adminPath = `/en/enterprise-server@${enterpriseServerReleases.latest}/admin`
  430. const $ = await getDOM(adminPath)
  431. expect($(`article a[href="${adminPath}/installation"]`).length).toBe(1)
  432. expect($.text()).toContain('This guide describes')
  433. })
  434. test('renders an Enterprise Admin category with correct links', async () => {
  435. const installationCategoryHome = `/en/enterprise-server@${enterpriseServerReleases.latest}/admin/installation`
  436. const $ = await getDOM(installationCategoryHome)
  437. expect($(`article a[href^="${installationCategoryHome}/"]`).length).toBeGreaterThan(1)
  438. })
  439. test('renders a translated Enterprise Admin category with English links', async () => {
  440. const installationCategoryHome = `/ja/enterprise-server@${enterpriseServerReleases.latest}/admin/installation`
  441. const $ = await getDOM(installationCategoryHome)
  442. expect($(`article a[href^="${installationCategoryHome}/"]`).length).toBeGreaterThan(1)
  443. })
  444. test('renders an Enterprise Admin category article', async () => {
  445. const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}/admin/installation/system-overview`)
  446. expect($.text()).toContain('your organization\'s private copy of GitHub')
  447. })
  448. test('renders an Enterprise Admin map topic', async () => {
  449. const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}/admin/enterprise-management/updating-the-virtual-machine-and-physical-resources`)
  450. expect($(`article a[href^="/en/enterprise-server@${enterpriseServerReleases.latest}/admin/enterprise-management/"]`).length).toBeGreaterThan(1)
  451. })
  452. test('renders an Enterprise Admin category article within a map topic', async () => {
  453. const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}/admin/installation/upgrade-requirements`)
  454. expect($.text()).toContain('Before upgrading GitHub Enterprise')
  455. })
  456. test('renders Enterprise homepage in Japanese', async () => {
  457. const res = await get(`/ja/enterprise-server@${enterpriseServerReleases.latest}`)
  458. expect(res.statusCode).toBe(200)
  459. })
  460. test('renders Enterprise User homepage in Japanese', async () => {
  461. const res = await get(`/ja/enterprise-server@${enterpriseServerReleases.latest}/github`)
  462. expect(res.statusCode).toBe(200)
  463. })
  464. test('renders Enterprise Admin homepage in Japanese', async () => {
  465. const res = await get(`/ja/enterprise-server@${enterpriseServerReleases.latest}/admin`)
  466. expect(res.statusCode).toBe(200)
  467. })
  468. test('renders Enterprise homepage in Chinese', async () => {
  469. const res = await get(`/cn/enterprise-server@${enterpriseServerReleases.latest}`)
  470. expect(res.statusCode).toBe(200)
  471. })
  472. test('renders Enterprise User homepage in Chinese', async () => {
  473. const res = await get(`/cn/enterprise-server@${enterpriseServerReleases.latest}/github`)
  474. expect(res.statusCode).toBe(200)
  475. })
  476. test('renders Enterprise Admin homepage in Chinese', async () => {
  477. const res = await get(`/cn/enterprise-server@${enterpriseServerReleases.latest}/admin`)
  478. expect(res.statusCode).toBe(200)
  479. })
  480. })
  481. describe('GitHub Desktop URLs', () => {
  482. test('renders the GitHub Desktop homepage with correct links', async () => {
  483. const $ = await getDOM('/en/desktop')
  484. expect($('article a[href^="/en/desktop/"]').length).toBeGreaterThan(1)
  485. })
  486. test('renders a Desktop category with expected links', async () => {
  487. const $ = await getDOM('/en/desktop/installing-and-configuring-github-desktop')
  488. expect($('article a[href^="/en/desktop/installing-and-configuring-github-desktop/"]').length).toBeGreaterThan(1)
  489. })
  490. test('renders a Desktop map topic', async () => {
  491. const $ = await getDOM('/en/desktop/installing-and-configuring-github-desktop/installing-and-authenticating-to-github-desktop')
  492. expect($('article a[href^="/en/desktop/installing-and-configuring-github-desktop/"]').length).toBeGreaterThan(1)
  493. })
  494. test('renders a Desktop article within a map topic', async () => {
  495. const res = await get('/en/desktop/installing-and-configuring-github-desktop/installing-github-desktop')
  496. expect(res.statusCode).toBe(200)
  497. })
  498. test('renders the Desktop homepage in Japanese', async () => {
  499. const res = await get('/ja/desktop')
  500. expect(res.statusCode).toBe(200)
  501. })
  502. })
  503. describe('static assets', () => {
  504. test('fonts', async () => {
  505. expect((await get('/dist/fonts/Inter-Medium.woff')).statusCode).toBe(200)
  506. expect((await get('/dist/fonts/Inter-Regular.woff')).statusCode).toBe(200)
  507. })
  508. })
  509. describe('extended Markdown', () => {
  510. test('renders styled warnings', async () => {
  511. const $ = await getDOM('/en/articles/removing-a-remote')
  512. const warning = $('div.extended-markdown.warning')
  513. expect(warning.length).toBe(1)
  514. expect(warning.text().includes('does not delete the remote')).toBe(true)
  515. })
  516. test('renders styled tips (multiple per page)', async () => {
  517. const $ = await getDOM('/en/articles/authorizing-oauth-apps')
  518. const tips = $('div.extended-markdown.tip')
  519. expect(tips.length).toBe(3)
  520. expect(tips.eq(0).text().includes('verify your email address')).toBe(true)
  521. })
  522. test('renders styled notes within liquid', async () => {
  523. const $ = await getDOM('/en/articles/removing-a-member-from-your-organization')
  524. const note = $('.extended-markdown.note').eq(0)
  525. expect(note.hasClass('color-border-info')).toBe(true)
  526. expect(note.hasClass('color-bg-info')).toBe(true)
  527. })
  528. test('renders platform-specific content', async () => {
  529. const $ = await getDOM('/en/github/using-git/associating-text-editors-with-git')
  530. expect($('.extended-markdown.mac h3#using-textmate-as-your-editor').length).toBe(1)
  531. expect($('.extended-markdown.windows h3#using-notepad-as-your-editor').length).toBe(1)
  532. expect($('.extended-markdown.linux h3#using-textmate-as-your-editor').length).toBe(0)
  533. expect($('.extended-markdown.linux h3#using-notepad-as-your-editor').length).toBe(0)
  534. })
  535. test('renders expected mini TOC headings in platform-specific content', async () => {
  536. const $ = await getDOM('/en/github/using-git/associating-text-editors-with-git')
  537. expect($('h2#in-this-article').length).toBe(1)
  538. expect($('h2#in-this-article + ul li.extended-markdown.mac').length).toBeGreaterThan(1)
  539. expect($('h2#in-this-article + ul li.extended-markdown.windows').length).toBeGreaterThan(1)
  540. expect($('h2#in-this-article + ul li.extended-markdown.linux').length).toBeGreaterThan(1)
  541. })
  542. })
  543. describe('search', () => {
  544. function findDupesInArray (arr) {
  545. return lodash.filter(arr, (val, i, iteratee) => lodash.includes(iteratee, val, i + 1))
  546. }
  547. it('homepage does not render any elements with duplicate IDs', async () => {
  548. const $ = await getDOM('/en')
  549. const ids = $('body')
  550. .find('[id]')
  551. .map((i, el) => $(el).attr('id'))
  552. .get()
  553. .sort()
  554. const dupes = findDupesInArray(ids)
  555. const message = `Oops found duplicate DOM id(s): ${dupes.join(', ')}`
  556. expect(ids.length).toBeGreaterThan(0)
  557. expect(dupes.length === 0, message).toBe(true)
  558. })
  559. it('articles pages do not render any elements with duplicate IDs', async () => {
  560. const $ = await getDOM('/en/articles/accessing-an-organization')
  561. const ids = $('body')
  562. .find('[id]')
  563. .map((i, el) => $(el).attr('id'))
  564. .get()
  565. .sort()
  566. const dupes = findDupesInArray(ids)
  567. const message = `Oops found duplicate DOM id(s): ${dupes.join(', ')}`
  568. expect(ids.length).toBeGreaterThan(0)
  569. expect(dupes.length === 0, message).toBe(true)
  570. })
  571. })
  572. describe('?json query param for context debugging', () => {
  573. it('uses query param value as a key', async () => {
  574. const res = await get('/en?json=page')
  575. const page = JSON.parse(res.text)
  576. expect(typeof page.title).toBe('string')
  577. })
  578. it('returns a helpful message with top-level keys if query param has no value', async () => {
  579. const res = await get('/en?json')
  580. const context = JSON.parse(res.text)
  581. expect(context.message.includes('context object is too big to display')).toBe(true)
  582. expect(Array.isArray(context.keys)).toBe(true)
  583. expect(context.keys.includes('page')).toBe(true)
  584. expect(context.keys.includes('pages')).toBe(true)
  585. expect(context.keys.includes('redirects')).toBe(true)
  586. })
  587. })
  588. describe('stylesheets', () => {
  589. it('compiles and sets the right content-type header', async () => {
  590. const stylesheetUrl = builtAssets.main.css
  591. const res = await get(stylesheetUrl)
  592. expect(res.statusCode).toBe(200)
  593. expect(res.headers['content-type']).toBe('text/css; charset=UTF-8')
  594. })
  595. })
  596. describe('client-side JavaScript bundle', () => {
  597. let res
  598. beforeAll(async (done) => {
  599. const scriptUrl = builtAssets.main.js
  600. res = await get(scriptUrl)
  601. done()
  602. })
  603. it('returns a 200 response', async () => {
  604. expect(res.statusCode).toBe(200)
  605. })
  606. it('sets the right content-type header', async () => {
  607. expect(res.headers['content-type']).toBe('application/javascript; charset=UTF-8')
  608. })
  609. // TODO: configure webpack to create production bundle in the test env
  610. // it('is not too big', async () => {
  611. // const tooBig = 10 * 1000
  612. // expect(res.text.length).toBeLessThan(tooBig)
  613. // })
  614. })
  615. describe('static routes', () => {
  616. it('serves content from the /assets directory', async () => {
  617. expect((await get('/assets/images/site/be-social.gif')).statusCode).toBe(200)
  618. })
  619. it('serves schema files from the /data/graphql directory at /public', async () => {
  620. expect((await get('/public/schema.docs.graphql')).statusCode).toBe(200)
  621. expect((await get(`/public/ghes-${enterpriseServerReleases.latest}/schema.docs-enterprise.graphql`)).statusCode).toBe(200)
  622. expect((await get(`/public/ghes-${enterpriseServerReleases.oldestSupported}/schema.docs-enterprise.graphql`)).statusCode).toBe(200)
  623. expect((await get('/public/ghae/schema.docs-ghae.graphql')).statusCode).toBe(200)
  624. })
  625. it('does not serve repo contents that live outside the /assets directory', async () => {
  626. expect((await get('/package.json', { followRedirects: true })).statusCode).toBe(404)
  627. expect((await get('/README.md', { followRedirects: true })).statusCode).toBe(404)
  628. expect((await get('/server.js', { followRedirects: true })).statusCode).toBe(404)
  629. })
  630. })
  631. describe('index pages', () => {
  632. const nonEnterpriseOnlyPath = '/en/github/setting-up-and-managing-your-github-user-account/managing-user-account-settings'
  633. test('includes dotcom-only links in dotcom TOC', async () => {
  634. const $ = await getDOM('/en/github/setting-up-and-managing-your-github-user-account')
  635. expect($(`article a[href="${nonEnterpriseOnlyPath}"]`).length).toBe(1)
  636. })
  637. test('excludes dotcom-only from GHE TOC', async () => {
  638. const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}/user/github/setting-up-and-managing-your-github-user-account`)
  639. expect($(`a[href="${nonEnterpriseOnlyPath}"]`).length).toBe(0)
  640. })
  641. test('includes correctly versioned links in GHE', async () => {
  642. const installationLatest = `/en/enterprise-server@${enterpriseServerReleases.latest}/admin/installation`
  643. const $ = await getDOM(installationLatest)
  644. expect($(`article a[href^="${installationLatest}/"]`).length).toBeGreaterThan(0)
  645. })
  646. })
Tip!

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

Comments

Loading...