Skip to content

Commit

Permalink
chore(mdx support): added test to make sure bad comment syntax not wo…
Browse files Browse the repository at this point in the history
…rking
  • Loading branch information
NathanYi authored and NathanYi committed Dec 13, 2023
1 parent 1c41392 commit ad125da
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/__tests__/md-inject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ describe('Markdown injection', () => {
isPr: false,
}))

jest.clearAllMocks()

process.env = originalProcessEnv
})

Expand Down Expand Up @@ -317,19 +319,9 @@ The output of some arbitrary command
expect(fs.writeFile).toHaveBeenCalledWith('foo.md', outFile)
})

it('writes to the markdown document (command) even though bad syntax', async () => {
mock({
config: {
type: 'command',
value: 'some arbitrary command',
},
mockResponse: 'The output of some arbitrary command',
})

await injectMarkdown()

it('does not write to the markdown document (command) because of bad syntax', async () => {
const outFile = `
{/* CODEBLOCK_START {"type":"command","value":"some arbitrary command"} -->
<!-- CODEBLOCK_START {"type":"command","value":"some arbitrary command"} */}
<!-- prettier-ignore -->
~~~~~~~~~~bash
$ some arbitrary command
Expand All @@ -338,7 +330,35 @@ The output of some arbitrary command
~~~~~~~~~~
<!-- CODEBLOCK_END */}`
expect(fs.writeFile).toHaveBeenCalled()

const mock = ({

Check warning on line 334 in src/__tests__/md-inject.test.ts

View workflow job for this annotation

GitHub Actions / Validate

'mock' is assigned a value but never used
config,
mockResponse = '',
}: {
name?: string
mockFileName?: string
config: any
includePrettierIgnore?: boolean
blockContents?: string
mockResponse?: string
}) => {
glob.mockResolvedValue([outFile])

fs.readFile.mockImplementation(async (fileName) => {
if (fileName === outFile) {
return outFile
}

if (config.type !== 'command' && fileName.includes(config.value)) {
return mockResponse
}
throw new Error('Unexpected file name passed')
})
}

await injectMarkdown()

expect(fs.writeFile).not.toHaveBeenCalled()
})

it('writes to the markdown document (file)', async () => {
Expand Down

0 comments on commit ad125da

Please sign in to comment.