0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/markdown/remark/test/remark-collect-images.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
JavaScript
Raw Normal View History

import { createMarkdownProcessor } from '../dist/index.js';
import chai from 'chai';
describe('collect images', async () => {
2024-01-17 08:14:53 -05:00
const processor = await createMarkdownProcessor();
2024-01-17 08:14:53 -05:00
it('should collect inline image paths', async () => {
const {
code,
metadata: { imagePaths },
} = await processor.render(`Hello ![inline image url](./img.png)`, {
fileURL: 'file.md',
});
2024-01-17 08:14:53 -05:00
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>'
);
2024-01-17 08:14:53 -05:00
chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.png']);
});
2024-01-17 08:14:53 -05:00
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',
});
2024-01-17 08:14:53 -05:00
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']);
});
});