Skip to content

Commit cab4d9d

Browse files
committed
test(block-replacer): add test verifying removeComments strips comment blocks
1 parent 9b79efe commit cab4d9d

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

packages/block-replacer/test/index.test.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ TotallyCustom uppercase
243243
content with comments
244244
BlockHere
245245
`
246-
246+
247247
/** @type {ProcessFileOptions} */
248248
const options = {
249249
content,
@@ -263,9 +263,53 @@ BlockHere
263263
const result = await processFile(options)
264264

265265
console.log('result', result)
266-
266+
267267
assert.is(result.stripComments, true)
268268
assert.is(result.isNewPath, true)
269269
})
270270

271+
test('removeComments should strip comment blocks from output file', async () => {
272+
const content = `# Test Document
273+
274+
<!-- block uppercase -->
275+
hello world
276+
<!-- /block -->
277+
278+
Some content in between.
279+
280+
<!-- block wordcount -->
281+
one two three four five
282+
<!-- /block -->
283+
284+
End of document.
285+
`
286+
287+
const removeCommentsOutput = path.join(testDir, 'stripped.md')
288+
289+
/** @type {ProcessFileOptions} */
290+
const options = {
291+
content,
292+
outputPath: removeCommentsOutput,
293+
removeComments: true,
294+
transforms: mockTransforms
295+
}
296+
297+
const result = await processFile(options)
298+
299+
assert.is(result.stripComments, true, 'stripComments should be true')
300+
assert.is(result.isNewPath, true, 'isNewPath should be true')
301+
assert.is(result.isChanged, true, 'isChanged should be true')
302+
303+
// Read the output file and verify comments are stripped
304+
const outputContent = await fs.readFile(removeCommentsOutput, 'utf8')
305+
306+
// Should contain the transformed content
307+
assert.ok(outputContent.includes('HELLO WORLD'), 'should have transformed content')
308+
assert.ok(outputContent.includes('Word count: 5'), 'should have wordcount transform')
309+
310+
// Should NOT contain comment blocks
311+
assert.not.ok(outputContent.includes('<!-- block'), 'should not have opening comment')
312+
assert.not.ok(outputContent.includes('<!-- /block'), 'should not have closing comment')
313+
})
314+
271315
test.run()

0 commit comments

Comments
 (0)