test: inject components export
This commit is contained in:
parent
e05ef2d492
commit
2bf00cc68d
6 changed files with 64 additions and 0 deletions
23
packages/integrations/mdx/test/fixtures/mdx-utils-jsToMdxTreeNode/astro.config.mjs
vendored
Normal file
23
packages/integrations/mdx/test/fixtures/mdx-utils-jsToMdxTreeNode/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
import mdx from '@astrojs/mdx';
|
||||
import { jsToMdxTreeNode } from '@astrojs/mdx/utils';
|
||||
|
||||
export default {
|
||||
site: 'https://mdx-is-neat.com/',
|
||||
markdown: {
|
||||
syntaxHighlight: false,
|
||||
},
|
||||
integrations: [mdx({
|
||||
remarkPlugins: [
|
||||
function injectComponentsExport() {
|
||||
const titlePath = new URL('./src/components/Title.astro', import.meta.url).pathname;
|
||||
return (tree) => {
|
||||
tree.children.unshift(
|
||||
jsToMdxTreeNode(`
|
||||
import Title from ${JSON.stringify(titlePath)};
|
||||
export const components = { h1: Title };
|
||||
`));
|
||||
};
|
||||
}
|
||||
]
|
||||
})],
|
||||
}
|
7
packages/integrations/mdx/test/fixtures/mdx-utils-jsToMdxTreeNode/package.json
vendored
Normal file
7
packages/integrations/mdx/test/fixtures/mdx-utils-jsToMdxTreeNode/package.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@test/mdx-utils-jstomdxtreenode",
|
||||
"dependencies": {
|
||||
"astro": "workspace:*",
|
||||
"@astrojs/mdx": "workspace:*"
|
||||
}
|
||||
}
|
1
packages/integrations/mdx/test/fixtures/mdx-utils-jsToMdxTreeNode/src/components/Title.astro
vendored
Normal file
1
packages/integrations/mdx/test/fixtures/mdx-utils-jsToMdxTreeNode/src/components/Title.astro
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<h1 data-is-title-component><slot></slot></h1>
|
3
packages/integrations/mdx/test/fixtures/mdx-utils-jsToMdxTreeNode/src/pages/index.mdx
vendored
Normal file
3
packages/integrations/mdx/test/fixtures/mdx-utils-jsToMdxTreeNode/src/pages/index.mdx
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Injected header test
|
||||
|
||||
Let's see if that header maps to our Astro component!
|
|
@ -0,0 +1,22 @@
|
|||
import { expect } from 'chai';
|
||||
import { parseHTML } from 'linkedom';
|
||||
import { loadFixture } from '../../../astro/test/test-utils.js';
|
||||
|
||||
describe('MDX utils - jsToMdxTreeNode', () => {
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: new URL('./fixtures/mdx-utils-jsToMdxTreeNode/', import.meta.url),
|
||||
});
|
||||
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('Successfully injects title component export', async () => {
|
||||
const html = await fixture.readFile('/index.html');
|
||||
const { document } = parseHTML(html);
|
||||
|
||||
expect(document.querySelector('[data-is-title-component]')).to.not.be.null;
|
||||
});
|
||||
});
|
|
@ -2539,6 +2539,14 @@ importers:
|
|||
'@astrojs/react': link:../../../../react
|
||||
astro: link:../../../../../astro
|
||||
|
||||
packages/integrations/mdx/test/fixtures/mdx-utils-jsToMdxTreeNode:
|
||||
specifiers:
|
||||
'@astrojs/mdx': workspace:*
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
'@astrojs/mdx': link:../../..
|
||||
astro: link:../../../../../astro
|
||||
|
||||
packages/integrations/mdx/test/fixtures/mdx-vite-env-vars:
|
||||
specifiers:
|
||||
'@astrojs/mdx': workspace:*
|
||||
|
|
Loading…
Reference in a new issue