const parallelPromise = require('./lib/parallelPromise')
const getMarkdown = require('./lib/getMarkdown')
const getArticles = require('./lib/getArticles')
module.exports = {
'/': (params) => [
'start',
() => new Promise((resolve, reject) => {
parallelPromise([
getMarkdown('start'),
getMarkdown('skills'),
getMarkdown('references')
])
.then((mdArr) => {
resolve({ sections: mdArr.map((md) => md[0].html) })
})
.catch(reject)
})
],
'/projects': (params) => [
'projects',
() => new Promise((resolve, reject) => {
getMarkdown('projects/*')
.then((mdArr) => resolve({ projects: mdArr.map((md) => md.html) }))
.catch(reject)
})
],
'/anotherblog': (params) => [
'blog',
() => new Promise((resolve, reject) => {
getArticles('blog')
.then((articles) => resolve({ articles }))
.catch(reject)
})
],
'/anotherblog/:article': (params) => [
'blogArticle',
() => new Promise((resolve, reject) => {
getArticles('blog')
.then((articles) =>
resolve(articles.filter((el) => el.name === params.article)[0])
)
.catch(reject)
}),
`blogArticle/${params.article}`
],
'/ipa': (params) => [
'generic',
() => new Promise((resolve, reject) => {
getMarkdown('dispo_interaktiver_news_artikel')
.then((md) => resolve({
title: 'Interaktiver News-Artikel',
generic: md[0].html
}))
.catch(reject)
}),
'ipa'
],
'/peopleidliketoworkwith': (params) => [
'generic',
() => new Promise((resolve, reject) => {
getMarkdown('peopleidliketoworkwith')
.then((md) => resolve({
title: 'peopleidliketoworkwith',
generic: md[0].html
}))
.catch(reject)
})
],
'/blacklist': (params) => [
'generic',
() => new Promise((resolve, reject) => {
resolve({
title: 'blacklist',
generic: 'YOLO'
})
})
]
}
import documentation from 'documentation';
import buildMarkdown from './';
function getMarkdown(documentationSource, args) {
return documentation
.build([{ source: documentationSource }], { shallow: true })
.then(comments => buildMarkdown(comments, args));
}
describe('buildMarkdown', () => {
describe('for class', () => {
it('should render markdown for class with constructor', async () => {
const documentationSource = `
/**
* Component description
*
* @example
* new Component({visible: true})
*/
class Component {
/**
* creates new Component
*/
constructor(config: any) {}
/**
* show
*/
show() {}
}
`;
const markdown = await getMarkdown(documentationSource);
expect(markdown).toMatchSnapshot();
});
});
describe('for API class', () => {
const title = 'API Methods';
it('should render markdown for getters/setters', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* \`isVisible\` getter comment
*/
get isVisible(): boolean {
return true;
}
/**
* \`width\` setter comment
*/
set width(value: number) {
console.log(value)
}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods default value', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* myMethod comment
* @param [x=''] - \`x\` description
*
*/
myMethod(x: string) {}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with @returns comment', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* myMethod comment
* @param x - \`x\` description
*
* @returns returns comment
*/
myMethod(x: string): string {
return x;
}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with UnionType with literals as @param type', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* myMethod comment
* @param y - \`y\` comment
*/
myMethod(y: 'bla' | 'not bla' | 7 | null) {
return y;
}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with UnionType with NOT literal as @param type', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* myMethod comment
* @param y - \`y\` comment
*/
myMethod(y: number | null) {
return y;
}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with @example end @note', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* myMethod comment
* @param x - \`x\` description. see http://example.com
*
* @note
* \`myMethod\` note 1
*
* @example <caption>test example caption</caption>
* console.log('example')
*
* @example
* console.log('example')
*
* @note
* \`myMethod\` note 2
* Read more about [myMethod](/my-method)
*
*/
myMethod(x: string): string {
return x;
}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with @deprecated', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* show component
* @deprecated use method \`show()\`
*/
doShow() {}
/**
* show component
*/
show() {}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with `...rest` as param', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* myMethod comment
*/
myMethod(...arr: string[]): string[] {
return arr;
}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with `optional` as param', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* myMethod comment
*/
myMethod(x: ?number): number {
return number;
}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods interface as return type', async () => {
const documentationSource = `
/**
* MyResult interface
* @property a - \`a\` description
* @property b - \`b\` description
*/
interface MyResult {
a: string;
b?: number;
}
/** Example class jsdoc */
class API {
/**
* myMethod comment
* @param y - \`y\` comment
*/
myMethod(y: 'bla' | 'not bla'): MyResult {
return y;
}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown sections in valid order', async () => {
const documentationSource = `
/** Example class jsdoc */
class API {
/**
* myMethod1 comment
* @param x - \`x\` description
*
* @example <caption>test example caption</caption>
* console.log('example')
* @note
* \`myMethod1\` note
* Read more about [myMethod](/my-method)
*
* @returns returns comment
*/
myMethod1(x: string): string {
return x;
}
/**
* myMethod2 comment
* @param y - y comment
*
* @example
* console.log('example')
*/
myMethod2(y: 'bla' | 'not bla'): string {
return y;
}
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
});
describe('for functions', async () => {
const title = 'Functions';
it('should render valid markdown', async () => {
const documentationSource = `
/**
* MyFuncResult interface
* @property a - \`a\` description
* @property b - \`b\` description
*/
interface MyFuncResult {
a: string;
b: number;
}
/**
* myFunc1 description
* @param x - \`x\` description
*/
function myFunc1(x: number): number {}
/**
* myFunc2 description
* @param x - \`x\` description
* @param y - \`y\` description
*
* @example <caption>MyFunc example</caption>
*
* console.log(myFunc(3, 2))
* // {a: '3', b: 2}
*/
function myFunc2(x: number, y:number): MyFuncResult {}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render valid markdown with function as argument', async () => {
const documentationSource = `
/**
* @param name - event name
* @param fn - event handler
*/
function myFunc(name: string, fn: (name: string, data: Object) => any) {}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render valid markdown with UnionType in TypeApplication as argument', async () => {
const documentationSource = `
/**
* @param fn - event handler
*/
function myFunc(fn: (value: string | null) => void) {}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render valid markdown with function as return type', async () => {
const documentationSource = `
/**
* @returns myFunc result function
*/
function myFunc(): (flag: boolean) => void {}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render valid markdown with function in return type interface', async () => {
const documentationSource = `
/**
* @property update - update entity
* @property destroy - destroy entity
*/
interface MyEntity {
id: string;
title: string;
updateTitle(id: string, title: string): Promise<any>;
destroy(): void;
}
/**
* create new entity
* @param title - entity title
* @returns new entity
*/
function create(title: string): MyEntity {}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
});
describe('with ApplicationType as return type', () => {
const title = 'API Methods';
it('should render markdown for methods with Promise as @returns type', async () => {
const documentationSource = `
/**
* @returns returns comment
*/
function myFn(): Promise<string> {
return x;
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with Promise & interface as @returns type', async () => {
const documentationSource = `
/** */
interface IResult {
x: number;
y: number;
}
/**
* @returns returns comment
*/
function myFn(): Promise<IResult> {
return {x: 1, y: 1};
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with Array as @returns type', async () => {
const documentationSource = `
/**
* @returns returns comment
*/
function myFn(): string[] {
return [''];
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
it('should render markdown for methods with Array & interface as @returns type', async () => {
const documentationSource = `
/** */
interface IResult {
x: number;
y: number;
}
/**
* @returns returns comment
*/
function myFn(): IResult[] {
return [{x: 1, y: 1}];
}
`;
const markdown = await getMarkdown(documentationSource, { title });
expect(markdown).toMatchSnapshot();
});
});
});
import React from 'react';
import JsDoc, { getMarkdown } from './JsDoc';
const tags = {
deprecated: [
{
title: 'description',
description: 'Use *another* method',
},
],
version: [
{
title: 'version',
description: '2.0.0',
},
],
since: [
{
title: 'since',
description: '1.0.0',
},
],
author: [
{
title: 'author',
description: '[Author 1](#TestLink)',
},
{
title: 'author',
description: '[Author 2](#TestLink2)',
},
],
see: [
{
title: 'see',
description: '[See 1](#TestLink)',
},
{
title: 'see',
description: '[See 2](#TestLink2)',
},
],
link: [
{
title: 'link',
description: '[Link 1](#TestLink)',
},
],
};
describe('getMarkdown', () => {
it('should return Markdown for all tags', () => {
const result = getMarkdown(tags);
expect(result).toMatchSnapshot();
});
it('should return Markdown for one author', () => {
const result = getMarkdown({
author: [tags.author[0]],
});
expect(result).toMatchSnapshot();
});
it('should return Markdown for multiple authors', () => {
const result = getMarkdown({
author: tags.author,
});
expect(result).toMatchSnapshot();
});
});
describe('JsDoc', () => {
it('should render Markdown', () => {
const actual = shallow(<JsDoc {...tags} />);
expect(actual).toMatchSnapshot();
});
it('should render null for empty tags', () => {
const actual = shallow(<JsDoc />);
expect(actual.getElement()).toBe(null);
});
});
Accelerate Your Automation Test Cycles With LambdaTest
Leverage LambdaTestās cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.