@@ -2,15 +2,31 @@ const glob = require('glob')
22const fs = require ( 'fs' )
33const path = require ( 'path' )
44
5+ function toPascalCase ( str ) {
6+ return str
7+ . split ( '-' )
8+ . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) )
9+ . join ( '' )
10+ }
11+
12+ function toCamelCase ( str ) {
13+ const parts = str . split ( '-' )
14+ return parts [ 0 ] + parts . slice ( 1 ) . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) ) . join ( '' )
15+ }
16+
517if ( fs . existsSync ( 'acceptance' ) ) {
618 fs . rmdirSync ( 'acceptance' , { recursive : true } )
719}
820
21+ const sampleNames = [ ]
22+
923for ( const ndjsonPath of glob . sync (
1024 'node_modules/@cucumber/compatibility-kit/features/**/*.ndjson'
1125) ) {
1226 const filename = path . basename ( ndjsonPath )
1327 const [ suiteName ] = filename . split ( '.' )
28+ sampleNames . push ( suiteName )
29+
1430 const content = fs . readFileSync ( ndjsonPath , { encoding : 'utf-8' } )
1531 const asTs = `// Generated file. Do not edit.
1632import { Envelope } from '@cucumber/messages'
@@ -21,3 +37,52 @@ export default [${content.split('\n').join(',')}] as ReadonlyArray<Envelope>
2137 fs . mkdirSync ( `acceptance/${ suiteName } ` , { recursive : true } )
2238 fs . writeFileSync ( targetPath , asTs , { encoding : 'utf-8' } )
2339}
40+
41+ sampleNames . sort ( )
42+
43+ const storiesPath = 'src/components/app/Report.stories.tsx'
44+
45+ const imports = sampleNames
46+ . map ( name => `import ${ toCamelCase ( name ) } Sample from '../../../acceptance/${ name } /${ name } .js'` )
47+ . join ( '\n' )
48+
49+ const stories = sampleNames
50+ . map ( name => {
51+ const exportName = toPascalCase ( name )
52+ const importName = toCamelCase ( name ) + 'Sample'
53+ return `export const ${ exportName } = Template.bind({})
54+ ${ exportName } .args = {
55+ envelopes: ${ importName } ,
56+ }`
57+ } )
58+ . join ( '\n\n' )
59+
60+ const storiesTemplate = `// Generated file. Do not edit.
61+ import { Envelope } from '@cucumber/messages'
62+ import { Story } from '@ladle/react'
63+ import React from 'react'
64+
65+ ${ imports }
66+ import { EnvelopesProvider } from './EnvelopesProvider.js'
67+ import { Report } from './Report.js'
68+
69+ export default {
70+ title: 'App/Report',
71+ }
72+
73+ type TemplateArgs = {
74+ envelopes: Envelope[]
75+ }
76+
77+ const Template: Story<TemplateArgs> = ({ envelopes }) => {
78+ return (
79+ <EnvelopesProvider envelopes={envelopes}>
80+ <Report />
81+ </EnvelopesProvider>
82+ )
83+ }
84+
85+ ${ stories }
86+ `
87+
88+ fs . writeFileSync ( storiesPath , storiesTemplate , { encoding : 'utf-8' } )
0 commit comments