@@ -39,9 +39,9 @@ function processFrontmatter(contents, file) {
39
39
40
40
describe ( 'removing liquid statements only' , ( ) => {
41
41
test ( 'removes liquid statements that specify "greater than version to deprecate"' , async ( ) => {
42
- let contents = await fs . readFile ( greaterThan , 'utf8' )
43
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
44
- const $ = cheerio . load ( contents )
42
+ const content = await fs . readFile ( greaterThan , 'utf8' )
43
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
44
+ const $ = cheerio . load ( newContent )
45
45
expect ( $ ( '.example1' ) . text ( ) . trim ( ) ) . toBe ( `{% ifversion ghes %}\n
46
46
Alpha\n\n{% endif %}` )
47
47
expect ( $ ( '.example2' ) . text ( ) . trim ( ) ) . toBe ( `{% ifversion fpt or ghes %}\n
@@ -65,9 +65,9 @@ Alpha\n\n{% else %}\n\nBravo\n\n{% ifversion ghes > 2.16 %}\n\nCharlie\n
65
65
{% else %}\n\nBravo\n\n{% endif %}` )
66
66
} )
67
67
test ( 'removes liquid statements that specify all known versions, including some nested conditionals"' , async ( ) => {
68
- let contents = await fs . readFile ( unnecessary , 'utf8' )
69
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
70
- const $ = cheerio . load ( contents )
68
+ const content = await fs . readFile ( unnecessary , 'utf8' )
69
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
70
+ const $ = cheerio . load ( newContent )
71
71
expect ( $ ( '.example1' ) . text ( ) . trim ( ) ) . toBe ( `Alpha` )
72
72
expect ( $ ( '.example2' ) . text ( ) . trim ( ) ) . toBe (
73
73
`Alpha\n {% ifversion fpt or ghec %}\n Bravo\n {% endif %}`
@@ -84,9 +84,9 @@ Alpha\n\n{% else %}\n\nBravo\n\n{% ifversion ghes > 2.16 %}\n\nCharlie\n
84
84
} )
85
85
86
86
test ( 'removes liquid statements that specify "and greater than version to deprecate"' , async ( ) => {
87
- let contents = await fs . readFile ( andGreaterThan1 , 'utf8' )
88
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
89
- const $ = cheerio . load ( contents )
87
+ const content = await fs . readFile ( andGreaterThan1 , 'utf8' )
88
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
89
+ const $ = cheerio . load ( newContent )
90
90
expect ( $ ( '.example1' ) . text ( ) . trim ( ) ) . toBe (
91
91
'{% ifversion not fpt and ghes %}\n\nAlpha\n\n{% endif %}'
92
92
)
@@ -102,9 +102,9 @@ Alpha\n\n{% ifversion ghes > 2.16 %}\n\nBravo\n\n{% endif %}\n\n{% else %}\n\nCh
102
102
} )
103
103
104
104
test ( 'removes liquid statements that specify "and greater than version to deprecate" (alternate format)' , async ( ) => {
105
- let contents = await fs . readFile ( andGreaterThan2 , 'utf8' )
106
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
107
- const $ = cheerio . load ( contents )
105
+ const content = await fs . readFile ( andGreaterThan2 , 'utf8' )
106
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
107
+ const $ = cheerio . load ( newContent )
108
108
expect ( $ ( '.example1' ) . text ( ) . trim ( ) ) . toBe ( '{% ifversion ghes < 2.16 %}\n\nAlpha\n\n{% endif %}' )
109
109
expect ( $ ( '.example2' ) . text ( ) . trim ( ) ) . toBe ( `{% ifversion ghes < 2.16 %}\n\nAlpha\n\n{% else %}\n
110
110
Bravo\n\n{% endif %}` )
@@ -117,9 +117,9 @@ Alpha\n\n{% ifversion not fpt %}\n\nBravo\n\n{% endif %}\n\n{% else %}\n\nCharli
117
117
} )
118
118
119
119
test ( 'removes liquid statements that specify "not equals version to deprecate"' , async ( ) => {
120
- let contents = await fs . readFile ( notEquals , 'utf8' )
121
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
122
- const $ = cheerio . load ( contents )
120
+ const content = await fs . readFile ( notEquals , 'utf8' )
121
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
122
+ const $ = cheerio . load ( newContent )
123
123
expect ( $ ( '.example1' ) . text ( ) . trim ( ) ) . toBe ( '{% ifversion ghes %}\n\nAlpha\n\n{% endif %}' )
124
124
expect ( $ ( '.example2' ) . text ( ) . trim ( ) ) . toBe ( '{% ifversion fpt or ghes %}\n\nAlpha\n\n{% endif %}' )
125
125
expect ( $ ( '.example3' ) . text ( ) . trim ( ) ) . toBe ( `{% ifversion fpt %}\n
@@ -136,9 +136,9 @@ Alpha\n\n{% endif %}`)
136
136
137
137
describe ( 'removing liquid statements and content' , ( ) => {
138
138
test ( 'removes interior content and liquid statements that specify "equals version to deprecate"' , async ( ) => {
139
- let contents = await fs . readFile ( equals , 'utf8' )
140
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
141
- const $ = cheerio . load ( contents )
139
+ const content = await fs . readFile ( equals , 'utf8' )
140
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
141
+ const $ = cheerio . load ( newContent )
142
142
expect ( $ ( '.example1' ) . text ( ) . trim ( ) ) . toBe ( '' )
143
143
expect ( $ ( '.example2' ) . text ( ) . trim ( ) ) . toBe ( '{% ifversion not fpt %}\n\nAlpha\n\n{% endif %}' )
144
144
expect ( $ ( '.example3' ) . text ( ) . trim ( ) ) . toBe ( `{% ifversion fpt %}\n
@@ -152,9 +152,9 @@ Alpha\n\n{% else %}\n\nCharlie\n\n{% endif %}`)
152
152
} )
153
153
154
154
test ( 'removes interior content and liquid statements that specify "less than next oldest than version to deprecate"' , async ( ) => {
155
- let contents = await fs . readFile ( lessThanNextOldest , 'utf8' )
156
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
157
- const $ = cheerio . load ( contents )
155
+ const content = await fs . readFile ( lessThanNextOldest , 'utf8' )
156
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
157
+ const $ = cheerio . load ( newContent )
158
158
expect ( $ ( '.example1' ) . text ( ) . trim ( ) ) . toBe ( 'Alpha' )
159
159
expect ( $ ( '.example2' ) . text ( ) . trim ( ) ) . toBe (
160
160
'Alpha\n\n{% ifversion fpt %}\n\nBravo\n\n{% endif %}'
@@ -193,19 +193,19 @@ describe('updating frontmatter', () => {
193
193
194
194
describe ( 'whitespace' , ( ) => {
195
195
test ( 'does not add newlines when whitespace control is used' , async ( ) => {
196
- let contents = await fs . readFile ( whitespace , 'utf8' )
197
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
198
- const $ = cheerio . load ( contents )
196
+ const content = await fs . readFile ( whitespace , 'utf8' )
197
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
198
+ const $ = cheerio . load ( newContent )
199
199
expect ( $ ( '.example1' ) . text ( ) ) . toBe ( '\n{% ifversion ghes %}\n Alpha\n{% endif %}\n' )
200
200
expect ( $ ( '.example2' ) . text ( ) ) . toBe ( '\n{%- ifversion ghes %}\n Alpha\n{% endif %}\n' )
201
201
expect ( $ ( '.example3' ) . text ( ) ) . toBe ( '\n{% ifversion fpt or ghes %}\n Alpha\n{%- endif %}\n' )
202
202
expect ( $ ( '.example4' ) . text ( ) ) . toBe ( '\n{%- ifversion fpt or ghes %}\n Alpha\n{%- endif %}\n' )
203
203
} )
204
204
205
205
test ( 'does not add newlines when no newlines are present' , async ( ) => {
206
- let contents = await fs . readFile ( whitespace , 'utf8' )
207
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
208
- const $ = cheerio . load ( contents )
206
+ const content = await fs . readFile ( whitespace , 'utf8' )
207
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
208
+ const $ = cheerio . load ( newContent )
209
209
expect ( $ ( '.example5' ) . text ( ) ) . toBe ( '\n{% ifversion ghes %}\n Alpha\n{% endif %}\n' )
210
210
expect ( $ ( '.example6' ) . text ( ) ) . toBe (
211
211
'\n Alpha\n{% ifversion fpt or ghes %}\n Bravo\n{% endif %}\n Charlie\n'
@@ -214,9 +214,9 @@ describe('whitespace', () => {
214
214
} )
215
215
216
216
test ( 'only remove newlines when tag starts at beginning of line' , async ( ) => {
217
- let contents = await fs . readFile ( whitespace , 'utf8' )
218
- contents = removeLiquidStatements ( contents , versionToDeprecate , nextOldestVersion )
219
- const $ = cheerio . load ( contents )
217
+ const content = await fs . readFile ( whitespace , 'utf8' )
218
+ const { newContent } = removeLiquidStatements ( content , versionToDeprecate , nextOldestVersion )
219
+ const $ = cheerio . load ( newContent )
220
220
expect ( $ ( '.example8' ) . text ( ) ) . toBe ( '\nAlpha\nBravo\n' )
221
221
expect ( $ ( '.example9' ) . text ( ) ) . toBe ( '\nAlpha\nBravo\n' )
222
222
expect ( $ ( '.example10' ) . text ( ) ) . toBe ( '\nPre\nBravo\n' )
0 commit comments