plugins.test.js 736 B

12345678910111213141516171819202122232425262728
  1. import assert from 'node:assert/strict';
  2. import { describe, it } from 'node:test';
  3. import { createMarkdownProcessor } from '../dist/index.js';
  4. import { fileURLToPath } from 'node:url';
  5. describe('plugins', () => {
  6. it('should be able to get file path when passing fileURL', async () => {
  7. let context;
  8. const processor = await createMarkdownProcessor({
  9. remarkPlugins: [
  10. () => {
  11. const transformer = (tree, file) => {
  12. context = file;
  13. };
  14. return transformer;
  15. },
  16. ],
  17. });
  18. await processor.render(`test`, {
  19. fileURL: new URL('virtual.md', import.meta.url),
  20. });
  21. assert.ok(typeof context === 'object');
  22. assert.equal(context.path, fileURLToPath(new URL('virtual.md', import.meta.url)));
  23. });
  24. });