`}'
- )
- ).toBeTruthy()
-})
-
-it.skip('Should support comments', async () => {
- const result = await mdxWithVueCompiler(`
-A paragraph
-
-\`\`\`md
-
-\`\`\`
-
-
- {/* a nested JSX comment */}
-
-
- `)
-
- expect(result.includes('')).toBeTruthy()
- expect(result.includes('{/* a nested JSX comment */}')).toBeTruthy()
- expect(result.includes('{/* a nested Markdown comment */}')).toBeTruthy()
-})
-
-it('Should not include export wrapper if skipExport is true', async () => {
- const result = await mdxWithVueCompiler('> test\n\n> `test`', {
- skipExport: true
- })
-
- expect(
- result.includes(`
- export default {
- render() {
- `)
- ).toBeFalsy()
-})
-
-it('Should recognize components as properties', async () => {
- const result = await mdxWithVueCompiler('# Hello\n\n
')
- expect(
- result.includes(
- '
{`Hello`}\n
'
- )
- ).toBeTruthy()
-})
-
-it('Should render elements without wrapping blank new lines', async () => {
- const result = await mdxWithVueCompiler(`
- | Test | Table |
- | :--- | :---- |
- | Col1 | Col2 |`)
-
- expect(result.includes('{`\n`}')).toBe(false)
-})
-
-it('Should await and render async plugins', async () => {
- const result = await mdxWithVueCompiler(fixtureBlogPost, {
- rehypePlugins: [
- () => tree =>
- (() => {
- const headingNode = select('h1', tree)
- const textNode = headingNode.children[0]
- textNode.value = textNode.value.toUpperCase()
- })()
- ]
- })
-
- expect(result).toMatch(/HELLO, WORLD!/)
-})
-
-it('Should parse and render footnotes', async () => {
- const result = await mdxWithVueCompiler(
- 'This is a paragraph with a [^footnote]\n\n[^footnote]: Here is the footnote'
- )
-
- expect(
- result.includes(
- '
'
- )
- )
-
- expect(
- result.includes(
- ''
- )
- )
-}, 10000)
diff --git a/packages/vue/test/fixtures/blog-post.md b/packages/vue/test/fixtures/blog-post.md
deleted file mode 100644
index 66eb2dad1..000000000
--- a/packages/vue/test/fixtures/blog-post.md
+++ /dev/null
@@ -1,41 +0,0 @@
-import { Baz } from './Fixture'
-import { Buz } from './Fixture'
-
-export const foo = {
- hi: `Fudge ${Baz.displayName || 'Baz'}`,
- authors: [
- 'fred',
- 'sally'
- ]
-}
-
-# Hello, world!
-
-
-I'm an awesome paragraph.
-
-
-
-
- hi
- {hello}
- {/* another commment */}
-
-
-```
-test codeblock
-```
-
-```js
-module.exports = 'test'
-```
-
-```sh
-npm i -g foo
-```
-
-| Test | Table |
-| :--- | :---- |
-| Col1 | Col2 |
-
-export default ({children}) => {children}
diff --git a/packages/vue/test/mdx-components.js b/packages/vue/test/mdx-components.js
new file mode 100644
index 000000000..a87b9f62a
--- /dev/null
+++ b/packages/vue/test/mdx-components.js
@@ -0,0 +1,57 @@
+const components = {
+ inlineCode: props => ({
+ name: 'InlineCode',
+ render(h) {
+ return h('code', {
+ attrs: {
+ id: 'mdx-code',
+ style: {
+ color: 'currentColor',
+ fontFamily: 'monospace, mono',
+ fontSize: '0.85em'
+ }
+ },
+ domProps: {
+ ...props
+ }
+ }, this.$slots.default)
+ }
+ }),
+ h1: props => ({
+ name: 'Heading',
+ render(h) {
+ return h('h1', {
+ attrs: {
+ id: 'mdx-h1',
+ style: {
+ fontWeight: 'bold',
+ }
+ },
+ domProps: {
+ ...props
+ }
+ }, this.$slots.default)
+ }
+ }),
+ blockquote: props => ({
+ name: 'BlockQuote',
+ render(h) {
+ return h('blockquote', {
+ attrs: {
+ id: 'mdx-blockquote',
+ style: {
+ borderLeft: '5px solid tomato',
+ borderRadius: '0.5rem',
+ marginTop: '3rem',
+ marginBottom: '3rem',
+ }
+ },
+ domProps: {
+ ...props
+ }
+ }, this.$slots.default)
+ }
+ }),
+}
+
+export default components
diff --git a/packages/vue/test/mdx-provider.test.js b/packages/vue/test/mdx-provider.test.js
index 9bd217831..5ce23f06a 100644
--- a/packages/vue/test/mdx-provider.test.js
+++ b/packages/vue/test/mdx-provider.test.js
@@ -1,33 +1,36 @@
-import {mount} from '@vue/test-utils'
-import {MDXProvider, MDXTag} from '../src'
+import { shallowMount } from '@vue/test-utils'
+import MDXProvider from '../src/mdx-provider'
+import components from './mdx-components'
-const H1Tag = {
- render() {
- const data = {style: {color: 'green'}}
- return {this.$slots.default}
+/**
+ * Skipped because @vue/test-utils requires jsdom-global installed.
+ * @todo Add unit test setup for vue components with @vue/test-utils or @testing-library/vue
+ */
+xdescribe('===== MDXProvider Component =====', () => {
+ let mdxProvider
+ const ChildComponent = {
+ inject: ['$mdxComponents'],
+ render: h => h('div', {})
}
-}
-const Layout = {
- render() {
- return {this.$slots.default}
- }
-}
+ it('should be a Vue component', () => {
+ mdxProvider = shallowMount(MDXProvider, {
+ slots: {
+ default: [ChildComponent]
+ }
+ })
+ expect(mdxProvider.isVueInstance()).toBeTruthy()
+ })
-it('Should allow components to be passed via context', () => {
- const components = {h1: H1Tag}
- const TestComponent = {
- render() {
- return (
-
-
- Hello World!
-
-
- )
- }
- }
- const wrapper = mount(TestComponent)
- expect(wrapper.html()).toMatch(/id="layout"/)
- expect(wrapper.html()).toMatch(/style="color: green;"/)
+ it('should provide mdx components object to child components', () => {
+ mdxProvider = shallowMount(MDXProvider, {
+ slots: {
+ default: [ChildComponent]
+ },
+ propsData: {
+ components,
+ }
+ })
+ expect(mdxProvider.find(ChildComponent).vm.$mdxComponents()).toBe(components)
+ })
})
diff --git a/packages/vue/test/mdx-tag.test.js b/packages/vue/test/mdx-tag.test.js
deleted file mode 100644
index 44e5d295a..000000000
--- a/packages/vue/test/mdx-tag.test.js
+++ /dev/null
@@ -1,52 +0,0 @@
-import {mount} from '@vue/test-utils'
-import {MDXTag} from '../src'
-
-const H1Tag = {
- render() {
- return {this.$slots.default}
- }
-}
-
-const Layout = {
- props: ['id'],
- render() {
- return {this.$slots.default}
- }
-}
-
-it('Should render the desired component', () => {
- const wrapper = mount(MDXTag, {
- propsData: {
- name: 'h1',
- components: {h1: H1Tag}
- },
- slots: {
- default: 'Hello World!'
- }
- })
- expect(wrapper.isVueInstance()).toBeTruthy()
- expect(wrapper.html()).toMatch(/style="color: green;"/)
-})
-
-it('Should render the Layout component', () => {
- const components = {h1: H1Tag}
- const MDXTagWithLayout = {
- render() {
- return (
-
-
- Hello World!
-
-
- )
- }
- }
- const wrapper = mount(MDXTagWithLayout)
- expect(wrapper.html()).toMatch(/id="layout"/)
- expect(wrapper.html()).toMatch(/style="color: green;"/)
-})
diff --git a/yarn.lock b/yarn.lock
index 766e39686..115fde972 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -45,7 +45,7 @@
dependencies:
cross-fetch "3.0.4"
-"@babel/cli@^7.5.5":
+"@babel/cli@^7.5.5", "@babel/cli@^7.8.4":
version "7.8.4"
resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.8.4.tgz#505fb053721a98777b2b175323ea4f090b7d3c1c"
integrity sha512-XXLgAm6LBbaNxaGhMAznXXaxtCWfuv6PIDJ9Alsy9JYTOh+j2jJz+L/162kkfU1j/pTSxK1xGmlwI4pdIMkoag==
@@ -6947,9 +6947,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000844, caniuse-lite@^1.0.30000884, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30000989, caniuse-lite@^1.0.30001017, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001039, caniuse-lite@^1.0.30001043:
- version "1.0.30001045"
- resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001045.tgz#a770df9de36ad6ca0c34f90eaa797a2dbbb1b619"
- integrity sha512-Y8o2Iz1KPcD6FjySbk1sPpvJqchgxk/iow0DABpGyzA1UeQAuxh63Xh0Enj5/BrsYbXtCN32JmR4ZxQTCQ6E6A==
+ version "1.0.30001046"
+ resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001046.tgz#7a06d3e8fd8aa7f4d21c9a2e313f35f2d06b013e"
+ integrity sha512-CsGjBRYWG6FvgbyGy+hBbaezpwiqIOLkxQPY4A4Ea49g1eNsnQuESB+n4QM0BKii1j80MyJ26Ir5ywTQkbRE4g==
capture-exit@^1.2.0:
version "1.2.0"
@@ -8179,6 +8179,13 @@ create-react-context@^0.2.2, create-react-context@^0.2.3:
fbjs "^0.8.0"
gud "^1.0.0"
+cross-env@^7.0.2:
+ version "7.0.2"
+ resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.2.tgz#bd5ed31339a93a3418ac4f3ca9ca3403082ae5f9"
+ integrity sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw==
+ dependencies:
+ cross-spawn "^7.0.1"
+
cross-fetch@2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.2.tgz#a47ff4f7fc712daba8f6a695a11c948440d45723"
@@ -26454,6 +26461,14 @@ warning@^4.0.1, warning@^4.0.3:
dependencies:
loose-envify "^1.0.0"
+watch@^1.0.2:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/watch/-/watch-1.0.2.tgz#340a717bde765726fa0aa07d721e0147a551df0c"
+ integrity sha1-NApxe952Vyb6CqB9ch4BR6VR3ww=
+ dependencies:
+ exec-sh "^0.2.0"
+ minimist "^1.2.0"
+
watch@~0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/watch/-/watch-0.18.0.tgz#28095476c6df7c90c963138990c0a5423eb4b986"