-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test componentToHints
, exclude test files from be published
#381
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.test.* | ||
|
||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ import { Box } from './Box/Box'; | |
|
||
import { assignInlineVars } from '@vanilla-extract/dynamic'; | ||
|
||
const staticTypes = __PLAYROOM_GLOBAL__STATIC_TYPES__; | ||
|
||
const resizableConfig = (position: EditorPosition = 'bottom') => ({ | ||
top: position === 'bottom', | ||
right: false, | ||
|
@@ -59,7 +61,7 @@ const getTitle = (title: string | undefined) => { | |
}; | ||
|
||
export interface PlayroomProps { | ||
components: Record<string, ComponentType>; | ||
components: Record<string, ComponentType<any>>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
themes: string[]; | ||
widths: number[]; | ||
snippets: Snippets; | ||
|
@@ -122,7 +124,7 @@ export default ({ components, themes, widths, snippets }: PlayroomProps) => { | |
dispatch({ type: 'updateCode', payload: { code: newCode } }) | ||
} | ||
previewCode={previewEditorCode} | ||
hints={componentsToHints(components)} | ||
hints={componentsToHints(components, staticTypes)} | ||
/> | ||
<StatusMessage /> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import componentsToHints from './componentsToHints'; | ||
// @ts-expect-error | ||
import * as PropTypeComponents from '../../cypress/projects/themed/components'; | ||
import * as TypeScriptComponents from '../../cypress/projects/typescript/components'; | ||
|
||
describe('componentsToHints', () => { | ||
it('should support javascript components with proptypes', () => { | ||
const result = componentsToHints({ | ||
Bar: PropTypeComponents.Bar, | ||
Foo: PropTypeComponents.Foo, | ||
}); | ||
|
||
expect(result).toMatchInlineSnapshot(` | ||
{ | ||
"Bar": { | ||
"attrs": { | ||
"color": [ | ||
"red", | ||
"blue", | ||
], | ||
}, | ||
}, | ||
"Foo": { | ||
"attrs": { | ||
"color": [ | ||
"red", | ||
"blue", | ||
], | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
it('should support typescript components when provided with type data', () => { | ||
const result = componentsToHints( | ||
{ | ||
Bar: TypeScriptComponents.Bar, | ||
Foo: TypeScriptComponents.Foo, | ||
}, | ||
{ | ||
Bar: { color: ['red', 'blue', 'black'] }, | ||
Foo: { color: ['red', 'blue', 'black'] }, | ||
} | ||
); | ||
|
||
expect(result).toMatchInlineSnapshot(` | ||
{ | ||
"Bar": { | ||
"attrs": { | ||
"color": [ | ||
"red", | ||
"blue", | ||
"black", | ||
], | ||
}, | ||
}, | ||
"Foo": { | ||
"attrs": { | ||
"color": [ | ||
"red", | ||
"blue", | ||
"black", | ||
], | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ import omit from 'lodash/omit'; | |
import parsePropTypes from 'parse-prop-types'; | ||
import type { PlayroomProps } from '../Playroom/Playroom'; | ||
|
||
const staticTypes = __PLAYROOM_GLOBAL__STATIC_TYPES__; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving this into |
||
|
||
export default (components: PlayroomProps['components']) => { | ||
export default ( | ||
components: PlayroomProps['components'], | ||
staticTypes: typeof __PLAYROOM_GLOBAL__STATIC_TYPES__ = {} | ||
) => { | ||
const componentNames = Object.keys(components).sort(); | ||
|
||
return Object.assign( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this with
npm pack
:Before: 128 files being packaged.
After: 124 files being packaged.
There are exactly 4 test files inside
src
, so this seems correct.