@@ -2,7 +2,6 @@ import fs from 'node:fs'
22import path from 'node:path'
33import { describe , expect , test } from 'vitest'
44import glob from 'fast-glob'
5- import groupBy from 'lodash.groupby'
65
76const ROOT_DIRECTORY = path . resolve ( __dirname , '..' , '..' )
87
@@ -84,51 +83,47 @@ const stories = await Promise.all(
8483 } ) ,
8584)
8685
87- const components = Object . entries (
88- groupBy ( stories , ( { name } ) => {
89- return name
90- } ) ,
91- )
86+ // Flatten the stories array to work with vitest 4.0.16's stricter suite function rules
87+ const flattenedStories = stories . map ( story => ( {
88+ testName : ` ${ story . name } - ${ story . story . default . title } ( ${ story . relativeFilepath } )` ,
89+ ... story ,
90+ } ) )
9291
93- describe . each ( components ) ( '%s' , ( _component , stories ) => {
94- for ( const { story, type, relativeFilepath} of stories ) {
95- describe ( `${ story . default . title } (${ relativeFilepath } )` , ( ) => {
96- test ( 'title follows naming convention' , ( ) => {
97- // Matches:
98- // - title: 'Components/TreeView'
99- // Does not match:
100- // - title: 'Component/TreeView/Features'
101- // - title: 'TreeView'
102- const defaultTitlePattern = / C o m p o n e n t s \/ \w + /
92+ describe . each ( flattenedStories ) ( '$testName' , ( { story, type} ) => {
93+ test ( 'title follows naming convention' , ( ) => {
94+ // Matches:
95+ // - title: 'Components/TreeView'
96+ // Does not match:
97+ // - title: 'Component/TreeView/Features'
98+ // - title: 'TreeView'
99+ const defaultTitlePattern = / C o m p o n e n t s \/ \w + /
103100
104- // Matches:
105- // - title: 'Components/TreeView/Features'
106- // Does not match:
107- // - title: 'Component/TreeView'
108- // - title: 'TreeView'
109- const featureTitlePattern = / C o m p o n e n t s \/ \w + \/ F e a t u r e s /
101+ // Matches:
102+ // - title: 'Components/TreeView/Features'
103+ // Does not match:
104+ // - title: 'Component/TreeView'
105+ // - title: 'TreeView'
106+ const featureTitlePattern = / C o m p o n e n t s \/ \w + \/ F e a t u r e s /
110107
111- expect ( story . default . title ) . toMatch ( type === 'default' ? defaultTitlePattern : featureTitlePattern )
112- } )
108+ expect ( story . default . title ) . toMatch ( type === 'default' ? defaultTitlePattern : featureTitlePattern )
109+ } )
113110
114- if ( type === 'default' ) {
115- test ( 'exports a Default story' , ( ) => {
116- expect ( story . Default ) . toBeDefined ( )
117- } )
111+ if ( type === 'default' ) {
112+ test ( 'exports a Default story' , ( ) => {
113+ expect ( story . Default ) . toBeDefined ( )
114+ } )
118115
119- test ( 'Default story does not have `args`' , ( ) => {
120- expect ( story . Default . args ) . not . toBeDefined ( )
121- } )
116+ test ( 'Default story does not have `args`' , ( ) => {
117+ expect ( story . Default . args ) . not . toBeDefined ( )
118+ } )
122119
123- test ( 'Default story does not have `argTypes`' , ( ) => {
124- expect ( story . Default . argTypes ) . not . toBeDefined ( )
125- } )
120+ test ( 'Default story does not have `argTypes`' , ( ) => {
121+ expect ( story . Default . argTypes ) . not . toBeDefined ( )
122+ } )
126123
127- test ( 'only exports Default and Playground stories' , ( ) => {
128- for ( const storyName of Object . keys ( story ) ) {
129- 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 )
130- }
131- } )
124+ test ( 'only exports Default and Playground stories' , ( ) => {
125+ for ( const storyName of Object . keys ( story ) ) {
126+ 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 )
132127 }
133128 } )
134129 }
0 commit comments