mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
3ab3b4efbc
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { before, describe, it } from 'node:test';
|
|
import { createMarkdownProcessor } from '../dist/index.js';
|
|
|
|
describe('collect images', async () => {
|
|
let processor;
|
|
|
|
before(async () => {
|
|
processor = await createMarkdownProcessor();
|
|
});
|
|
|
|
it('should collect inline image paths', async () => {
|
|
const markdown = `Hello ![inline image url](./img.png)`;
|
|
const fileURL = 'file.md';
|
|
|
|
const {
|
|
code,
|
|
metadata: { imagePaths },
|
|
} = await processor.render(markdown, { fileURL });
|
|
|
|
assert.equal(
|
|
code,
|
|
'<p>Hello <img __ASTRO_IMAGE_="{"src":"./img.png","alt":"inline image url","index":0}"></p>',
|
|
);
|
|
|
|
assert.deepEqual(imagePaths, ['./img.png']);
|
|
});
|
|
|
|
it('should add image paths from definition', async () => {
|
|
const markdown = `Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`;
|
|
const fileURL = 'file.md';
|
|
|
|
const { code, metadata } = await processor.render(markdown, { fileURL });
|
|
|
|
assert.equal(
|
|
code,
|
|
'<p>Hello <img __ASTRO_IMAGE_="{"src":"./img.webp","alt":"image ref","index":0}"></p>',
|
|
);
|
|
|
|
assert.deepEqual(metadata.imagePaths, ['./img.webp']);
|
|
});
|
|
});
|