Skip to content

Commit

Permalink
Add mdx test
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Jan 30, 2023
1 parent 983f6f0 commit 03f66b5
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/integrations/mdx/test/css-head-mdx.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import mdx from '@astrojs/mdx';

import { expect } from 'chai';
import { parseHTML } from 'linkedom';
import { loadFixture } from '../../../astro/test/test-utils.js';

describe('Head injection w/ MDX', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/css-head-mdx/', import.meta.url),
integrations: [mdx()],
});
});

describe('build', () => {
before(async () => {
await fixture.build();
});

it('only injects contents into head', async () => {
const html = await fixture.readFile('/indexThree/index.html');
const { document } = parseHTML(html);

const links = document.querySelectorAll('link[rel=stylesheet]');
expect(links).to.have.a.lengthOf(1);

const scripts = document.querySelectorAll('script[type=module]');
expect(scripts).to.have.a.lengthOf(1);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
---

<h3>Hello world!!</h3>
<slot />

<style>h3 { color: red }</style>

<script>
console.log('hellooooo')
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
---

<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Astro</title>
</head>
<body>
<slot />
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
import Two from './Two.astro'
---
<Two>
<slot />
</Two>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
import One from './One.astro'
---
<One>
<slot />
</One>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
import One from '../layouts/One.astro'
import { Content } from '../test.mdx'
---

<One>
<h1>Astro</h1>
<Content />
</One>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
import Three from '../layouts/Three.astro'
import { Content } from '../test.mdx'
---

<Three>
<h1>Astro</h1>
<Content />
</Three>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
import Two from '../layouts/Two.astro'
import { Content } from '../test.mdx'
---

<Two>
<h1>Astro</h1>
<Content />
</Two>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: '../layouts/One.astro'
title: "hello world"
publishDate: "2023-01-01"
---

import HelloWorld from '../components/HelloWorld.astro';

# Test

123

<HelloWorld />

456
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: '../layouts/Three.astro'
title: "hello world"
publishDate: "2023-01-01"
---

import HelloWorld from '../components/HelloWorld.astro';

# Test

123

<HelloWorld />

456
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: '../layouts/Two.astro'
title: "hello world"
publishDate: "2023-01-01"
---

import HelloWorld from '../components/HelloWorld.astro';

# Test

123

<HelloWorld />

456
14 changes: 14 additions & 0 deletions packages/integrations/mdx/test/fixtures/css-head-mdx/src/test.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "hello world"
publishDate: "2023-01-01"
---

import HelloWorld from './components/HelloWorld.astro';

# Test

123

<HelloWorld />

456

0 comments on commit 03f66b5

Please sign in to comment.