71 lines
2.3 KiB
JavaScript
71 lines
2.3 KiB
JavaScript
/* eslint-disable import/no-extraneous-dependencies */
|
|
import chai 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 { expect } = chai;
|
|
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(
|
|
'<p>Since it extends from <a href="../../fieldset/overview.md">fieldset</a></p>',
|
|
);
|
|
});
|
|
|
|
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(
|
|
'<p>see <a href="https://github.com/ing-bank/lion/issues/591">explanation</a></p>',
|
|
);
|
|
});
|
|
|
|
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(
|
|
'<p>see <a href="https://github.com/ing-bank/lion/">explanation</a></p>',
|
|
);
|
|
});
|
|
|
|
it('works with images', async () => {
|
|
const result = await execute(
|
|
`see `,
|
|
);
|
|
|
|
expect(result).to.equal(
|
|
'<p>see <img src="../../../fundamentals/systems/form/assets/FormatMixinDiagram-1.svg" alt="Standard flow" title="Standard flow"></p>',
|
|
);
|
|
});
|
|
});
|