/* eslint-disable import/no-extraneous-dependencies */ import { expect } from 'chai'; import path from 'path'; import mdStringify from 'remark-html'; import markdown from 'remark-parse'; import unified from 'unified'; import { fileURLToPath } from 'url'; import { remarkUrlToLocal } from '../src/remarkUrlToLocal.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); /** * @param {string} input * @returns */ async function execute(input) { const rootDir = path.join(__dirname, '../../../'); const parser = unified() // .use(markdown) .use(remarkUrlToLocal, { gitHubUrl: 'https://github.com/ing-bank/lion/', rootDir, page: { inputPath: path.join(rootDir, 'docs/components/form/overview/index.md'), }, }) .use(mdStringify); const result = await parser.process(input); return result.contents.toString().trim(); } describe('remarkUrlToLocal', () => { it('convert urls to local', async () => { const result = await execute( 'Since it extends from [fieldset](https://github.com/ing-bank/lion/blob/6f2b6f940a0875091f1d940f45f0cd32dffce9ac/docs/components/fieldset/overview.md)', ); expect(result).to.equal( '
Since it extends from fieldset
', ); }); it('does not touch issue urls', async () => { const result = await execute('see [explanation](https://github.com/ing-bank/lion/issues/591)'); expect(result).to.equal( 'see explanation
', ); }); it('does not touch urls to the repo', async () => { const result = await execute('see [explanation](https://github.com/ing-bank/lion/)'); expect(result).to.equal( 'see explanation
', ); }); it('works with images', async () => { const result = await execute( `see `, ); expect(result).to.equal( 'see