mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
000e8f4654
* feat: implement redesign * fix: make it build * feat: visual tweaks * feat(overlay): update styling, integration endpoint * feat: add fallback icons * Clean up tests (#9183) * Add `@astrojs/upgrade` package for automatic package upgrades (#8525) Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * [ci] format * fix: links with same path but different search params not prefetched (#9189) Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * fix: discord icon * chore: changeset --------- Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Spencer Whitehead <35475068+SpencerWhitehead7@users.noreply.github.com> Co-authored-by: Matthew Phillips <matthew@skypack.dev>
124 lines
4.2 KiB
JavaScript
124 lines
4.2 KiB
JavaScript
import mdx from '@astrojs/mdx';
|
|
|
|
import { expect } from 'chai';
|
|
import { parseHTML } from 'linkedom';
|
|
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
|
|
describe('MDX slots', () => {
|
|
let fixture;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: new URL('./fixtures/mdx-slots/', import.meta.url),
|
|
integrations: [mdx()],
|
|
});
|
|
});
|
|
|
|
describe('build', () => {
|
|
before(async () => {
|
|
await fixture.build();
|
|
});
|
|
|
|
it('supports top-level imports', async () => {
|
|
const html = await fixture.readFile('/index.html');
|
|
const { document } = parseHTML(html);
|
|
|
|
const h1 = document.querySelector('h1');
|
|
const defaultSlot = document.querySelector('[data-default-slot]');
|
|
const namedSlot = document.querySelector('[data-named-slot]');
|
|
|
|
expect(h1.textContent).to.equal('Hello slotted component!');
|
|
expect(defaultSlot.textContent).to.equal('Default content.');
|
|
expect(namedSlot.textContent).to.equal('Content for named slot.');
|
|
});
|
|
|
|
it('supports glob imports - <Component.default />', async () => {
|
|
const html = await fixture.readFile('/glob/index.html');
|
|
const { document } = parseHTML(html);
|
|
|
|
const h1 = document.querySelector('[data-default-export] h1');
|
|
const defaultSlot = document.querySelector('[data-default-export] [data-default-slot]');
|
|
const namedSlot = document.querySelector('[data-default-export] [data-named-slot]');
|
|
|
|
expect(h1.textContent).to.equal('Hello slotted component!');
|
|
expect(defaultSlot.textContent).to.equal('Default content.');
|
|
expect(namedSlot.textContent).to.equal('Content for named slot.');
|
|
});
|
|
|
|
it('supports glob imports - <Content />', async () => {
|
|
const html = await fixture.readFile('/glob/index.html');
|
|
const { document } = parseHTML(html);
|
|
|
|
const h1 = document.querySelector('[data-content-export] h1');
|
|
const defaultSlot = document.querySelector('[data-content-export] [data-default-slot]');
|
|
const namedSlot = document.querySelector('[data-content-export] [data-named-slot]');
|
|
|
|
expect(h1.textContent).to.equal('Hello slotted component!');
|
|
expect(defaultSlot.textContent).to.equal('Default content.');
|
|
expect(namedSlot.textContent).to.equal('Content for named slot.');
|
|
});
|
|
});
|
|
|
|
describe('dev', () => {
|
|
let devServer;
|
|
|
|
before(async () => {
|
|
devServer = await fixture.startDevServer();
|
|
});
|
|
|
|
after(async () => {
|
|
await devServer.stop();
|
|
});
|
|
|
|
it('supports top-level imports', async () => {
|
|
const res = await fixture.fetch('/');
|
|
|
|
expect(res.status).to.equal(200);
|
|
|
|
const html = await res.text();
|
|
const { document } = parseHTML(html);
|
|
|
|
const h1 = document.querySelector('h1');
|
|
const defaultSlot = document.querySelector('[data-default-slot]');
|
|
const namedSlot = document.querySelector('[data-named-slot]');
|
|
|
|
expect(h1.textContent).to.equal('Hello slotted component!');
|
|
expect(defaultSlot.textContent).to.equal('Default content.');
|
|
expect(namedSlot.textContent).to.equal('Content for named slot.');
|
|
});
|
|
|
|
it('supports glob imports - <Component.default />', async () => {
|
|
const res = await fixture.fetch('/glob');
|
|
|
|
expect(res.status).to.equal(200);
|
|
|
|
const html = await res.text();
|
|
const { document } = parseHTML(html);
|
|
|
|
const h1 = document.querySelector('[data-default-export] h1');
|
|
const defaultSlot = document.querySelector('[data-default-export] [data-default-slot]');
|
|
const namedSlot = document.querySelector('[data-default-export] [data-named-slot]');
|
|
|
|
expect(h1.textContent).to.equal('Hello slotted component!');
|
|
expect(defaultSlot.textContent).to.equal('Default content.');
|
|
expect(namedSlot.textContent).to.equal('Content for named slot.');
|
|
});
|
|
|
|
it('supports glob imports - <Content />', async () => {
|
|
const res = await fixture.fetch('/glob');
|
|
|
|
expect(res.status).to.equal(200);
|
|
|
|
const html = await res.text();
|
|
const { document } = parseHTML(html);
|
|
|
|
const h1 = document.querySelector('[data-content-export] h1');
|
|
const defaultSlot = document.querySelector('[data-content-export] [data-default-slot]');
|
|
const namedSlot = document.querySelector('[data-content-export] [data-named-slot]');
|
|
|
|
expect(h1.textContent).to.equal('Hello slotted component!');
|
|
expect(defaultSlot.textContent).to.equal('Default content.');
|
|
expect(namedSlot.textContent).to.equal('Content for named slot.');
|
|
});
|
|
});
|
|
});
|