mdx-page.test.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { describe, it, before, after } from 'node:test';
  2. import * as assert from 'node:assert/strict';
  3. import { parseHTML } from 'linkedom';
  4. import { loadFixture } from '../../../astro/test/test-utils.js';
  5. describe('MDX Page', () => {
  6. let fixture;
  7. before(async () => {
  8. fixture = await loadFixture({
  9. root: new URL('./fixtures/mdx-page/', import.meta.url),
  10. // test suite was authored when inlineStylesheets defaulted to never
  11. build: { inlineStylesheets: 'never' },
  12. });
  13. });
  14. describe('build', () => {
  15. before(async () => {
  16. await fixture.build();
  17. });
  18. it('works', async () => {
  19. const html = await fixture.readFile('/index.html');
  20. const { document } = parseHTML(html);
  21. const h1 = document.querySelector('h1');
  22. assert.equal(h1.textContent, 'Hello page!');
  23. });
  24. it('injects style imports when layout is not applied', async () => {
  25. const html = await fixture.readFile('/index.html');
  26. const { document } = parseHTML(html);
  27. const stylesheet = document.querySelector('link[rel="stylesheet"]');
  28. assert.notEqual(stylesheet, null);
  29. });
  30. });
  31. describe('dev', () => {
  32. let devServer;
  33. before(async () => {
  34. devServer = await fixture.startDevServer();
  35. });
  36. after(async () => {
  37. await devServer.stop();
  38. });
  39. it('works', async () => {
  40. const res = await fixture.fetch('/');
  41. assert.equal(res.status, 200);
  42. const html = await res.text();
  43. const { document } = parseHTML(html);
  44. const h1 = document.querySelector('h1');
  45. assert.equal(h1.textContent, 'Hello page!');
  46. });
  47. });
  48. });