-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
generate-stub-specs-ts.ts
31 lines (25 loc) · 950 Bytes
/
generate-stub-specs-ts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { randomComponents } from './testStubSpecs'
import * as fs from 'fs'
import * as path from 'path'
const argv = process.argv
if (argv.includes('--help') || argv.includes('-h') || argv.length < 5 || !['Spec', 'FileParts'].includes(argv[4])) {
// eslint-disable-next-line no-console
console.log(
'yarn generate-stub-specs <filename> <n> <baseTypeName> [--app]\n' +
'<baseTypeName> is Spec or FileParts',
)
process.exit()
}
const components = randomComponents(parseInt(argv[3]), argv[4] as ('Spec' | 'FileParts'))
const root = argv.includes('--app')
? path.join(__dirname, '../../app')
: path.join(__dirname, '..')
fs.writeFile(path.join(root, 'cypress/fixtures', `${argv[2]}.json`), JSON.stringify(components, null, 2), (err) => {
if (err) {
// eslint-disable-next-line no-console
console.error(err)
} else {
// eslint-disable-next-line no-console
console.log('fixture generation succeeded.')
}
})