@@ -4,29 +4,35 @@ import groupBy from 'lodash.groupby'
44
55const  ROOT_DIRECTORY  =  path . resolve ( __dirname ,  '..' ,  '..' ) 
66// Components opted into the new story format 
7- const  allowlist  =  [ 'TreeView' ] 
7+ const  allowlist  =  [ 'ActionList'  ,   'Button' ,   'IconButton' ,   'FilteredActionList' ,   ' TreeView'] 
88const  stories  =  glob 
99  . sync ( 'src/**/*.stories.tsx' ,  { 
1010    cwd : ROOT_DIRECTORY , 
1111  } ) 
12-   . filter ( file  =>  allowlist . some ( component  =>  file . includes ( component ) ) ) 
12+   // Filter out deprecated stories 
13+   . filter ( file  =>  ! file . includes ( 'deprecated' ) ) 
14+   . filter ( file  => 
15+     allowlist . some ( 
16+       component  =>  file . includes ( `/${ component }  .stories.tsx` )  ||  file . includes ( `/${ component }  .features.stories.tsx` ) , 
17+     ) , 
18+   ) 
1319  . map ( file  =>  { 
1420    const  filepath  =  path . join ( ROOT_DIRECTORY ,  file ) 
1521    const  type  =  path . basename ( filepath ,  '.stories.tsx' ) . endsWith ( 'features' )  ? 'feature'  : 'default' 
1622    const  name  =  type  ===  'feature'  ? path . basename ( file ,  '.features.stories.tsx' )  : path . basename ( file ,  '.stories.tsx' ) 
1723
18-     return  [ name ,  require ( filepath ) ,  type ] 
24+     return  { name,  story :  require ( filepath ) ,  type,   relativeFilepath :  path . relative ( ROOT_DIRECTORY ,   filepath ) } 
1925  } ) 
2026
2127const  components  =  Object . entries ( 
22-   groupBy ( stories ,  ( [ name ] )  =>  { 
28+   groupBy ( stories ,  ( { name} )  =>  { 
2329    return  name 
2430  } ) , 
2531) 
2632
2733describe . each ( components ) ( '%s' ,  ( _component ,  stories )  =>  { 
28-   for  ( const  [ ,   story ,  type ]  of  stories )  { 
29-     describe ( `${ story . default . title }  ` ,  ( )  =>  { 
34+   for  ( const  { story,  type,  relativeFilepath }  of  stories )  { 
35+     describe ( `${ story . default . title }  ( ${ relativeFilepath } ) ` ,  ( )  =>  { 
3036      test ( 'title follows naming convention' ,  ( )  =>  { 
3137        // Matches: 
3238        // - title: 'Components/TreeView' 
@@ -46,17 +52,23 @@ describe.each(components)('%s', (_component, stories) => {
4652      } ) 
4753
4854      if  ( type  ===  'default' )  { 
49-         test ( 'exports a " Default"  story' ,  ( )  =>  { 
55+         test ( 'exports a Default story' ,  ( )  =>  { 
5056          expect ( story . Default ) . toBeDefined ( ) 
5157        } ) 
5258
53-         test ( '" Default"  story does not use  args' ,  ( )  =>  { 
59+         test ( 'Default story does not have ` args` ' ,  ( )  =>  { 
5460          expect ( story . Default . args ) . not . toBeDefined ( ) 
5561        } ) 
5662
57-         test ( '" Default"  story does not set  `argTypes` on the `Default` story ' ,  ( )  =>  { 
63+         test ( 'Default story does not have  `argTypes`' ,  ( )  =>  { 
5864          expect ( story . Default . argTypes ) . not . toBeDefined ( ) 
5965        } ) 
66+ 
67+         test ( 'only exports Default and Playground stories' ,  ( )  =>  { 
68+           for  ( const  storyName  of  Object . keys ( story ) )  { 
69+             expect ( / ^ D e f a u l t $ | ^ ( .* ) P l a y g r o u n d $ | ^ d e f a u l t $ / . test ( storyName ) ) . toBe ( true ) 
70+           } 
71+         } ) 
6072      } 
6173    } ) 
6274  } 
0 commit comments