@@ -2,25 +2,41 @@ import _ from 'lodash';
22import path from 'path' ;
33import stardust from 'stardust' ;
44
5- const componentPaths = require . context (
5+ const componentCtx = require . context (
66 'src/' ,
77 true ,
88 / ( a d d o n s | c o l l e c t i o n s | e l e m e n t s | m o d u l e s | v i e w s ) .* \. j s $ /
99) ;
1010
11- const componentNames = _ . map ( componentPaths . keys ( ) , key => {
11+ const componentNames = _ . map ( componentCtx . keys ( ) , key => {
1212 return path . basename ( key ) . replace ( '.js' , '' ) ;
1313} ) ;
1414
15- describe ( 'index.js' , ( ) => {
16- it ( 'has a property for every component' , ( ) => {
17- _ . each ( componentNames , component => {
18- expect ( stardust ) . to . have . any . keys ( component ) ;
19- expect ( stardust [ component ] ) . to . be . a ( 'function' ) ;
20- } ) ;
21- } ) ;
15+ describe ( 'stardust (index.js)' , ( ) => {
16+ _ . each ( componentNames , name => {
17+ const isPrivate = _ . startsWith ( name , '_' ) ;
18+ const isStardustProp = _ . has ( stardust , name ) ; // => stardust.H1
19+ const isSubComponent = _ . some ( stardust , name ) ; // => stardust.Header.H1
20+ // console.log(`${name} isStardustProp=${isStardustProp} isSubComponent=${isSubComponent}`);
21+
22+ if ( isPrivate ) {
23+ it ( `does not expose private component "${ name } "` , ( ) => {
24+ expect ( ! isStardustProp ) . to . equal ( true ,
25+ `"${ name } " is private (starts with "_"), it cannot be a key on the stardust object`
26+ ) ;
27+
28+ expect ( ! isSubComponent ) . to . equal ( true ,
29+ `"${ name } " is private (starts with "_"), it cannot be a static prop of another component (sub-component)`
30+ ) ;
31+ } ) ;
32+ }
2233
23- it ( 'only has properties which correspond to components' , ( ) => {
24- _ . each ( stardust , component => expect ( component in componentNames ) ) ;
34+ if ( ! isPrivate ) {
35+ it ( `exposes public component "${ name } "` , ( ) => {
36+ expect ( ! isPrivate && ! isStardustProp && ! isSubComponent ) . to . equal ( false ,
37+ `"${ name } " must be: a key on stardust || key on another component (sub-component) || private (start with "_")`
38+ ) ;
39+ } ) ;
40+ }
2541 } ) ;
2642} ) ;
0 commit comments