2024-02-12 07:25:29 -05:00
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { describe, it } from 'node:test';
|
2022-05-24 17:02:11 -05:00
|
|
|
import { fileURLToPath } from 'node:url';
|
2023-09-14 05:22:16 -05:00
|
|
|
import { createMarkdownProcessor } from '../dist/index.js';
|
2022-05-24 17:02:11 -05:00
|
|
|
|
|
|
|
describe('plugins', () => {
|
|
|
|
it('should be able to get file path when passing fileURL', async () => {
|
|
|
|
let context;
|
2023-09-14 05:22:16 -05:00
|
|
|
|
|
|
|
const processor = await createMarkdownProcessor({
|
2022-05-24 17:02:11 -05:00
|
|
|
remarkPlugins: [
|
2024-02-12 07:25:29 -05:00
|
|
|
() => {
|
2022-05-24 17:02:11 -05:00
|
|
|
const transformer = (tree, file) => {
|
|
|
|
context = file;
|
|
|
|
};
|
|
|
|
return transformer;
|
2022-05-24 17:03:29 -05:00
|
|
|
},
|
|
|
|
],
|
2022-05-24 17:02:11 -05:00
|
|
|
});
|
|
|
|
|
2023-09-14 05:22:16 -05:00
|
|
|
await processor.render(`test`, {
|
|
|
|
fileURL: new URL('virtual.md', import.meta.url),
|
|
|
|
});
|
|
|
|
|
2024-02-12 07:25:29 -05:00
|
|
|
assert.ok(typeof context === 'object');
|
|
|
|
assert.equal(context.path, fileURLToPath(new URL('virtual.md', import.meta.url)));
|
2022-05-24 17:02:11 -05:00
|
|
|
});
|
2022-05-24 17:03:29 -05:00
|
|
|
});
|