2022-08-05 21:13:30 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import { parseHTML } from 'linkedom';
|
|
|
|
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
|
|
|
2023-08-31 15:31:01 +00:00
|
|
|
function hookError() {
|
|
|
|
const error = console.error;
|
|
|
|
const errors = [];
|
|
|
|
console.error = function(...args) {
|
|
|
|
errors.push(args);
|
|
|
|
};
|
|
|
|
return () => {
|
|
|
|
console.error = error;
|
|
|
|
return errors;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-05 21:13:30 +00:00
|
|
|
describe('MDX and React', () => {
|
|
|
|
let fixture;
|
2023-08-31 15:31:01 +00:00
|
|
|
let unhook;
|
2022-08-05 21:13:30 +00:00
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
fixture = await loadFixture({
|
|
|
|
root: new URL('./fixtures/mdx-plus-react/', import.meta.url),
|
|
|
|
});
|
2023-08-31 15:31:01 +00:00
|
|
|
unhook = hookError();
|
2022-08-05 21:13:30 +00:00
|
|
|
await fixture.build();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can be used in the same project', async () => {
|
|
|
|
const html = await fixture.readFile('/index.html');
|
|
|
|
const { document } = parseHTML(html);
|
|
|
|
|
|
|
|
const p = document.querySelector('p');
|
|
|
|
|
|
|
|
expect(p.textContent).to.equal('Hello world');
|
|
|
|
});
|
2023-08-31 15:31:01 +00:00
|
|
|
|
|
|
|
it('mdx renders fine', async () => {
|
|
|
|
const html = await fixture.readFile('/post/index.html');
|
|
|
|
const { document } = parseHTML(html);
|
|
|
|
const h = document.querySelector('#testing');
|
|
|
|
expect(h.textContent).to.equal('Testing');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not get a invalid hook call warning', () => {
|
|
|
|
const errors = unhook();
|
|
|
|
expect(errors).to.have.a.lengthOf(0);
|
|
|
|
});
|
2022-08-05 21:13:30 +00:00
|
|
|
});
|