fix: do not generate empty file when use ts without router (#4374)

(cherry picked from commit 52bae8e14a)
This commit is contained in:
Cédric Exbrayat
2019-07-30 10:42:00 +02:00
committed by Haoqun Jiang
parent bb2e3e7217
commit 7c19dd61e2
2 changed files with 19 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ test('generate files', async () => {
expect(files['src/main.ts']).toBeTruthy()
expect(files['src/main.js']).toBeFalsy()
expect(files['src/App.vue']).toMatch('<script lang="ts">')
// checks that the Home.vue file has not been created, even empty
expect(files.hasOwnProperty('src/views/Home.vue')).toBeFalsy()
})
test('classComponent', async () => {
@@ -62,6 +64,22 @@ test('use with Babel', async () => {
expect(files['tsconfig.json']).toMatch(`"target": "esnext"`)
})
test('use with router', async () => {
const { files } = await generateWithPlugin([
{
id: '@vue/cli-plugin-router',
apply: require('@vue/cli-plugin-router/generator'),
options: {}
},
{
id: 'ts',
apply: require('../generator'),
options: {}
}
])
expect(files['src/views/Home.vue']).toMatch('<div class=\"home\">')
})
test('lint', async () => {
const { pkg, files } = await generateWithPlugin([
{

View File

@@ -412,7 +412,7 @@ function renderFile (name, data, ejsOptions) {
// if evaluated to falsy value, return early to avoid extra cost for extend expression
const result = ejs.render(finalTemplate, data, ejsOptions)
if (!result) {
return
return ''
}
}