diff --git a/bin/__tests__/react-docgen-test.js b/bin/__tests__/react-docgen-test.js index e7fc35fd432..3d43f299729 100644 --- a/bin/__tests__/react-docgen-test.js +++ b/bin/__tests__/react-docgen-test.js @@ -198,7 +198,6 @@ describe('react-docgen CLI', () => { }, TEST_TIMEOUT, ); - it( 'writes to stdout', () => { diff --git a/package.json b/package.json index cd5d87206ad..c7e2e31bc82 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "doctrine": "^3.0.0", "neo-async": "^2.6.1", "node-dir": "^0.1.10", + "resolve": "^1.17.0", "strip-indent": "^3.0.0" }, "devDependencies": { diff --git a/src/__tests__/__snapshots__/main-test.js.snap b/src/__tests__/__snapshots__/main-test.js.snap index 30c6605c57d..99041fe6d4f 100644 --- a/src/__tests__/__snapshots__/main-test.js.snap +++ b/src/__tests__/__snapshots__/main-test.js.snap @@ -1008,9 +1008,6 @@ Object { exports[`main fixtures processes component "component_19.js" without errors 1`] = ` Object { - "composes": Array [ - undefined, - ], "description": "", "displayName": "Component", "methods": Array [], @@ -1577,3 +1574,326 @@ Object { }, } `; + +exports[`main fixtures processes component "component_33.tsx" without errors 1`] = ` +Object { + "description": "This is a typescript component with imported prop types", + "displayName": "ImportedExtendedComponent", + "methods": Array [], + "props": Object { + "bar": Object { + "description": "", + "required": true, + "tsType": Object { + "name": "number", + }, + }, + "foo": Object { + "description": "", + "required": true, + "tsType": Object { + "name": "string", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_34.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "CustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "color": Object { + "description": "", + "required": false, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_35.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperCustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_36.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperDuperCustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_37.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperDuperCustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_38.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperDuperCustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_39.tsx" without errors 1`] = ` +Object { + "description": "This is a typescript component with imported prop types", + "displayName": "ImportedComponent", + "methods": Array [], + "props": Object { + "foo": Object { + "description": "", + "required": true, + "tsType": Object { + "name": "string", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_40.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperDuperCustomButton", + "methods": Array [], + "props": Object { + "size": Object { + "defaultValue": Object { + "computed": true, + "value": "Sizes.EXTRA_LARGE", + }, + "description": "", + "required": false, + "type": Object { + "computed": true, + "name": "enum", + "value": "Object.values(Sizes)", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "flow-export-type.js" without errors 1`] = ` +Object { + "description": "This is a Flow class component", + "displayName": "FlowComponent", + "methods": Array [ + Object { + "docblock": null, + "modifiers": Array [], + "name": "foo", + "params": Array [ + Object { + "name": "a", + "optional": undefined, + "type": Object { + "name": "string", + }, + }, + ], + "returns": Object { + "type": Object { + "name": "string", + }, + }, + }, + Object { + "docblock": null, + "modifiers": Array [], + "name": "bar", + "params": Array [ + Object { + "name": "a", + "optional": undefined, + "type": Object { + "name": "string", + }, + }, + ], + "returns": Object { + "type": Object { + "name": "string", + }, + }, + }, + ], + "props": Object { + "foo": Object { + "description": "", + "flowType": Object { + "name": "string", + }, + "required": true, + }, + }, +} +`; + +exports[`main fixtures processes component "flow-import-type.js" without errors 1`] = ` +Object { + "description": "This is a Flow component with imported prop types", + "displayName": "ImportedComponent", + "methods": Array [], + "props": Object { + "foo": Object { + "description": "", + "flowType": Object { + "name": "string", + }, + "required": true, + }, + }, +} +`; + +exports[`main fixtures processes component "flow-spread-import-type.js" without errors 1`] = ` +Object { + "description": "This is a Flow component with imported prop types", + "displayName": "ImportedExtendedComponent", + "methods": Array [], + "props": Object { + "bar": Object { + "description": "", + "flowType": Object { + "name": "number", + }, + "required": true, + }, + "foo": Object { + "description": "", + "flowType": Object { + "name": "string", + }, + "required": true, + }, + }, +} +`; diff --git a/src/__tests__/fixtures/component_27.tsx b/src/__tests__/fixtures/component_27.tsx index ea49e8b716d..eb5cc2f3fed 100644 --- a/src/__tests__/fixtures/component_27.tsx +++ b/src/__tests__/fixtures/component_27.tsx @@ -8,7 +8,7 @@ import React, { Component } from 'react'; -interface Props { +export interface Props { foo: string } diff --git a/src/__tests__/fixtures/component_33.tsx b/src/__tests__/fixtures/component_33.tsx new file mode 100644 index 00000000000..0be4a2226a9 --- /dev/null +++ b/src/__tests__/fixtures/component_33.tsx @@ -0,0 +1,17 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +import React, { Component } from 'react'; +import ExtendedProps from './component_39'; + +/** + * This is a typescript component with imported prop types + */ +export function ImportedExtendedComponent(props: ExtendedProps) { + return

Hello world

; +} diff --git a/src/__tests__/fixtures/component_34.js b/src/__tests__/fixtures/component_34.js new file mode 100644 index 00000000000..4b227a5bc62 --- /dev/null +++ b/src/__tests__/fixtures/component_34.js @@ -0,0 +1,13 @@ +import Button from './component_6'; +import PropTypes from 'prop-types'; + +export function CustomButton({color, ...otherProps}) { + return