summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/remark-imgattr.test.js
blob: ebd9207b26ada7753855c4424a41b331dce2fbff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from '../../../astro/test/test-utils.js';

const FIXTURE_ROOT = new URL('./fixtures/image-remark-imgattr/', import.meta.url);

describe('Testing remark plugins for image processing', () => {
	/** @type {import('./test-utils').Fixture} */
	let fixture;

	describe('start dev server', () => {
		/** @type {import('./test-utils').DevServer} */
		let devServer;

		before(async () => {
			fixture = await loadFixture({
				root: FIXTURE_ROOT,
			});

			devServer = await fixture.startDevServer();
		});

		after(async () => {
			await devServer.stop();
		});

		describe('Test image attributes can be added by remark plugins', () => {
			let $;
			before(async () => {
				let res = await fixture.fetch('/');
				let html = await res.text();
				$ = cheerio.load(html);
			});

			it('<img> has correct attributes', async () => {
				let $img = $('img');
				assert.equal($img.attr('id'), 'test');
				assert.equal($img.attr('sizes'), '(min-width: 600px) 600w, 300w');
				assert.ok($img.attr('srcset'));
			});

			it('<img> was processed properly', async () => {
				let $img = $('img');
				assert.equal(new URL($img.attr('src'), 'http://example.com').searchParams.get('w'), '300');
			});
		});
	});
});