Skip to content

Commit eb65c82

Browse files
committed
refactor: decouple tests from vue test utils
1 parent 443a928 commit eb65c82

File tree

9 files changed

+110
-148
lines changed

9 files changed

+110
-148
lines changed

e2e/__projects__/basic/__snapshots__/test.js.snap

Lines changed: 23 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,6 @@ Object.defineProperty(exports, \\"__esModule\\", {
77
value: true
88
});
99
exports[\\"default\\"] = void 0;
10-
//
11-
//
12-
//
13-
//
14-
//
15-
//
16-
//
17-
//
18-
//
19-
//
20-
//
21-
//
22-
//
23-
//
24-
//
25-
//
26-
//
27-
//
28-
//
29-
//
30-
//
31-
//
3210
var _default = {
3311
name: 'basic',
3412
computed: {
@@ -54,38 +32,19 @@ var _default = {
5432
};
5533
exports[\\"default\\"] = _default;
5634
;
57-
var __options__ = typeof exports.default === 'function' ? exports.default.options : exports.default
58-
var render = function() {
59-
var _vm = this
60-
var _h = _vm.$createElement
61-
/* istanbul ignore next */
62-
var _c = _vm._self._c || _h
63-
return _c(\\"div\\", { staticClass: \\"hello\\" }, [
64-
_c(\\"h1\\", { class: _vm.headingClasses }, [_vm._v(_vm._s(_vm.msg))])
65-
])
35+
\\"use strict\\";
36+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
37+
var vue_1 = require(\\"vue\\");
38+
var _hoisted_1 = { class: \\"hello\\" };
39+
function render(_ctx, _cache) {
40+
return (vue_1.openBlock(), vue_1.createBlock(\\"div\\", _hoisted_1, [
41+
vue_1.createVNode(\\"h1\\", { class: _ctx.headingClasses }, vue_1.toDisplayString(_ctx.msg), 3 /* TEXT, CLASS */)
42+
]));
6643
}
67-
var staticRenderFns = []
68-
render._withStripped = true
69-
70-
__options__.render = render
71-
__options__.staticRenderFns = staticRenderFns
72-
;(function() {
73-
var beforeCreate = __options__.beforeCreate
74-
var styleFn = function () { if(!this['css']) {
75-
this['css'] = {};
76-
}
77-
this['css'] = Object.assign(
78-
this['css'], {\\"testA\\":\\"testA\\"});
79-
if(!this['$style']) {
80-
this['$style'] = {};
81-
}
82-
this['$style'] = Object.assign(
83-
this['$style'], {\\"testB\\":\\"testB\\"});
84-
}
85-
__options__.beforeCreate = beforeCreate ? [].concat(beforeCreate, styleFn) : [styleFn]
86-
})()
87-
88-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJhc2ljLnZ1ZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTs7QUFHQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUhBO0FBS0E7QUFQQTtBQVNBO0FBQ0E7QUFDQTtBQUNBO0FBRkE7QUFJQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBSEE7QUFqQkE7Ozs7QUF2QkE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBIiwic291cmNlc0NvbnRlbnQiOlsiPHRlbXBsYXRlPlxuICA8ZGl2IGNsYXNzPVwiaGVsbG9cIj5cbiAgICA8aDEgOmNsYXNzPVwiaGVhZGluZ0NsYXNzZXNcIj57eyBtc2cgfX08L2gxPlxuICA8L2Rpdj5cbjwvdGVtcGxhdGU+XG5cbjxzdHlsZSBtb2R1bGU9XCJjc3NcIj5cbi50ZXN0QSB7XG4gIGJhY2tncm91bmQtY29sb3I6IHJlZDtcbn1cbjwvc3R5bGU+XG48c3R5bGUgbW9kdWxlPlxuLnRlc3RCIHtcbiAgYmFja2dyb3VuZC1jb2xvcjogYmx1ZTtcbn1cbjwvc3R5bGU+XG48c3R5bGU+XG4udGVzdEMge1xuICBiYWNrZ3JvdW5kLWNvbG9yOiBibHVlO1xufVxuPC9zdHlsZT5cblxuPHNjcmlwdD5cbmV4cG9ydCBkZWZhdWx0IHtcbiAgbmFtZTogJ2Jhc2ljJyxcbiAgY29tcHV0ZWQ6IHtcbiAgICBoZWFkaW5nQ2xhc3NlczogZnVuY3Rpb24gaGVhZGluZ0NsYXNzZXMoKSB7XG4gICAgICByZXR1cm4ge1xuICAgICAgICByZWQ6IHRoaXMuaXNDcmF6eSxcbiAgICAgICAgYmx1ZTogIXRoaXMuaXNDcmF6eSxcbiAgICAgICAgc2hhZG93OiB0aGlzLmlzQ3JhenlcbiAgICAgIH1cbiAgICB9XG4gIH0sXG4gIGRhdGE6IGZ1bmN0aW9uIGRhdGEoKSB7XG4gICAgcmV0dXJuIHtcbiAgICAgIG1zZzogJ1dlbGNvbWUgdG8gWW91ciBWdWUuanMgQXBwJyxcbiAgICAgIGlzQ3Jhenk6IGZhbHNlXG4gICAgfVxuICB9LFxuICBtZXRob2RzOiB7XG4gICAgdG9nZ2xlQ2xhc3M6IGZ1bmN0aW9uIHRvZ2dsZUNsYXNzKCkge1xuICAgICAgdGhpcy5pc0NyYXp5ID0gIXRoaXMuaXNDcmF6eVxuICAgIH1cbiAgfVxufVxuPC9zY3JpcHQ+XG4iXX0="
44+
exports.render = render;
45+
//# sourceMappingURL=module.js.map;
46+
;exports.default = {...exports.default, render};
47+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJhc2ljLnZ1ZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFIQTtBQUtBO0FBUEE7QUFTQTtBQUNBO0FBQ0E7QUFDQTtBQUZBO0FBSUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUhBO0FBakJBIiwic291cmNlc0NvbnRlbnQiOlsiPHRlbXBsYXR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ates source maps using src attributes 1`] = `
@@ -120,21 +79,17 @@ var _default = {
12079
};
12180
exports[\\"default\\"] = _default;
12281
;
123-
var __options__ = typeof exports.default === 'function' ? exports.default.options : exports.default
124-
var render = function() {
125-
var _vm = this
126-
var _h = _vm.$createElement
127-
/* istanbul ignore next */
128-
var _c = _vm._self._c || _h
129-
return _c(\\"div\\", { staticClass: \\"hello\\" }, [
130-
_c(\\"h1\\", { class: _vm.headingClasses }, [_vm._v(_vm._s(_vm.msg))])
131-
])
82+
\\"use strict\\";
83+
Object.defineProperty(exports, \\"__esModule\\", { value: true });
84+
var vue_1 = require(\\"vue\\");
85+
var _hoisted_1 = { class: \\"hello\\" };
86+
function render(_ctx, _cache) {
87+
return (vue_1.openBlock(), vue_1.createBlock(\\"div\\", _hoisted_1, [
88+
vue_1.createVNode(\\"h1\\", { class: _ctx.headingClasses }, vue_1.toDisplayString(_ctx.msg), 3 /* TEXT, CLASS */)
89+
]));
13290
}
133-
var staticRenderFns = []
134-
render._withStripped = true
135-
136-
__options__.render = render
137-
__options__.staticRenderFns = staticRenderFns
138-
91+
exports.render = render;
92+
//# sourceMappingURL=module.js.map;
93+
;exports.default = {...exports.default, render};
13994
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIlNvdXJjZU1hcHNTcmMudnVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUhBO0FBS0E7QUFQQTtBQVNBO0FBQ0E7QUFDQTtBQUNBO0FBRkE7QUFJQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBSEE7QUFqQkEiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCB7XG4gIG5hbWU6ICdiYXNpYycsXG4gIGNvbXB1dGVkOiB7XG4gICAgaGVhZGluZ0NsYXNzZXM6IGZ1bmN0aW9uIGhlYWRpbmdDbGFzc2VzKCkge1xuICAgICAgcmV0dXJuIHtcbiAgICAgICAgcmVkOiB0aGlzLmlzQ3JhenksXG4gICAgICAgIGJsdWU6ICF0aGlzLmlzQ3JhenksXG4gICAgICAgIHNoYWRvdzogdGhpcy5pc0NyYXp5XG4gICAgICB9XG4gICAgfVxuICB9LFxuICBkYXRhOiBmdW5jdGlvbiBkYXRhKCkge1xuICAgIHJldHVybiB7XG4gICAgICBtc2c6ICdXZWxjb21lIHRvIFlvdXIgVnVlLmpzIEFwcCcsXG4gICAgICBpc0NyYXp5OiBmYWxzZVxuICAgIH1cbiAgfSxcbiAgbWV0aG9kczoge1xuICAgIHRvZ2dsZUNsYXNzOiBmdW5jdGlvbiB0b2dnbGVDbGFzcygpIHtcbiAgICAgIHRoaXMuaXNDcmF6eSA9ICF0aGlzLmlzQ3JhenlcbiAgICB9XG4gIH1cbn1cbiJdfQ=="
14095
`;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<template>
2-
<div />
2+
<h1>Coffee</h1>
33
</template>
44

55
<script lang="coffee">
66
export default
7+
name: 'coffee'
78
data: -> {}
89
</script>

e2e/__projects__/basic/components/CoffeeScript.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div />
2+
<h1>CoffeeScript</h1>
33
</template>
44

55
<script lang="coffeescript">

e2e/__projects__/basic/components/Pug.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
2-
extends /components/PugBase.pug
3-
block component
4-
div(class="pug-extended")
2+
extends /components/PugBase.pug
3+
block component
4+
div(class="pug-extended")
55
</template>
66

77
<script>

e2e/__projects__/basic/components/PugRelativeExtends.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
2-
extends ./relative/PugRelativeBase.pug
3-
block component
4-
div(class="pug-extended")
2+
extends ./relative/PugRelativeBase.pug
3+
block component
4+
div(class="pug-extended")
55
</template>
66

77
<script>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script>
2+
import { h } from 'vue'
23
export default {
34
name: 'RenderFunction',
4-
render(createElement) {
5-
return createElement('section', [this.$slots.default])
5+
render() {
6+
return h('section', this.$slots.default())
67
}
78
}
89
</script>

e2e/__projects__/basic/components/TypeScript.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<template>
22
<div>
3-
{{ exclamationMarks }}
3+
<div id="parent">
4+
{{ exclamationMarks }}
5+
</div>
46
<type-script-child />
57
</div>
68
</template>
79

810
<script lang="ts">
911
import TypeScriptChild from './TypeScriptChild.vue'
10-
1112
export default {
1213
computed: {
1314
exclamationMarks(): string {
14-
return 'string'
15+
return 'Parent'
1516
}
1617
},
1718
components: {

e2e/__projects__/basic/components/TypeScriptChild.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<template>
2-
<div>{{ exclamationMarks }}</div>
2+
<div id="child">{{ exclamationMarks }}</div>
33
</template>
44

55
<script lang="ts">
66
export default {
77
computed: {
88
exclamationMarks(): string {
9-
return 'string'
9+
return 'Child'
1010
}
1111
}
1212
}

e2e/__projects__/basic/test.js

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
1-
import { mount } from '@vue/test-utils'
2-
import TypeScript from './components/TypeScript.vue'
1+
const { createApp, h } = require('vue')
32
import { resolve } from 'path'
43
import { readFileSync } from 'fs'
5-
import jestVue from 'vue-jest'
6-
import RenderFunction from './components/RenderFunction.vue'
7-
import Jade from './components/Jade.vue'
8-
import FunctionalSFC from './components/FunctionalSFC.vue'
9-
import Basic from './components/Basic.vue'
4+
105
import BasicSrc from './components/BasicSrc.vue'
11-
import { randomExport } from './components/NamedExport.vue'
6+
import Pug from './components/Pug.vue'
127
import Coffee from './components/Coffee.vue'
8+
import Basic from './components/Basic.vue'
9+
import TypeScript from './components/TypeScript.vue'
10+
import jestVue from '../../../'
11+
import RenderFunction from './components/RenderFunction.vue'
12+
import FunctionalSFC from './components/FunctionalSFC.vue'
1313
import CoffeeScript from './components/CoffeeScript.vue'
1414
import FunctionalSFCParent from './components/FunctionalSFCParent.vue'
1515
import NoScript from './components/NoScript.vue'
16-
import Pug from './components/Pug.vue'
1716
import PugRelative from './components/PugRelativeExtends.vue'
18-
import Jsx from './components/Jsx.vue'
19-
import Constructor from './components/Constructor.vue'
17+
import { randomExport } from './components/NamedExport.vue'
18+
// TODO: JSX for Vue 3? TSX?
19+
// import Jsx from './components/Jsx.vue'
20+
21+
function mount(Component, props, slots) {
22+
document.getElementsByTagName('html')[0].innerHTML = ''
23+
const el = document.createElement('div')
24+
el.id = 'app'
25+
document.body.appendChild(el)
26+
const Parent = {
27+
render() {
28+
return h(Component, props, slots)
29+
}
30+
}
31+
const app = createApp(Parent).mount(el)
32+
}
2033

2134
test('processes .vue files', () => {
22-
const wrapper = mount(Basic)
23-
expect(wrapper.vm.msg).toEqual('Welcome to Your Vue.js App')
24-
wrapper.vm.toggleClass()
35+
mount(Basic)
36+
expect(document.querySelector('h1').textContent).toBe(
37+
'Welcome to Your Vue.js App'
38+
)
2539
})
2640

2741
test('processes .vue files with src attributes', () => {
28-
const wrapper = mount(BasicSrc)
29-
wrapper.vm.toggleClass()
42+
mount(BasicSrc)
43+
expect(document.querySelector('h1').textContent).toBe(
44+
'Welcome to Your Vue.js App'
45+
)
3046
})
3147

3248
test('handles named exports', () => {
@@ -55,73 +71,61 @@ test('generates source maps using src attributes', () => {
5571
expect(code).toMatchSnapshot()
5672
})
5773

58-
test('processes .vue file using jsx', () => {
59-
const wrapper = mount(Jsx)
60-
expect(wrapper.is('div')).toBeTruthy()
61-
})
62-
63-
test('processes extended functions', () => {
64-
const wrapper = mount(Constructor)
65-
expect(wrapper.is('div')).toBeTruthy()
66-
})
67-
6874
test('processes .vue file with lang set to coffee', () => {
69-
const wrapper = mount(Coffee)
70-
expect(wrapper.is('div')).toBeTruthy()
75+
mount(Coffee)
76+
expect(document.querySelector('h1').textContent).toBe('Coffee')
7177
})
7278

7379
test('processes .vue file with lang set to coffeescript', () => {
74-
const wrapper = mount(CoffeeScript)
75-
expect(wrapper.is('div')).toBeTruthy()
80+
mount(CoffeeScript)
81+
expect(document.querySelector('h1').textContent).toBe('CoffeeScript')
7682
})
7783

78-
test('processes .vue files with lang set to typescript', () => {
79-
const wrapper = mount(TypeScript)
80-
expect(wrapper.is('div')).toBeTruthy()
84+
test('processes SFC with no template', () => {
85+
const wrapper = mount(
86+
RenderFunction,
87+
{},
88+
{ default: () => h('div', { id: 'slot' }) }
89+
)
90+
expect(document.querySelector('#slot')).toBeTruthy()
8191
})
8292

83-
test('processes functional components', () => {
84-
const clickSpy = jest.fn()
85-
const wrapper = mount(FunctionalSFC, {
86-
context: {
87-
props: { msg: { id: 1, title: 'foo' }, onClick: clickSpy }
88-
}
89-
})
90-
expect(wrapper.text().trim()).toBe('foo')
91-
wrapper.trigger('click')
92-
expect(clickSpy).toHaveBeenCalledWith(1)
93+
test('processes .vue files with lang set to typescript', () => {
94+
const wrapper = mount(TypeScript)
95+
expect(document.querySelector('#parent').textContent).toBe('Parent')
96+
expect(document.querySelector('#child').textContent).toBe('Child')
9397
})
9498

95-
test('processes SFC with functional template from parent', () => {
96-
const wrapper = mount(FunctionalSFCParent)
97-
expect(wrapper.text().trim()).toBe('foo')
99+
test('handles missing script block', () => {
100+
mount(NoScript)
101+
expect(document.querySelector('.footer').textContent).toBe("I'm footer!")
98102
})
99103

100-
test('handles missing script block', () => {
101-
const wrapper = mount(NoScript)
102-
expect(wrapper.contains('footer'))
104+
test('processes pug templates', () => {
105+
mount(Pug)
106+
expect(document.querySelector('.pug-base')).toBeTruthy()
107+
expect(document.querySelector('.pug-extended')).toBeTruthy()
103108
})
104109

105-
test('processes .vue file with jade template', () => {
106-
const wrapper = mount(Jade)
107-
expect(wrapper.is('div')).toBeTruthy()
108-
expect(wrapper.classes()).toContain('jade')
110+
test('supports relative paths when extending templates from .pug files', () => {
111+
mount(PugRelative)
112+
expect(document.querySelector('.pug-relative-base')).toBeTruthy()
109113
})
110114

111-
test('processes pug templates', () => {
112-
const wrapper = mount(Pug)
113-
expect(wrapper.is('div')).toBeTruthy()
114-
expect(wrapper.classes()).toContain('pug-base')
115-
expect(wrapper.find('.pug-extended').exists()).toBeTruthy()
115+
// TODO: How do functional components work in Vue 3?
116+
xtest('processes functional components', () => {
117+
const clickSpy = jest.fn()
118+
mount(FunctionalSFC)
116119
})
117120

118-
test('supports relative paths when extending templates from .pug files', () => {
119-
const wrapper = mount(PugRelative)
120-
expect(wrapper.is('div')).toBeTruthy()
121-
expect(wrapper.find('.pug-relative-base').exists()).toBeTruthy()
121+
// TODO: How do functional components work in Vue 3?
122+
xtest('processes SFC with functional template from parent', () => {
123+
mount(FunctionalSFCParent)
124+
expect(document.querySelector('div').textContent).toBe('foo')
122125
})
123126

124-
test('processes SFC with no template', () => {
125-
const wrapper = mount(RenderFunction)
126-
expect(wrapper.is('section')).toBe(true)
127+
// TODO: JSX in Vue 3?
128+
xtest('processes .vue file using jsx', () => {
129+
const wrapper = mount(Jsx)
130+
expect(document.querySelector('#jsx')).toBeTruthy()
127131
})

0 commit comments

Comments
 (0)