2023-09-14 10:22:16 +00:00
|
|
|
import { createMarkdownProcessor } from '../dist/index.js';
|
2022-05-24 22:02:11 +00:00
|
|
|
import chai from 'chai';
|
|
|
|
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
|
|
|
|
describe('plugins', () => {
|
|
|
|
// https://github.com/withastro/astro/issues/3264
|
|
|
|
it('should be able to get file path when passing fileURL', async () => {
|
|
|
|
let context;
|
2023-09-14 10:22:16 +00:00
|
|
|
|
|
|
|
const processor = await createMarkdownProcessor({
|
2022-05-24 22:02:11 +00:00
|
|
|
remarkPlugins: [
|
|
|
|
function () {
|
|
|
|
const transformer = (tree, file) => {
|
|
|
|
context = file;
|
|
|
|
};
|
|
|
|
|
|
|
|
return transformer;
|
2022-05-24 22:03:29 +00:00
|
|
|
},
|
|
|
|
],
|
2022-05-24 22:02:11 +00:00
|
|
|
});
|
|
|
|
|
2023-09-14 10:22:16 +00:00
|
|
|
await processor.render(`test`, {
|
|
|
|
fileURL: new URL('virtual.md', import.meta.url),
|
|
|
|
});
|
|
|
|
|
2022-05-24 22:02:11 +00:00
|
|
|
chai.expect(typeof context).to.equal('object');
|
|
|
|
chai.expect(context.path).to.equal(fileURLToPath(new URL('virtual.md', import.meta.url)));
|
|
|
|
});
|
2022-05-24 22:03:29 +00:00
|
|
|
});
|