2020-11-15 05:14:09 -05:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
|
2021-11-03 14:56:36 -05:00
|
|
|
import { parseReadme } from '../src/utils/web-utils';
|
2020-03-03 17:59:19 -05:00
|
|
|
|
2020-11-15 05:14:09 -05:00
|
|
|
const readmeFile = (fileName = 'markdown.md') => {
|
|
|
|
return fs.readFileSync(path.join(__dirname, `./partials/readme/${fileName}`));
|
|
|
|
};
|
|
|
|
|
2020-03-03 17:59:19 -05:00
|
|
|
describe('Utilities', () => {
|
2020-11-15 05:14:09 -05:00
|
|
|
describe('parseReadme', () => {
|
|
|
|
test('should parse makrdown text to html template', () => {
|
|
|
|
const markdown = '# markdown';
|
|
|
|
expect(parseReadme('testPackage', markdown)).toEqual('<h1 id="markdown">markdown</h1>');
|
|
|
|
// @ts-ignore
|
|
|
|
expect(parseReadme('testPackage', String(readmeFile('markdown.md')))).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should pass for conversion of non-ascii to markdown text', () => {
|
|
|
|
const simpleText = 'simple text';
|
|
|
|
const randomText = '%%%%%**##==';
|
|
|
|
const randomTextMarkdown = 'simple text \n # markdown';
|
|
|
|
|
|
|
|
expect(parseReadme('testPackage', randomText)).toEqual('<p>%%%%%**##==</p>');
|
|
|
|
expect(parseReadme('testPackage', simpleText)).toEqual('<p>simple text</p>');
|
|
|
|
expect(parseReadme('testPackage', randomTextMarkdown)).toEqual(
|
|
|
|
'<p>simple text </p>\n<h1 id="markdown">markdown</h1>'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should show error for no readme data', () => {
|
|
|
|
const noData = '';
|
|
|
|
expect(() => parseReadme('testPackage', noData)).toThrowError('ERROR: No README data found!');
|
|
|
|
});
|
|
|
|
});
|
2020-03-03 17:59:19 -05:00
|
|
|
});
|