2022-08-05 16:13:30 -05:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import { parseHTML } from 'linkedom';
|
|
|
|
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
|
|
|
2023-08-31 10:31:01 -05:00
|
|
|
function hookError() {
|
|
|
|
const error = console.error;
|
|
|
|
const errors = [];
|
2023-08-31 10:32:51 -05:00
|
|
|
console.error = function (...args) {
|
2023-08-31 10:31:01 -05:00
|
|
|
errors.push(args);
|
|
|
|
};
|
2023-08-31 10:32:51 -05:00
|
|
|
return () => {
|
2023-08-31 10:31:01 -05:00
|
|
|
console.error = error;
|
|
|
|
return errors;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-05 16:13:30 -05:00
|
|
|
describe('MDX and React', () => {
|
|
|
|
let fixture;
|
2023-08-31 10:31:01 -05:00
|
|
|
let unhook;
|
2022-08-05 16:13:30 -05:00
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
fixture = await loadFixture({
|
|
|
|
root: new URL('./fixtures/mdx-plus-react/', import.meta.url),
|
|
|
|
});
|
2023-08-31 10:31:01 -05:00
|
|
|
unhook = hookError();
|
2022-08-05 16:13:30 -05: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 10:31:01 -05: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 16:13:30 -05:00
|
|
|
});
|