summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/test/remark-collect-images.test.js
blob: d5c743e20d6b21dd7694a867053b4c7b58f0b7ae (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
import { renderMarkdown } from '../dist/index.js';
import { mockRenderMarkdownParams } from './test-utils.js';
import chai from 'chai';

describe('collect images', () => {
	it('should collect inline image paths', async () => {
		const { code, vfile } = await renderMarkdown(
			`Hello ![inline image url](./img.png)`,
			mockRenderMarkdownParams
		);

		chai
			.expect(code)
			.to.equal('<p>Hello <img alt="inline image url" __ASTRO_IMAGE_="./img.png"></p>');

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

	it('should add image paths from definition', async () => {
		const { code, vfile } = await renderMarkdown(
			`Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`,
			mockRenderMarkdownParams
		);

		chai.expect(code).to.equal('<p>Hello <img alt="image ref" __ASTRO_IMAGE_="./img.webp"></p>');
		chai.expect(Array.from(vfile.data.imagePaths)).to.deep.equal(['./img.webp']);
	});
});