Skip to content

Commit

Permalink
fix: ensure unit test examples work in projects created with --bare
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 18, 2018
1 parent a024513 commit b62c6ba
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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>/
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)`)
})

Expand All @@ -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\`)`)
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%_ if (!hasTS) { _%>
import { shallowMount } from '@vue/test-utils'
<%_ if (!rootOptions.bare) { _%>
import HelloWorld from '@/components/HelloWorld.vue'

describe('HelloWorld.vue', () => {
Expand All @@ -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`)
})
<%_ } _%>
<%_ } _%>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%_ if (hasTS) { _%>
import { shallowMount } from '@vue/test-utils'
<%_ if (!rootOptions.bare) { _%>
import HelloWorld from '@/components/HelloWorld.vue'

describe('HelloWorld.vue', () => {
Expand All @@ -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`)
})
<%_ } _%>
<%_ } _%>
Original file line number Diff line number Diff line change
Expand Up @@ -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\`)`)
})
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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`)
})
})
<%_ } _%>
<%_ } _%>
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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`)
})
})
<%_ } _%>
<%_ } _%>

0 comments on commit b62c6ba

Please sign in to comment.