Skip to content

Commit

Permalink
Merge pull request #3 from WezomCompany/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
OlehDutchenko authored Mar 7, 2021
2 parents 3ad70ce + 75220ec commit bedeef7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 29 deletions.
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion src/function-signature-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* expected: 9
* },
* {
* name: 'Custom test name'
* name: 'Custom test name',
* parameters: [false, 4, 5],
* expected: null
* }
Expand Down
19 changes: 14 additions & 5 deletions utils/autodoc-ts-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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':
Expand Down Expand Up @@ -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 (
'| ' +
Expand All @@ -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(
Expand Down

0 comments on commit bedeef7

Please sign in to comment.