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

site-data.js 4.0 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
  1. const fs = require('fs')
  2. const path = require('path')
  3. const { get, isPlainObject, has } = require('lodash')
  4. const flat = require('flat')
  5. const loadSiteData = require('../../lib/site-data')
  6. const patterns = require('../../lib/patterns')
  7. const { liquid } = require('../../lib/render-content')
  8. describe('siteData module (English)', () => {
  9. let data
  10. beforeAll(async (done) => {
  11. data = await loadSiteData()
  12. done()
  13. })
  14. test('exports an object', async () => {
  15. expect(isPlainObject(data)).toBe(true)
  16. })
  17. test('sets a top-level key for each language', async () => {
  18. expect('en' in data).toEqual(true)
  19. expect('ja' in data).toEqual(true)
  20. })
  21. test('includes English variables', async () => {
  22. const prodName = get(data, 'en.site.data.variables.product.prodname_dotcom')
  23. expect(prodName).toBe('GitHub')
  24. })
  25. test('includes English reusables', async () => {
  26. const reusable = get(data, 'en.site.data.reusables.command_line.switching_directories_procedural')
  27. expect(reusable).toBe('1. Change the current working directory to your local repository.')
  28. })
  29. test('includes Japanese variables', async () => {
  30. const prodName = get(data, 'ja.site.data.variables.product.prodname_dotcom')
  31. expect(prodName).toBe('GitHub')
  32. })
  33. test('includes Japanese reusables', async () => {
  34. const reusable = get(data, 'ja.site.data.reusables.audit_log.octicon_icon')
  35. expect(reusable.includes('任意のページの左上で')).toBe(true)
  36. })
  37. // TODO: re-enable once Janky flakyness is resolved
  38. test.skip('backfills missing translated site data with English values', async () => {
  39. const newFile = path.join(__dirname, '../../data/newfile.yml')
  40. await fs.writeFile(newFile, 'newvalue: bar')
  41. const data = await loadSiteData()
  42. expect(get(data, 'en.site.data.newfile.newvalue')).toEqual('bar')
  43. expect(get(data, 'ja.site.data.newfile.newvalue')).toEqual('bar')
  44. await fs.unlink(newFile)
  45. })
  46. test('all Liquid templating is valid', async () => {
  47. const dataMap = flat(data)
  48. for (const key in dataMap) {
  49. const value = dataMap[key]
  50. if (!patterns.hasLiquid.test(value)) continue
  51. let message = `${key} contains a malformed Liquid expression`
  52. let result = null
  53. try {
  54. result = await liquid.parseAndRender(value)
  55. } catch (err) {
  56. console.trace(err)
  57. message += `: ${err.message}`
  58. }
  59. expect(typeof result, message).toBe('string')
  60. }
  61. })
  62. test('includes markdown files as data', async () => {
  63. const reusable = get(data, 'en.site.data.reusables.enterprise_enterprise_support.submit-support-ticket-first-section')
  64. expect(typeof reusable).toBe('string')
  65. expect(reusable.includes('1. ')).toBe(true)
  66. })
  67. test.skip('encodes bracketed parentheses to prevent them from becoming links', async () => {
  68. const reusable = get(data, 'ja.site.data.reusables.organizations.team_name')
  69. const expectation = `reusable should contain a bracket followed by a space. Actual value: ${reusable}`
  70. expect(reusable.includes('] ('), expectation).toBe(true)
  71. })
  72. test('warn if any YAML reusables are found', async () => {
  73. const reusables = require('walk-sync')(path.join(__dirname, '../../data/reusables'))
  74. expect(reusables.length).toBeGreaterThan(100)
  75. const yamlReusables = reusables.filter(filename => filename.endsWith('.yml') || filename.endsWith('.yaml'))
  76. const message = `reusables are now written as individual Markdown files. Please migrate the following YAML files to Markdown:\n${yamlReusables.join('\n')}`
  77. expect(yamlReusables.length, message).toBe(0)
  78. })
  79. test('all non-English data has matching English data', async () => {
  80. for (const languageCode of Object.keys(data)) {
  81. if (languageCode === 'en') continue
  82. const nonEnglishKeys = Object.keys(flat(data[languageCode]))
  83. for (const key of nonEnglishKeys) {
  84. if (!has(data.en, key)) {
  85. throw new Error(`matching data not found for ${languageCode}.${key}`)
  86. }
  87. }
  88. }
  89. })
  90. })
Tip!

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

Comments

Loading...