1+ import './setup-tests.js'
2+ import * as Preact from "preact" ;
3+ import * as PreactDOM from "preact/compat" ;
4+ import * as _jsx_runtime from 'preact/jsx-runtime' ;
5+ import { test } from 'uvu'
6+ import * as assert from 'uvu/assert'
7+ import { render } from '@testing-library/preact'
8+ import { bundleMDX } from '../index.js'
9+ import { getMDXComponent } from '../client/jsx.js'
10+
11+
12+
13+ const jsxBundlerConfig = {
14+ jsxLib : {
15+ varName : 'Preact' ,
16+ package : 'preact' ,
17+ } ,
18+ jsxDom : {
19+ varName : 'PreactDom' ,
20+ package : 'preact/compat' ,
21+ } ,
22+ jsxRuntime : {
23+ varName : '_jsx_runtime' ,
24+ package : 'preact/jsx-runtime' ,
25+ } ,
26+ }
27+ const jsxComponentConfig = { Preact, PreactDOM, _jsx_runtime }
28+
29+ const mdxSource = `
30+ ---
31+ title: Example Post
32+ published: 2021-02-13
33+ description: This is some meta-data
34+ ---
35+ import Demo from './demo'
36+
37+ # This is the title
38+
39+ Here's a **neat** demo:
40+ <Demo />
41+ ` . trim ( ) ;
42+
43+ const demoTsx = `
44+ export default function Demo() {
45+ return <div>mdx-bundler with Preact's runtime!</div>
46+ }
47+ ` . trim ( ) ;
48+
49+
50+ test ( 'smoke test for preact' , async ( ) => {
51+
52+ const result = await bundleMDX ( {
53+ source : mdxSource ,
54+ jsxConfig : jsxBundlerConfig ,
55+ files : {
56+ './demo.tsx' : demoTsx
57+ }
58+ } ) ;
59+
60+ const Component = getMDXComponent ( result . code , jsxComponentConfig )
61+
62+ /** @param {Preact.JSX.HTMLAttributes<HTMLSpanElement> } props */
63+ const SpanBold = ( { children} ) => {
64+ return Preact . createElement ( 'span' , { className : "strong" } , children )
65+ }
66+
67+ assert . equal ( result . frontmatter , {
68+ title : 'Example Post' ,
69+ published : new Date ( '2021-02-13' ) ,
70+ description : 'This is some meta-data' ,
71+ } )
72+
73+ const { container} = render (
74+ Preact . h ( Component , { components : { strong : SpanBold } } )
75+ )
76+
77+ assert . equal (
78+ container . innerHTML ,
79+ `<h1>This is the title</h1>
80+ <p>Here's a <span class="strong">neat</span> demo:</p>
81+ <div>mdx-bundler with Preact's runtime!</div>` ,
82+ )
83+ } )
84+
85+ test . run ( )
0 commit comments