Skip to content

Commit

Permalink
chore(mdx support): updated test to be more extensive
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanYi authored and NathanYi committed Dec 13, 2023
1 parent ad125da commit 8e12214
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions src/__tests__/md-inject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,44 +320,31 @@ The output of some arbitrary command
})

it('does not write to the markdown document (command) because of bad syntax', async () => {
const outFile = `
const inFile = `
<!-- CODEBLOCK_START {"type":"command","value":"some arbitrary command"} */}
<!-- prettier-ignore -->
<!-- CODEBLOCK_END */}`

const inFileName = `<!-- prettier-ignore -->
~~~~~~~~~~bash
$ some arbitrary command
The output of some arbitrary command
~~~~~~~~~~
~~~~~~~~~~`

<!-- CODEBLOCK_END */}`
glob.mockResolvedValue([inFileName])

const mock = ({
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')
})
}
fs.readFile.mockImplementation(async (fileName) => {
if (fileName === inFileName) {
return inFile
}
throw new Error('Unexpected file name passed')
})

await injectMarkdown()

expect(fs.readFile).toHaveBeenCalledWith(inFileName, { encoding: 'utf-8' })

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

Expand Down

0 comments on commit 8e12214

Please sign in to comment.