aboutsummaryrefslogtreecommitdiff
path: root/packages/markdown/remark/test/remark-collect-images.test.js
blob: 259bea96e31048a5fed7f2d2ce4392c1d6412311 (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
import { createMarkdownProcessor } from '../dist/index.js';
import chai from 'chai';

describe('collect images', async () => {
	const processor = await createMarkdownProcessor();

	it('should collect inline image paths', async () => {
		const {
			code,
			metadata: { imagePaths },
		} = await processor.render(`Hello ![inline image url](./img.png)`, {
			fileURL: 'file.md',
		});

		chai
			.expect(code)
			.to.equal(
				'<p>Hello <img __ASTRO_IMAGE_="{&#x22;src&#x22;:&#x22;./img.png&#x22;,&#x22;alt&#x22;:&#x22;inline image url&#x22;,&#x22;index&#x22;:0}"></p>'
			);

		chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.png']);
	});

	it('should add image paths from definition', async () => {
		const {
			code,
			metadata: { imagePaths },
		} = await processor.render(`Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`, {
			fileURL: 'file.md',
		});

		chai
			.expect(code)
			.to.equal(
				'<p>Hello <img __ASTRO_IMAGE_="{&#x22;src&#x22;:&#x22;./img.webp&#x22;,&#x22;alt&#x22;:&#x22;image ref&#x22;,&#x22;index&#x22;:0}"></p>'
			);
		chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.webp']);
	});
});