Skip to content

Commit

Permalink
test: add mdx playground
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Dec 8, 2022
1 parent f0a088d commit 549ca18
Show file tree
Hide file tree
Showing 11 changed files with 974 additions and 0 deletions.
23 changes: 23 additions & 0 deletions playground/mdx/__tests__/mdx.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, test } from 'vitest'
import {
editFile,
isServe,
page,
untilBrowserLogAfter,
untilUpdated,
} from '~utils'

test('should render', async () => {
expect(await page.textContent('h1')).toMatch('Vite + MDX')
})

if (isServe) {
test('should hmr', async () => {
editFile('src/demo.mdx', (code) => code.replace('Vite + MDX', 'Updated'))
await untilBrowserLogAfter(
() => page.textContent('h1'),
'[vite] hot updated: /src/demo.mdx',
)
await untilUpdated(() => page.textContent('h1'), 'Updated')
})
}
13 changes: 13 additions & 0 deletions playground/mdx/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + MDX</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions playground/mdx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@vitejs/test-mdx",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@mdx-js/rollup": "^2.1.5",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@vitejs/plugin-react": "workspace:*"
}
}
1 change: 1 addition & 0 deletions playground/mdx/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions playground/mdx/src/demo.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Vite + MDX

Sint sit cillum pariatur eiusmod nulla pariatur ipsum.

### Unordered List

- Olive
- Orange
- Blood orange
- Clementine
- Papaya
9 changes: 9 additions & 0 deletions playground/mdx/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import Demo from './demo.mdx'

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<Demo />
</React.StrictMode>,
)
6 changes: 6 additions & 0 deletions playground/mdx/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference types="vite/client" />

declare module '*.mdx' {
import { JSX } from 'react'
export default () => JSX.Element
}
21 changes: 21 additions & 0 deletions playground/mdx/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
9 changes: 9 additions & 0 deletions playground/mdx/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
8 changes: 8 additions & 0 deletions playground/mdx/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import mdx from '@mdx-js/rollup'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [{ enforce: 'pre', ...mdx() }, react({ include: /.mdx$/ })],
})
Loading

0 comments on commit 549ca18

Please sign in to comment.