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

remove-liquid-statements.js 10 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
  1. const path = require('path')
  2. const cheerio = require('cheerio')
  3. const matter = require('gray-matter')
  4. const readFileAsync = require('../../lib/readfile-async')
  5. const removeLiquidStatements = require('../../lib/remove-liquid-statements')
  6. const removeDeprecatedFrontmatter = require('../../lib/remove-deprecated-frontmatter')
  7. const removeLiquidStatementsFixtures = path.join(__dirname, '../fixtures/remove-liquid-statements')
  8. // Hardcode values so tests don't go out of date
  9. const versionToDeprecate = 'enterprise-server@2.13'
  10. const nextOldestVersion = 'enterprise-server@2.14'
  11. // Remove liquid only
  12. const greaterThan = path.join(removeLiquidStatementsFixtures, 'greater-than.md')
  13. const andGreaterThan1 = path.join(removeLiquidStatementsFixtures, 'and-greater-than1.md')
  14. const andGreaterThan2 = path.join(removeLiquidStatementsFixtures, 'and-greater-than2.md')
  15. const notEquals = path.join(removeLiquidStatementsFixtures, 'not-equals.md')
  16. // Remove liquid and content
  17. const lessThanNextOldest = path.join(removeLiquidStatementsFixtures, 'less-than-next-oldest.md')
  18. const equals = path.join(removeLiquidStatementsFixtures, 'equals.md')
  19. // Check whitespace
  20. const whitespace = path.join(removeLiquidStatementsFixtures, 'whitespace.md')
  21. // Update frontmatter
  22. const frontmatter1 = path.join(removeLiquidStatementsFixtures, 'frontmatter1.md')
  23. const frontmatter2 = path.join(removeLiquidStatementsFixtures, 'frontmatter2.md')
  24. // process frontmatter
  25. function processFrontmatter (contents, file) {
  26. const { content, data } = matter(contents)
  27. removeDeprecatedFrontmatter(file, data.versions, versionToDeprecate, nextOldestVersion)
  28. return matter.stringify(content, data, { lineWidth: 10000 })
  29. }
  30. describe('removing liquid statements only', () => {
  31. test('removes liquid statements that specify "greater than version to deprecate"', async () => {
  32. let contents = await readFileAsync(greaterThan, 'utf8')
  33. contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion)
  34. const $ = cheerio.load(contents)
  35. expect($('.example1').text().trim()).toBe('Alpha')
  36. expect($('.example2').text().trim()).toBe('Alpha')
  37. expect($('.example3').text().trim()).toBe('Alpha')
  38. expect($('.example4').text().trim()).toBe(`{% if currentVersion ver_gt "enterprise-server@2.16" %}\n
  39. Alpha\n\n{% else %}\n\nBravo\n\nCharlie\n\n{% endif %}`)
  40. expect($('.example5').text().trim()).toBe(`{% if currentVersion ver_lt "enterprise-server@2.16" %}\n
  41. Alpha\n\nBravo\n\n{% else %}\n\nCharlie\n\n{% endif %}`)
  42. expect($('.example6').text().trim()).toBe(`Alpha\n\n{% if currentVersion ver_lt "enterprise-server@2.16" %}\n
  43. Bravo\n\n{% endif %}`)
  44. expect($('.example7').text().trim()).toBe(`Alpha\n\n{% if currentVersion ver_gt "enterprise-server@2.16" %}\n
  45. Bravo\n\n{% else %}\n\nCharlie\n\n{% endif %}`)
  46. expect($('.example8').text().trim()).toBe('Alpha')
  47. expect($('.example9').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n
  48. Alpha\n\n{% else %}\n\nBravo\n\n{% if currentVersion ver_gt "enterprise-server@2.16" %}\n\nCharlie\n
  49. {% endif %}\n\nDelta\n\n{% endif %}`)
  50. expect($('.example10').text().trim()).toBe('Alpha')
  51. })
  52. test('removes liquid statements that specify "and greater than version to deprecate"', async () => {
  53. let contents = await readFileAsync(andGreaterThan1, 'utf8')
  54. contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion)
  55. const $ = cheerio.load(contents)
  56. expect($('.example1').text().trim()).toBe('{% if currentVersion != "free-pro-team@latest" %}\n\nAlpha\n\n{% endif %}')
  57. expect($('.example2').text().trim()).toBe('{% if currentVersion != "free-pro-team@latest" %}\n\nAlpha\n\n{% endif %}')
  58. expect($('.example3').text().trim()).toBe(`{% if currentVersion ver_gt "enterprise-server@2.16" %}\n
  59. Alpha\n\n{% else %}\n\nBravo\n\n{% if currentVersion != "free-pro-team@latest" %}\n\nCharlie\n\n{% endif %}\n{% endif %}`)
  60. expect($('.example4').text().trim()).toBe(`{% if currentVersion ver_lt "enterprise-server@2.16" %}\n
  61. Alpha\n\n{% if currentVersion != "free-pro-team@latest" %}\n\nBravo\n\n{% endif %}\n\n{% else %}\n\nCharlie\n\n{% endif %}`)
  62. expect($('.example5').text().trim()).toBe(`{% if currentVersion != "free-pro-team@latest" %}\n
  63. Alpha\n\n{% if currentVersion ver_gt "enterprise-server@2.16" %}\n\nBravo\n\n{% endif %}\n\n{% endif %}`)
  64. })
  65. test('removes liquid statements that specify "and greater than version to deprecate" (alternate format)', async () => {
  66. let contents = await readFileAsync(andGreaterThan2, 'utf8')
  67. contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion)
  68. const $ = cheerio.load(contents)
  69. expect($('.example1').text().trim()).toBe('{% if currentVersion ver_lt "enterprise-server@2.16" %}\n\nAlpha\n\n{% endif %}')
  70. expect($('.example2').text().trim()).toBe('{% if currentVersion ver_lt "enterprise-server@2.16" %}\n\nAlpha\n\n{% endif %}')
  71. expect($('.example3').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n
  72. Alpha\n\n{% else %}\n\nBravo\n\n{% if currentVersion ver_lt "enterprise-server@2.16" %}\n\nCharlie\n\n{% endif %}\n{% endif %}`)
  73. expect($('.example4').text().trim()).toBe(`{% if currentVersion != "free-pro-team@latest" %}\n
  74. Alpha\n\n{% if currentVersion ver_lt "enterprise-server@2.16" %}\n\nBravo\n\n{% endif %}\n\n{% else %}\n\nCharlie\n\n{% endif %}`)
  75. expect($('.example5').text().trim()).toBe(`{% if currentVersion ver_lt "enterprise-server@2.16" %}\n
  76. Alpha\n\n{% if currentVersion != "free-pro-team@latest" %}\n\nBravo\n\n{% endif %}\n\n{% endif %}`)
  77. })
  78. test('removes liquid statements that specify "not equals version to deprecate"', async () => {
  79. let contents = await readFileAsync(notEquals, 'utf8')
  80. contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion)
  81. const $ = cheerio.load(contents)
  82. expect($('.example1').text().trim()).toBe('Alpha')
  83. expect($('.example2').text().trim()).toBe('{% if currentVersion == "free-pro-team@latest" %}\n\nAlpha\n\n{% endif %}')
  84. expect($('.example3').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n
  85. Alpha\n\n{% else %}\n\nBravo\n\nCharlie\n\n{% endif %}`)
  86. expect($('.example4').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n
  87. Alpha\n\nBravo\n\n{% else %}\n\nCharlie\n\n{% endif %}`)
  88. expect($('.example5').text().trim()).toBe(`Alpha\n\n{% if currentVersion == "free-pro-team@latest" %}\n
  89. Bravo\n\n{% endif %}`)
  90. expect($('.example6').text().trim()).toBe(`{% if currentVersion != "free-pro-team@latest" %}\n
  91. Alpha\n\n{% endif %}`)
  92. })
  93. })
  94. describe('removing liquid statements and content', () => {
  95. test('removes interior content and liquid statements that specify "equals version to deprecate"', async () => {
  96. let contents = await readFileAsync(equals, 'utf8')
  97. contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion)
  98. const $ = cheerio.load(contents)
  99. expect($('.example1').text().trim()).toBe('')
  100. expect($('.example2').text().trim()).toBe('')
  101. expect($('.example3').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n
  102. Alpha\n\n{% else %}\n\nBravo\n\n{% endif %}`)
  103. expect($('.example4').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n
  104. Alpha\n\n{% else %}\n\nCharlie\n\n{% endif %}`)
  105. expect($('.example5').text().trim()).toBe('Charlie')
  106. expect($('.example6').text().trim()).toBe('Charlie\n\nBravo')
  107. })
  108. test('removes interior content and liquid statements that specify "less than next oldest than version to deprecate"', async () => {
  109. let contents = await readFileAsync(lessThanNextOldest, 'utf8')
  110. contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion)
  111. const $ = cheerio.load(contents)
  112. expect($('.example1').text().trim()).toBe('Alpha')
  113. expect($('.example2').text().trim()).toBe('Alpha')
  114. expect($('.example3').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n
  115. Alpha\n\n{% else %}\n\nBravo\n\n{% endif %}`)
  116. expect($('.example4').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n
  117. Alpha\n\n{% else %}\n\nCharlie\n\n{% endif %}`)
  118. expect($('.example5').text().trim()).toBe('Charlie')
  119. expect($('.example6').text().trim()).toBe(`{% if currentVersion ver_lt "enterprise-server@2.16" %}\n
  120. Alpha\n\n{% else %}\n\nCharlie\n\n{% endif %}`)
  121. expect($('.example7').text().trim()).toBe('')
  122. expect($('.example8').text().trim()).toBe(`Bravo\n\n{% if currentVersion ver_gt "enterprise-server@2.16" %}\n
  123. Charlie\n\n{% else %}\n\nDelta\n\n{% endif %}\n\nEcho`)
  124. })
  125. })
  126. describe('updating frontmatter', () => {
  127. test('updates frontmatter versions Enterprise if set to greater-than-or-equal-to version to deprecate', async () => {
  128. let contents = await readFileAsync(frontmatter1, 'utf8')
  129. contents = processFrontmatter(contents, frontmatter1)
  130. const $ = cheerio.load(contents)
  131. // console.log('foo')
  132. // console.log($.text())
  133. expect($.text().includes('enterprise-server: \'*\'')).toBe(true)
  134. expect($.text().includes('enterprise-server: \'>=2.13\'')).toBe(false)
  135. })
  136. test('updates frontmatter versions Enterprise if set to greater-than-or-equal-to next oldest version', async () => {
  137. let contents = await readFileAsync(frontmatter2, 'utf8')
  138. contents = processFrontmatter(contents, frontmatter2)
  139. const $ = cheerio.load(contents)
  140. expect($.text().includes('enterprise-server: \'*\'')).toBe(true)
  141. expect($.text().includes('enterprise-server: \'>=2.14\'')).toBe(false)
  142. })
  143. })
  144. describe('whitespace', () => {
  145. test('does not add newlines when whitespace control is used', async () => {
  146. let contents = await readFileAsync(whitespace, 'utf8')
  147. contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion)
  148. const $ = cheerio.load(contents)
  149. expect($('.example1').text()).toBe('\n Alpha\n')
  150. expect($('.example2').text()).toBe('\n Alpha\n')
  151. expect($('.example3').text()).toBe('\n Alpha\n')
  152. expect($('.example4').text()).toBe('\n Alpha\n')
  153. })
  154. test('does not add newlines when no newlines are present', async () => {
  155. let contents = await readFileAsync(whitespace, 'utf8')
  156. contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion)
  157. const $ = cheerio.load(contents)
  158. expect($('.example5').text()).toBe('\n Alpha\n')
  159. expect($('.example6').text()).toBe('\n Alpha\n Bravo\n Charlie\n')
  160. expect($('.example7').text()).toBe('\nAlpha\nBravo\n')
  161. })
  162. })
Tip!

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

Comments

Loading...