2024-01-31 03:37:34 -05:00
|
|
|
import * as assert from 'node:assert/strict';
|
|
|
|
import { before, describe, it } from 'node:test';
|
2022-08-05 16:13:30 -05:00
|
|
|
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');
|
|
|
|
|
2024-01-31 03:37:34 -05:00
|
|
|
assert.equal(p.textContent, 'Hello world');
|
2022-08-05 16:13:30 -05:00
|
|
|
});
|
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');
|
2024-01-31 03:37:34 -05:00
|
|
|
assert.equal(h.textContent, 'Testing');
|
2023-08-31 10:31:01 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not get a invalid hook call warning', () => {
|
|
|
|
const errors = unhook();
|
2024-01-31 03:37:34 -05:00
|
|
|
assert.equal(errors.length === 0, true);
|
2023-08-31 10:31:01 -05:00
|
|
|
});
|
2022-08-05 16:13:30 -05:00
|
|
|
});
|