diff --git a/README.md b/README.md index dfc9c44..7e4d90e 100644 --- a/README.md +++ b/README.md @@ -54,27 +54,26 @@ _Returns:_ `void` _Examples:_ ```ts - // x.ts - export const x = (y: boolean, z: number, w: number):number|null => y ? z + w : null; - - // x.spec.ts - import x from 'x.ts' - import { jestFunctionSignatureTest } from '@wezom/toolkit-jest' - - describe('Function signature should match specification', () => { - jestFunctionSignatureTest(x, [ - { - parameters: [true, 4, 5], - expected: 9 - }, - { - name: 'Custom test name' - parameters: [false, 4, 5], - expected: null - } - ]); - }); - +// x.ts +export const x = (y: boolean, z: number, w: number): number | null => (y ? z + w : null); + +// x.spec.ts +import x from 'x.ts'; +import { jestFunctionSignatureTest } from '@wezom/toolkit-jest'; + +describe('Function signature should match specification', () => { + jestFunctionSignatureTest(x, [ + { + parameters: [true, 4, 5], + expected: 9 + }, + { + name: 'Custom test name', + parameters: [false, 4, 5], + expected: null + } + ]); +}); ``` [comment]: <> (AUTODOC-TOOL-END) diff --git a/package-lock.json b/package-lock.json index 5c7f59f..69b64c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@wezom/toolkit-jest", - "version": "3.1.0", + "version": "3.1.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 4337285..bc058d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@wezom/toolkit-jest", - "version": "3.1.0", + "version": "3.1.1", "description": "Useful tools for working with Jest", "main": "dist/index.js", "files": [ diff --git a/src/function-signature-test.ts b/src/function-signature-test.ts index 243ecdd..deb7091 100644 --- a/src/function-signature-test.ts +++ b/src/function-signature-test.ts @@ -15,7 +15,7 @@ * expected: 9 * }, * { - * name: 'Custom test name' + * name: 'Custom test name', * parameters: [false, 4, 5], * expected: null * } diff --git a/utils/autodoc-ts-tool.js b/utils/autodoc-ts-tool.js index 0df2e3d..49619a2 100644 --- a/utils/autodoc-ts-tool.js +++ b/utils/autodoc-ts-tool.js @@ -12,7 +12,7 @@ const _code = (value, isRest) => const _trimCode = (value) => value.replace(/^`|`$/g, ''); const _trimAllCode = (value) => value.replace(/`/g, ''); const _parseTrimJoin = (arr, joiner) => arr.map(_parseType).map(_trimCode).join(joiner); -const _parseType = (docType, { isRest } = {}) => { +const _parseType = (docType, { isRest, inTable } = {}) => { switch (docType.type) { case 'intrinsic': return _code(docType.name, isRest); @@ -25,10 +25,12 @@ const _parseType = (docType, { isRest } = {}) => { } return _code(docType.name, isRest); case 'array': - const _type = _parseType(docType.elementType, { isRest }); + const _type = _parseType(docType.elementType, { isRest, inTable }); return _type ? _code(_trimCode(_type) + '[]') : _type; case 'reflection': - return _code(_trimAllCode(_parseReflection(docType.declaration, true))); + return _code( + _trimAllCode(_parseReflection(docType.declaration, inTable === true)) + ); case 'intersection': return _code(_parseTrimJoin(docType.types, ' & '), isRest); case 'union': @@ -99,7 +101,8 @@ const newToolsFileContent = toolsFileContent.replace(regExp, (str, g1, g2, g3, g .map((parameter) => { const { flags = {}, comment = {}, type = {} } = parameter; const dataType = _parseType(type, { - isRest: flags.isRest + isRest: flags.isRest, + inTable: true }); return ( '| ' + @@ -120,7 +123,13 @@ const newToolsFileContent = toolsFileContent.replace(regExp, (str, g1, g2, g3, g let returnType = _parseType(rType); if (returnType) { - returnType = '_Returns:_ ' + returnType; + if (returnType.includes('\n')) { + returnType = `_Returns:_\n\n\`\`\`ts\n${_trimAllCode( + returnType + )}\n\`\`\``; + } else { + returnType = '_Returns:_ ' + returnType; + } } blocks.push(