2020-09-09 16:09:53 +08:00
|
|
|
const fs = require('fs').promises
|
|
|
|
const path = require('path')
|
2020-12-11 13:27:47 +08:00
|
|
|
const _ = require('lodash')
|
2020-09-09 16:09:53 +08:00
|
|
|
|
|
|
|
;(async () => {
|
|
|
|
const files = await fs.readdir(
|
|
|
|
path.resolve(__dirname, '..', 'src')
|
|
|
|
)
|
2020-12-11 13:27:47 +08:00
|
|
|
for (const file of files) {
|
|
|
|
if ([
|
|
|
|
'locales'
|
|
|
|
].includes(file)) continue
|
|
|
|
if (!file.startsWith('_') && !file.endsWith('.js')) {
|
|
|
|
console.log(`- [ ] ${file}`)
|
|
|
|
await generateImportOnDemandTest(file)
|
|
|
|
}
|
|
|
|
}
|
2020-09-09 16:09:53 +08:00
|
|
|
})()
|
2020-12-11 13:27:47 +08:00
|
|
|
|
|
|
|
async function generateImportOnDemandTest (name) {
|
|
|
|
const styleVarName = `${_.camelCase(name)}Light`
|
2020-12-11 13:32:33 +08:00
|
|
|
const testFileName = `${_.upperFirst(_.camelCase(name))}.spec.js`
|
2020-12-11 13:27:47 +08:00
|
|
|
const compVarName = `N${_.upperFirst(_.camelCase(name))}`
|
|
|
|
const script = `import { mount } from '@vue/test-utils'
|
|
|
|
import create from '../../create'
|
|
|
|
import { enUS } from '../../locales'
|
|
|
|
import { ${styleVarName} } from '../styles'
|
|
|
|
import { ${compVarName} } from '../index'
|
|
|
|
|
|
|
|
describe('n-${name}', () => {
|
|
|
|
const naive = create({
|
|
|
|
locales: [
|
|
|
|
enUS
|
|
|
|
],
|
|
|
|
styles: [
|
|
|
|
${styleVarName}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
it('should work with import on demand', () => {
|
|
|
|
mount(${compVarName}, {
|
|
|
|
global: {
|
|
|
|
plugins: [naive]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
`
|
|
|
|
if (
|
|
|
|
await fs.stat(path.resolve(__dirname, '../src/', name, 'tests')).then(() => true).catch(() => false)
|
|
|
|
) {
|
|
|
|
} else {
|
|
|
|
await fs.mkdir(path.resolve(__dirname, '../src/', name, 'tests'))
|
|
|
|
}
|
2020-12-11 13:32:33 +08:00
|
|
|
await fs.writeFile(path.resolve(__dirname, '../src/', name, 'tests', testFileName), script)
|
2020-12-11 13:27:47 +08:00
|
|
|
}
|