Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

chore(docgen): remove constructorName property #587

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions build/gulp/plugins/util/getComponentInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ const getComponentInfo = (filepath: string, checksum?: string) => {
// add checksum
info.checksum = checksum

// add exported Component info
const Component = require(absPath).default
info.constructorName = _.get(Component, 'prototype.constructor.name', null)

// add component type
info.type = componentType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import $DisplayName from 'src/components/$DisplayName/$DisplayName'

describe('$DisplayName', () => {
isConformant($DisplayName)
isConformant($DisplayName, '$DisplayName')
})
1 change: 0 additions & 1 deletion docs/src/utils/componentInfoShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const componentInfoShape = PropTypes.shape({
name: PropTypes.string,
}),
),
constructorName: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
isParent: PropTypes.bool.isRequired,
isChild: PropTypes.bool.isRequired,
Expand Down
27 changes: 8 additions & 19 deletions test/specs/commonTests/isConformant.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as _ from 'lodash'
import * as React from 'react'
import { ReactWrapper } from 'enzyme'
import * as ReactDOMServer from 'react-dom/server'

import isExportedAtTopLevel from './isExportedAtTopLevel'
import {
Expand All @@ -28,14 +27,15 @@ export interface Conformant {
/**
* Assert Component conforms to guidelines that are applicable to all components.
* @param {React.Component|Function} Component A component that should conform.
* @param {String} componentName A name of a component that should conform.
* @param {Object} [options={}]
* @param {Object} [options.eventTargets={}] Map of events and the child component to target.
* @param {boolean} [options.exportedAtTopLevel=false] Is this component exported as top level API?
* @param {boolean} [options.rendersPortal=false] Does this component render a Portal powered component?
* @param {Object} [options.requiredProps={}] Props required to render Component without errors or warnings.
* @param {boolean} [options.usesWrapperSlot=false] This component uses wrapper slot to wrap the 'meaningful' element.
*/
export default (Component, options: Conformant = {}) => {
export default (Component, componentName: string, options: Conformant = {}) => {
const {
eventTargets = {},
exportedAtTopLevel = true,
Expand Down Expand Up @@ -77,24 +77,13 @@ export default (Component, options: Conformant = {}) => {
throwError(`Components should export a class or function, got: ${componentType}.`)
}

// tests depend on Component constructor names, enforce them
const constructorName = Component.prototype.constructor.name
if (!constructorName) {
throwError(
[
'Component is not a named function. This should help identify it:\n\n',
`${ReactDOMServer.renderToStaticMarkup(<Component />)}`,
].join(''),
)
}

// ----------------------------------------
// Component info
// ----------------------------------------
// This is pretty ugly because:
// - jest doesn't support custom error messages
// - jest will run all test
const infoJSONPath = `docs/src/componentInfo/${constructorName}.info.json`
const infoJSONPath = `docs/src/componentInfo/${componentName}.info.json`

let info

Expand Down Expand Up @@ -137,16 +126,16 @@ export default (Component, options: Conformant = {}) => {
}

// ----------------------------------------
// Class and file name
// Component and file name
// ----------------------------------------
test(`constructor name matches filename "${constructorName}"`, () => {
expect(constructorName).toEqual(info.filenameWithoutExt)
test(`component name matches filename "${componentName}"`, () => {
expect(componentName).toEqual(info.filenameWithoutExt)
})

// find the apiPath in the stardust object
const foundAsSubcomponent = _.isFunction(_.get(stardust, info.apiPath))

exportedAtTopLevel && isExportedAtTopLevel(constructorName, info.displayName)
exportedAtTopLevel && isExportedAtTopLevel(componentName, info.displayName)
if (info.isChild) {
test('is a static component on its parent', () => {
const message =
Expand Down Expand Up @@ -489,7 +478,7 @@ export default (Component, options: Conformant = {}) => {
// ----------------------------------------
describe('static displayName (common)', () => {
test('matches constructor name', () => {
expect(Component.displayName).toEqual(info.constructorName)
expect(Component.displayName).toEqual(componentName)
})
})

Expand Down
4 changes: 2 additions & 2 deletions test/specs/commonTests/isExportedAtTopLevel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as stardust from 'src/'
// Is exported or private
// ----------------------------------------
// detect components like: stardust.H1
export default (constructorName: string, displayName: string) => {
const isTopLevelAPIProp = _.has(stardust, constructorName)
export default (componentName: string, displayName: string) => {
const isTopLevelAPIProp = _.has(stardust, componentName)

// require all components to be exported at the top level
test('is exported at the top level', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Accordion/Accordion-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import Accordion from 'src/components/Accordion/Accordion'

describe('Accordion', () => {
isConformant(Accordion)
isConformant(Accordion, 'Accordion')
})
2 changes: 1 addition & 1 deletion test/specs/components/Animation/Animation-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import Animation from 'src/components/Animation/Animation'

describe('Animation', () => {
isConformant(Animation)
isConformant(Animation, 'Animation')
})
2 changes: 1 addition & 1 deletion test/specs/components/Attachment/Attachment-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Button from 'src/components/Button/Button'
const attachmentImplementsShorthandProp = implementsShorthandProp(Attachment)

describe('Attachment', () => {
isConformant(Attachment)
isConformant(Attachment, 'Attachment')
attachmentImplementsShorthandProp('header', Text)
attachmentImplementsShorthandProp('description', Text)
attachmentImplementsShorthandProp('icon', Icon, { mapsValueToProp: 'name' })
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Avatar/Avatar-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Image from 'src/components/Image/Image'
const avatarImplementsShorthandProp = implementsShorthandProp(Avatar)

describe('Avatar', () => {
isConformant(Avatar)
isConformant(Avatar, 'Avatar')
avatarImplementsShorthandProp('label', Label)
avatarImplementsShorthandProp('image', Image, { mapsValueToProp: 'src' })

Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Button/Button-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Icon from 'src/components/Icon/Icon'
const buttonImplementsShorthandProp = implementsShorthandProp(Button)

describe('Button', () => {
isConformant(Button)
isConformant(Button, 'Button')
buttonImplementsShorthandProp('icon', Icon, { mapsValueToProp: 'name' })

describe('accessibility', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Button/ButtonGroup-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AccessibilityDefinition } from 'src/lib/accessibility/types'
const buttonGroupImplementsCollectionShorthandProp = implementsCollectionShorthandProp(ButtonGroup)

describe('ButtonGroup', () => {
isConformant(ButtonGroup)
isConformant(ButtonGroup, 'ButtonGroup')
buttonGroupImplementsCollectionShorthandProp('buttons', Button)

describe('accessibility', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Chat/Chat-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AccessibilityDefinition } from 'src/lib/accessibility/types'
const chatImplementsCollectionShorthandProp = implementsCollectionShorthandProp(Chat)

describe('Chat', () => {
isConformant(Chat)
isConformant(Chat, 'Chat')
chatImplementsCollectionShorthandProp('items', ChatItem)

describe('accessibility', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Chat/ChatItem-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import ChatItem from 'src/components/Chat/ChatItem'

describe('ChatItem', () => {
isConformant(ChatItem)
isConformant(ChatItem, 'ChatItem')
})
2 changes: 1 addition & 1 deletion test/specs/components/Chat/ChatMessage-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AccessibilityDefinition } from 'src/lib/accessibility/types'
import Text from 'src/components/Text/Text'

describe('ChatMessage', () => {
isConformant(ChatMessage)
isConformant(ChatMessage, 'ChatMessage')
implementsShorthandProp(ChatMessage)('avatar', Avatar, { mapsValueToProp: 'name' })
implementsShorthandProp(ChatMessage)('author', Text)
implementsShorthandProp(ChatMessage)('timestamp', Text)
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Divider/Divider-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import Divider from 'src/components/Divider/Divider'

describe('Divider', () => {
isConformant(Divider)
isConformant(Divider, 'Divider')
})
2 changes: 1 addition & 1 deletion test/specs/components/Dropdown/Dropdown-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { isConformant } from 'test/specs/commonTests'

import Dropdown from 'src/components/Dropdown/Dropdown'
describe('Dropdown', () => {
isConformant(Dropdown)
isConformant(Dropdown, 'Dropdown')
})
2 changes: 1 addition & 1 deletion test/specs/components/Form/Form-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import FormField from 'src/components/Form/FormField'
const formImplementsCollectionShorthandProp = implementsCollectionShorthandProp(Form)

describe('Form', () => {
isConformant(Form)
isConformant(Form, 'Form')
formImplementsCollectionShorthandProp('fields', FormField, { mapsValueToProp: 'label' })
})
2 changes: 1 addition & 1 deletion test/specs/components/Form/FormField-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getFormField = (control: ComponentClass<any> | string) =>
mountWithProvider(<FormField control={{ as: control }} name="firstName" />).find('FormField')

describe('FormField', () => {
isConformant(FormField)
isConformant(FormField, 'FormField')
formFieldImplementsShorthandProp('label', Text)
formFieldImplementsShorthandProp('message', Text)
formFieldImplementsShorthandProp('control', Slot, { mapsValueToProp: 'children' })
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Grid/Grid-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import Grid from 'src/components/Grid/Grid'

describe('Grid', () => {
isConformant(Grid)
isConformant(Grid, 'Grid')
})
2 changes: 1 addition & 1 deletion test/specs/components/Header/Header-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import Header from 'src/components/Header/Header'

describe('Header', () => {
isConformant(Header)
isConformant(Header, 'Header')
})
2 changes: 1 addition & 1 deletion test/specs/components/Header/HeaderDescription-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import HeaderDescription from 'src/components/Header/HeaderDescription'

describe('HeaderDescription', () => {
isConformant(HeaderDescription)
isConformant(HeaderDescription, 'HeaderDescription')
})
2 changes: 1 addition & 1 deletion test/specs/components/Icon/Icon-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mountWithProviderAndGetComponent } from 'test/utils'
import { ThemeInput } from 'src/themes/types'

describe('Icon', () => {
isConformant(Icon)
isConformant(Icon, 'Icon')

describe('accessibility', () => {
handlesAccessibility(Icon, {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Image/Image-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Image from 'src/components/Image/Image'
import { mountWithProviderAndGetComponent } from 'test/utils'

describe('Image', () => {
isConformant(Image)
isConformant(Image, 'Image')

describe('accessibility', () => {
handlesAccessibility(Image, {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Input/Input-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const setUserInputValue = (inputComp: ReactWrapper, value: string) => {

describe('Input', () => {
describe('conformance', () => {
isConformant(Input, {
isConformant(Input, 'Input', {
eventTargets: { onChange: 'input' },
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/ItemLayout/ItemLayout-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import ItemLayout from 'src/components/ItemLayout/ItemLayout'

describe('ItemLayout', () => {
isConformant(ItemLayout)
isConformant(ItemLayout, 'ItemLayout')
})
2 changes: 1 addition & 1 deletion test/specs/components/Label/Label-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { implementsShorthandProp } from '../../commonTests'
const labelImplementsShorthandProp = implementsShorthandProp(Label)

describe('Label', () => {
isConformant(Label)
isConformant(Label, 'Label')
labelImplementsShorthandProp('icon', Icon, { mapsValueToProp: 'name' })
labelImplementsShorthandProp('image', Image, { mapsValueToProp: 'src' })

Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Layout/Layout-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import Layout from 'src/components/Layout/Layout'

describe('Layout', () => {
isConformant(Layout)
isConformant(Layout, 'Layout')
})
2 changes: 1 addition & 1 deletion test/specs/components/List/List-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ListItem from 'src/components/List/ListItem'
const listImplementsCollectionShorthandProp = implementsCollectionShorthandProp(List)

describe('List', () => {
isConformant(List)
isConformant(List, 'List')
handlesAccessibility(List, { defaultRootRole: 'list' })
listImplementsCollectionShorthandProp('items', ListItem, { mapsValueToProp: 'main' })
})
2 changes: 1 addition & 1 deletion test/specs/components/List/ListItem-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { isConformant, handlesAccessibility } from 'test/specs/commonTests'
import ListItem from 'src/components/List/ListItem'

describe('ListItem', () => {
isConformant(ListItem)
isConformant(ListItem, 'ListItem')
handlesAccessibility(ListItem, { defaultRootRole: 'listitem' })
})
2 changes: 1 addition & 1 deletion test/specs/components/Menu/Menu-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { AccessibilityDefinition } from 'src/lib/accessibility/types'
const menuImplementsCollectionShorthandProp = implementsCollectionShorthandProp(Menu)

describe('Menu', () => {
isConformant(Menu)
isConformant(Menu, 'Menu')
menuImplementsCollectionShorthandProp('items', MenuItem)

const getItems = () => [
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Menu/MenuItem-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import MenuItem from 'src/components/Menu/MenuItem'
import { toolbarButtonBehavior, tabBehavior } from '../../../../src/lib/accessibility'

describe('MenuItem', () => {
isConformant(MenuItem, {
isConformant(MenuItem, 'MenuItem', {
eventTargets: {
onClick: 'a',
},
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Popup/PopupContent-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { isConformant } from 'test/specs/commonTests'
import PopupContent from 'src/components/Popup/PopupContent'

describe('PopupContent', () => {
isConformant(PopupContent, { rendersPortal: true })
isConformant(PopupContent, 'PopupContent', { rendersPortal: true })
})
2 changes: 1 addition & 1 deletion test/specs/components/RadioGroup/RadioGroup-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const getShorthandItems = (props?: { disabledItem?: number }) => [
]

describe('RadioGroup', () => {
isConformant(RadioGroup)
isConformant(RadioGroup, 'RadioGroup')

describe('accessibility', () => {
handlesAccessibility(RadioGroup, {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/RadioGroup/RadioGroupItem-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isConformant, handlesAccessibility } from 'test/specs/commonTests'
import RadioGroupItem from 'src/components/RadioGroup/RadioGroupItem'

describe('RadioGroupItem', () => {
isConformant(RadioGroupItem)
isConformant(RadioGroupItem, 'RadioGroupItem')

describe('accessibility', () => {
handlesAccessibility(RadioGroupItem, {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Segment/Segment-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import Segment from 'src/components/Segment/Segment'

describe('Segment', () => {
isConformant(Segment)
isConformant(Segment, 'Segment')
})
2 changes: 1 addition & 1 deletion test/specs/components/Slot/Slot-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Slot', () => {
mount(factoryFn(val, options)).find(Slot)

xdescribe('is conformant', () => {
isConformant(Slot, { exportedAtTopLevel: false })
isConformant(Slot, 'Slot', { exportedAtTopLevel: false })
})

describe(`create`, () => {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Status/Status-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import Status from 'src/components/Status/Status'

describe('Status', () => {
isConformant(Status)
isConformant(Status, 'Status')
})
2 changes: 1 addition & 1 deletion test/specs/components/Text/Text-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mountWithProvider } from 'test/utils'
import Text from 'src/components/Text/Text'

describe('Text', () => {
isConformant(Text)
isConformant(Text, 'Text')

test('renders children', () => {
expect(mountWithProvider(<Text>children</Text>).text()).toEqual('children')
Expand Down
2 changes: 1 addition & 1 deletion test/specs/components/Tree/Tree-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { isConformant } from 'test/specs/commonTests'
import Tree from 'src/components/Tree/Tree'

describe('Tree', () => {
isConformant(Tree)
isConformant(Tree, 'Tree')
})