remark-imgattr.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { describe, it, before, after } from 'node:test';
  2. import * as assert from 'node:assert/strict';
  3. import * as cheerio from 'cheerio';
  4. import { loadFixture } from '../../../astro/test/test-utils.js';
  5. const FIXTURE_ROOT = new URL('./fixtures/image-remark-imgattr/', import.meta.url);
  6. describe('Testing remark plugins for image processing', () => {
  7. /** @type {import('./test-utils').Fixture} */
  8. let fixture;
  9. describe('start dev server', () => {
  10. /** @type {import('./test-utils').DevServer} */
  11. let devServer;
  12. before(async () => {
  13. fixture = await loadFixture({
  14. root: FIXTURE_ROOT,
  15. });
  16. devServer = await fixture.startDevServer();
  17. });
  18. after(async () => {
  19. await devServer.stop();
  20. });
  21. describe('Test image attributes can be added by remark plugins', () => {
  22. let $;
  23. before(async () => {
  24. let res = await fixture.fetch('/');
  25. let html = await res.text();
  26. $ = cheerio.load(html);
  27. });
  28. it('<img> has correct attributes', async () => {
  29. let $img = $('img');
  30. assert.equal($img.attr('id'), 'test');
  31. assert.equal($img.attr('sizes'), '(min-width: 600px) 600w, 300w');
  32. assert.ok($img.attr('srcset'));
  33. });
  34. it('<img> was processed properly', async () => {
  35. let $img = $('img');
  36. assert.equal(new URL($img.attr('src'), 'http://example.com').searchParams.get('w'), '300');
  37. });
  38. });
  39. });
  40. });