Skip to content

Commit ba48b22

Browse files
authored
Generate report stories from all CCK samples (#416)
1 parent 0c0f8d5 commit ba48b22

File tree

4 files changed

+66
-160
lines changed

4 files changed

+66
-160
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ build/
33
dist/
44
.idea/
55
node_modules/
6+
src/components/app/Report.stories.tsx
67
*.log
78
.codegen
89
*.iml

generate-fixtures.cjs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@ const glob = require('glob')
22
const fs = require('fs')
33
const 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+
517
if (fs.existsSync('acceptance')) {
618
fs.rmdirSync('acceptance', { recursive: true })
719
}
820

21+
const sampleNames = []
22+
923
for (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.
1632
import { 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' })

src/components/app/Report.stories.tsx

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/components/gherkin/GherkinDocument.stories.tsx

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)