Skip to content

Commit

Permalink
test(mdx): add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Nov 2, 2022
1 parent 6b7f04f commit d15f947
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/integration/plugin-mdx-rs/components/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default ({ children }) => (
<button
style={{
borderRadius: '3px',
border: '1px solid black',
color: 'black',
padding: '0.5em 1em',
cursor: 'pointer',
fontSize: '1.1em',
}}
>
{children}
</button>
)
9 changes: 9 additions & 0 deletions test/integration/plugin-mdx-rs/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const withMDX = require('@next/mdx')({
extension: /\.mdx?$/,
})
module.exports = withMDX({
pageExtensions: ['js', 'jsx', 'mdx'],
experimental: {
mdxRs: true,
},
})
7 changes: 7 additions & 0 deletions test/integration/plugin-mdx-rs/pages/button.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Button from '../components/button.js'

# MDX + Next.js

Look, a button! 👇

<Button>👋 Hello</Button>
5 changes: 5 additions & 0 deletions test/integration/plugin-mdx-rs/pages/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Hello MDX

Here's a simple mdx file!!

<p>Have p tag!</p>
28 changes: 28 additions & 0 deletions test/integration/plugin-mdx-rs/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-env jest */

import { join } from 'path'
import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils'

const context = {}

describe('Configuration', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(join(__dirname, '../'), context.appPort)
})
afterAll(() => {
killApp(context.server)
})

describe('MDX-rs Plugin support', () => {
it('should render an MDX page correctly', async () => {
expect(await renderViaHTTP(context.appPort, '/')).toMatch(/Hello MDX/)
})

it('should render an MDX page with component correctly', async () => {
expect(await renderViaHTTP(context.appPort, '/button')).toMatch(
/Look, a button!/
)
})
})
})

0 comments on commit d15f947

Please sign in to comment.