mdx-namespace.test.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 Namespace', () => {
  6. let fixture;
  7. before(async () => {
  8. fixture = await loadFixture({
  9. root: new URL('./fixtures/mdx-namespace/', import.meta.url),
  10. });
  11. });
  12. describe('build', () => {
  13. before(async () => {
  14. await fixture.build();
  15. });
  16. it('works for object', async () => {
  17. const html = await fixture.readFile('/object/index.html');
  18. const { document } = parseHTML(html);
  19. const island = document.querySelector('astro-island');
  20. const component = document.querySelector('#component');
  21. assert.notEqual(island, undefined);
  22. assert.equal(component.textContent, 'Hello world');
  23. });
  24. it('works for star', async () => {
  25. const html = await fixture.readFile('/star/index.html');
  26. const { document } = parseHTML(html);
  27. const island = document.querySelector('astro-island');
  28. const component = document.querySelector('#component');
  29. assert.notEqual(island, undefined);
  30. assert.equal(component.textContent, 'Hello world');
  31. });
  32. });
  33. describe('dev', () => {
  34. let devServer;
  35. before(async () => {
  36. devServer = await fixture.startDevServer();
  37. });
  38. after(async () => {
  39. await devServer.stop();
  40. });
  41. it('works for object', async () => {
  42. const res = await fixture.fetch('/object');
  43. assert.equal(res.status, 200);
  44. const html = await res.text();
  45. const { document } = parseHTML(html);
  46. const island = document.querySelector('astro-island');
  47. const component = document.querySelector('#component');
  48. assert.notEqual(island, undefined);
  49. assert.equal(component.textContent, 'Hello world');
  50. });
  51. it('works for star', async () => {
  52. const res = await fixture.fetch('/star');
  53. assert.equal(res.status, 200);
  54. const html = await res.text();
  55. const { document } = parseHTML(html);
  56. const island = document.querySelector('astro-island');
  57. const component = document.querySelector('#component');
  58. assert.notEqual(island, undefined);
  59. assert.equal(component.textContent, 'Hello world');
  60. });
  61. });
  62. });