File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -333,7 +333,7 @@ The output of some arbitrary command
333333
334334 const outFile = `
335335{/* CODEBLOCK_START {"type":"command","value":"some arbitrary command"} */}
336- <!-- prettier-ignore -->
336+ {/* prettier-ignore */}
337337~~~~~~~~~~bash
338338$ some arbitrary command
339339
@@ -344,6 +344,35 @@ The output of some arbitrary command
344344 expect ( fs . writeFile ) . toHaveBeenCalledWith ( 'foo.mdx' , outFile )
345345 } )
346346
347+ it ( 'fails to write to the markdown document (command) with mixed syntax' , async ( ) => {
348+ const inFile = `
349+ {/* CODEBLOCK_START {"type":"command","value":"some arbitrary command"} */}
350+
351+ {/* CODEBLOCK_END */}`
352+
353+ const inFileName = `<!-- prettier-ignore -->
354+ ~~~~~~~~~~bash
355+ $ some arbitrary command
356+
357+ The output of some arbitrary command
358+ ~~~~~~~~~~`
359+
360+ glob . mockResolvedValue ( [ inFileName ] )
361+
362+ fs . readFile . mockImplementation ( async ( fileName ) => {
363+ if ( fileName === inFileName ) {
364+ return inFile
365+ }
366+ throw new Error ( 'Unexpected file name passed' )
367+ } )
368+
369+ await injectMarkdown ( )
370+
371+ expect ( fs . readFile ) . toHaveBeenCalledWith ( inFileName , { encoding : 'utf-8' } )
372+
373+ expect ( fs . writeFile ) . not . toHaveBeenCalled ( )
374+ } )
375+
347376 it ( 'does not write to the markdown document (command) because of bad syntax' , async ( ) => {
348377 const inFile = `
349378<!-- CODEBLOCK_START {"type":"command","value":"some arbitrary command"} */}
Original file line number Diff line number Diff line change @@ -207,7 +207,10 @@ const main = async (
207207 // https://github.github.com/gfm/#example-94
208208 const codeblockFence = '~~~~~~~~~~'
209209
210- const prettierIgnore = '<!-- prettier-ignore -->'
210+ const checkFileName = fileName
211+ const prettierIgnore = checkFileName . includes ( 'mdx' )
212+ ? '{/* prettier-ignore */}'
213+ : '<!-- prettier-ignore -->'
211214
212215 if ( trim ) {
213216 out = out . trim ( )
You can’t perform that action at this time.
0 commit comments