fix: ensure unit test examples work in projects created with --bare

close #2262
This commit is contained in:
Evan You
2018-08-18 15:41:44 -04:00
parent a024513bcc
commit b62c6ba7f2
7 changed files with 168 additions and 3 deletions
@@ -1,7 +1,7 @@
---
extend: '@vue/cli-service/generator/template/src/App.vue'
replace:
- !!js/regexp /Welcome to Your Vue\.js App/
- !!js/regexp /Welcome to Your Vue\.js App/g
- !!js/regexp /<script>[^]*?<\/script>/
---
@@ -30,7 +30,7 @@ test('base', async () => {
// eslint
expect(files['tests/unit/.eslintrc.js']).toMatch('jest: true')
const spec = files['tests/unit/HelloWorld.spec.js']
const spec = files['tests/unit/example.spec.js']
expect(spec).toMatch(`expect(wrapper.text()).toMatch(msg)`)
})
@@ -46,3 +46,65 @@ test('without babel/eslint', async () => {
expect(pkg.devDependencies).not.toHaveProperty('babel-jest')
expect(files['tests/unit/.eslintrc.js']).toBeUndefined()
})
test('with TS', async () => {
const { files } = await generateWithPlugin([
{
id: 'unit-jest',
apply: require('../generator'),
options: {}
},
// mock presence of the ts plugin
{
id: 'typescript',
apply: () => {},
options: {}
}
])
const spec = files['tests/unit/example.spec.ts']
expect(spec).toMatch(`expect(wrapper.text()).toMatch(msg)`)
})
test('bare', async () => {
const { files } = await generateWithPlugin([
{
id: 'unit-jest',
apply: require('../generator'),
options: {}
},
{
id: '@vue/cli-service',
apply: () => {},
options: { bare: true }
}
])
const spec = files['tests/unit/example.spec.js']
expect(spec).toMatch(`const wrapper = shallowMount(App)`)
expect(spec).toMatch(`expect(wrapper.text()).toMatch(\`Welcome to Your Vue.js App\`)`)
})
test('TS + bare', async () => {
const { files } = await generateWithPlugin([
{
id: 'unit-jest',
apply: require('../generator'),
options: {}
},
{
id: 'typescript',
apply: () => {},
options: {}
},
{
id: '@vue/cli-service',
apply: () => {},
options: { bare: true }
}
])
const spec = files['tests/unit/example.spec.ts']
expect(spec).toMatch(`const wrapper = shallowMount(App)`)
expect(spec).toMatch(`expect(wrapper.text()).toMatch(\`Welcome to Your Vue.js + TypeScript App\`)`)
})
@@ -1,5 +1,6 @@
<%_ if (!hasTS) { _%>
import { shallowMount } from '@vue/test-utils'
<%_ if (!rootOptions.bare) { _%>
import HelloWorld from '@/components/HelloWorld.vue'
describe('HelloWorld.vue', () => {
@@ -11,4 +12,12 @@ describe('HelloWorld.vue', () => {
expect(wrapper.text()).toMatch(msg)
})
})
<%_ } else { _%>
import App from '@/App.vue'
test('App should work', () => {
const wrapper = shallowMount(App)
expect(wrapper.text()).toMatch(`Welcome to Your Vue.js App`)
})
<%_ } _%>
<%_ } _%>
@@ -1,5 +1,6 @@
<%_ if (hasTS) { _%>
import { shallowMount } from '@vue/test-utils'
<%_ if (!rootOptions.bare) { _%>
import HelloWorld from '@/components/HelloWorld.vue'
describe('HelloWorld.vue', () => {
@@ -11,4 +12,12 @@ describe('HelloWorld.vue', () => {
expect(wrapper.text()).toMatch(msg)
})
})
<%_ } else { _%>
import App from '@/App.vue'
test('App should work', () => {
const wrapper = shallowMount(App)
expect(wrapper.text()).toMatch(`Welcome to Your Vue.js + TypeScript App`)
})
<%_ } _%>
<%_ } _%>
@@ -19,7 +19,70 @@ test('base', async () => {
expect(pkg.devDependencies).toHaveProperty('@vue/test-utils')
expect(files['tests/unit/.eslintrc.js']).toMatch('mocha: true')
const spec = files['tests/unit/HelloWorld.spec.js']
const spec = files['tests/unit/example.spec.js']
expect(spec).toMatch(`import { expect } from 'chai'`)
expect(spec).toMatch(`expect(wrapper.text()).to.include(msg)`)
})
test('with TS', async () => {
const { files } = await generateWithPlugin([
{
id: 'unit-mocha',
apply: require('../generator'),
options: {}
},
// mock presence of the ts plugin
{
id: 'typescript',
apply: () => {},
options: {}
}
])
const spec = files['tests/unit/example.spec.ts']
expect(spec).toMatch(`import { expect } from 'chai'`)
expect(spec).toMatch(`expect(wrapper.text()).to.include(msg)`)
})
test('bare', async () => {
const { files } = await generateWithPlugin([
{
id: 'unit-mocha',
apply: require('../generator'),
options: {}
},
{
id: '@vue/cli-service',
apply: () => {},
options: { bare: true }
}
])
const spec = files['tests/unit/example.spec.js']
expect(spec).toMatch(`const wrapper = shallowMount(App)`)
expect(spec).toMatch(`expect(wrapper.text()).to.include(\`Welcome to Your Vue.js App\`)`)
})
test('TS + bare', async () => {
const { files } = await generateWithPlugin([
{
id: 'unit-mocha',
apply: require('../generator'),
options: {}
},
{
id: 'typescript',
apply: () => {},
options: {}
},
{
id: '@vue/cli-service',
apply: () => {},
options: { bare: true }
}
])
const spec = files['tests/unit/example.spec.ts']
expect(spec).toMatch(`const wrapper = shallowMount(App)`)
expect(spec).toMatch(`expect(wrapper.text()).to.include(\`Welcome to Your Vue.js + TypeScript App\`)`)
})
@@ -1,6 +1,7 @@
<%_ if (!hasTS) { _%>
import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
<%_ if (!rootOptions.bare) { _%>
import HelloWorld from '@/components/HelloWorld.vue'
describe('HelloWorld.vue', () => {
@@ -12,4 +13,14 @@ describe('HelloWorld.vue', () => {
expect(wrapper.text()).to.include(msg)
})
})
<%_ } else { _%>
import App from '@/App.vue'
describe('App', () => {
it('should work', () => {
const wrapper = shallowMount(App)
expect(wrapper.text()).to.include(`Welcome to Your Vue.js App`)
})
})
<%_ } _%>
<%_ } _%>
@@ -1,6 +1,7 @@
<%_ if (hasTS) { _%>
import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
<%_ if (!rootOptions.bare) { _%>
import HelloWorld from '@/components/HelloWorld.vue'
describe('HelloWorld.vue', () => {
@@ -12,4 +13,14 @@ describe('HelloWorld.vue', () => {
expect(wrapper.text()).to.include(msg)
})
})
<%_ } else { _%>
import App from '@/App.vue'
describe('App', () => {
it('should work', () => {
const wrapper = shallowMount(App)
expect(wrapper.text()).to.include(`Welcome to Your Vue.js + TypeScript App`)
})
})
<%_ } _%>
<%_ } _%>