Skip to content

Commit 01686a0

Browse files
authoredMay 4, 2018
fix: remove Array.find (#572)
run tests in phantom fixes #499
1 parent ee84e13 commit 01686a0

File tree

14 files changed

+315
-139
lines changed

14 files changed

+315
-139
lines changed
 

‎package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
"lint:fix": "npm run lint -- --fix",
2020
"prepublish": "npm run build && npm run test:unit:only",
2121
"publish": "lerna publish --conventional-commits -m \"chore(release): publish %s\"",
22-
"test": "npm run lint && npm run lint:docs && npm run flow && npm run test:types && npm run test:unit && npm run test:unit:karma npm run test:unit:node",
22+
"test": "npm run lint && npm run lint:docs && npm run flow && npm run test:types && npm run test:unit && npm run test:unit:karma && npm run test:unit:node",
2323
"test:compat": "scripts/test-compat.sh",
2424
"test:unit": "npm run build:test && npm run test:unit:only",
2525
"test:unit:only": "mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
2626
"test:unit:debug": "npm run build:test && node --inspect-brk node_modules/.bin/mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
27-
"test:unit:karma": "npm run build:test TARGET=browser karma start test/setup/karma.conf.js --single-run",
27+
"test:unit:karma": "npm run build:test && TARGET=browser karma start test/setup/karma.conf.js --single-run",
2828
"test:unit:node": "npm run build:test && npm run test:unit:node:only",
29+
"test:unit:node:only": "TEST_ENV=node mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
2930
"test:types": "tsc -p packages/test-utils/types && tsc -p packages/server-test-utils/types"
3031
},
3132
"devDependencies": {
@@ -54,6 +55,7 @@
5455
"karma": "^1.7.0",
5556
"karma-chrome-launcher": "^2.2.0",
5657
"karma-mocha": "^1.3.0",
58+
"karma-phantomjs-launcher": "^1.0.4",
5759
"karma-sinon-chai": "^1.3.1",
5860
"karma-sourcemap-loader": "^0.3.7",
5961
"karma-spec-reporter": "^0.0.31",

‎packages/test-utils/src/mount.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ export default function mount (component: Component, options: Options = {}): Vue
2929
} else {
3030
vm.$mount()
3131
}
32+
const componentsWithError = findAllVueComponentsFromVm(vm).filter(c => c._error)
3233

33-
const componentWithError = findAllVueComponentsFromVm(vm).find(c => c._error)
34-
35-
if (componentWithError) {
36-
throw (componentWithError._error)
34+
if (componentsWithError.length > 0) {
35+
throw (componentsWithError[0]._error)
3736
}
3837

3938
const wrapperOptions = {

‎test/resources/utils.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export const isRunningJSDOM =
1111
navigator.userAgent.includes &&
1212
navigator.userAgent.includes('jsdom')
1313

14+
export const isRunningPhantomJS =
15+
typeof navigator !== 'undefined' &&
16+
navigator.userAgent.includes &&
17+
navigator.userAgent.match(/PhantomJS/i)
18+
1419
export function injectSupported () {
1520
return vueVersion > 2.2
1621
}

‎test/setup/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const webpackConfig = require('./webpack.test.config.js')
22

33
module.exports = function (config) {
44
config.set({
5-
browsers: ['ChromeHeadless'],
5+
browsers: ['PhantomJS', 'ChromeHeadless'],
66
frameworks: ['mocha', 'sinon-chai'],
77
reporters: ['spec'],
88
files: [

‎test/specs/mounting-options/attrs.spec.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { compileToFunctions } from 'vue-template-compiler'
22
import { attrsSupported } from '~resources/utils'
33
import {
44
describeWithMountingMethods,
5-
itSkipIf
5+
itSkipIf,
6+
isRunningPhantomJS
67
} from '~resources/utils'
78

89
describeWithMountingMethods('options.attrs', (mountingMethod) => {
9-
itSkipIf(mountingMethod.name === 'renderToString',
10+
itSkipIf(
11+
mountingMethod.name === 'renderToString' || isRunningPhantomJS,
1012
'handles inherit attrs', () => {
1113
if (!attrsSupported()) return
1214
const wrapper = mountingMethod(compileToFunctions('<p :id="anAttr" />'), {

‎test/specs/mounting-options/listeners.spec.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
import { compileToFunctions } from 'vue-template-compiler'
22
import { listenersSupported } from '~resources/utils'
3-
import { describeWithShallowAndMount } from '~resources/utils'
3+
import {
4+
describeWithShallowAndMount,
5+
itSkipIf,
6+
isRunningPhantomJS
7+
} from '~resources/utils'
48

59
describeWithShallowAndMount('options.listeners', (mountingMethod) => {
6-
it('handles inherit listeners', () => {
7-
if (!listenersSupported()) return
8-
const aListener = () => {}
9-
const wrapper = mountingMethod(compileToFunctions('<p :id="aListener" />'), {
10-
listeners: {
11-
aListener
12-
}
13-
})
10+
itSkipIf(isRunningPhantomJS,
11+
'handles inherit listeners', () => {
12+
if (!listenersSupported()) return
13+
const aListener = () => {}
14+
const wrapper = mountingMethod(compileToFunctions('<p :id="aListener" />'), {
15+
listeners: {
16+
aListener
17+
}
18+
})
1419

15-
expect(wrapper.vm.$listeners.aListener).to.equal(aListener)
16-
expect(wrapper.vm.$listeners.aListener).to.equal(aListener)
17-
})
20+
expect(wrapper.vm.$listeners.aListener).to.equal(aListener)
21+
expect(wrapper.vm.$listeners.aListener).to.equal(aListener)
22+
})
1823

1924
it('defines listeners as empty object even when not passed', () => {
2025
const wrapper = mountingMethod(compileToFunctions('<p />'))
+26-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
import Vue from 'vue'
2-
import { describeWithMountingMethods } from '~resources/utils'
2+
import {
3+
describeWithMountingMethods,
4+
itSkipIf,
5+
isRunningPhantomJS
6+
} from '~resources/utils'
37

48
describeWithMountingMethods('options.localVue', (mountingMethod) => {
5-
it('mounts component using passed localVue as base Vue', () => {
6-
const TestComponent = {
7-
template: `
9+
itSkipIf(
10+
isRunningPhantomJS,
11+
'mounts component using passed localVue as base Vue', () => {
12+
const TestComponent = {
13+
template: `
814
<div>{{test}}</div>
915
`
10-
}
11-
const localVue = Vue.extend()
12-
localVue.version = '2.3'
13-
const wrapper = mountingMethod(TestComponent, {
14-
localVue: localVue,
15-
mocks: { test: 'some value' }
16+
}
17+
const localVue = Vue.extend()
18+
localVue.version = '2.3'
19+
const wrapper = mountingMethod(TestComponent, {
20+
localVue: localVue,
21+
mocks: { test: 'some value' }
22+
})
23+
const HTML = mountingMethod.name === 'renderToString'
24+
? wrapper
25+
: wrapper.html()
26+
expect(HTML).to.contain('some value')
27+
const freshWrapper = mountingMethod(TestComponent)
28+
const freshHTML = mountingMethod.name === 'renderToString'
29+
? freshWrapper
30+
: freshWrapper.html()
31+
expect(freshHTML).to.not.contain('some value')
1632
})
17-
const HTML = mountingMethod.name === 'renderToString'
18-
? wrapper
19-
: wrapper.html()
20-
expect(HTML).to.contain('some value')
21-
const freshWrapper = mountingMethod(TestComponent)
22-
const freshHTML = mountingMethod.name === 'renderToString'
23-
? freshWrapper
24-
: freshWrapper.html()
25-
expect(freshHTML).to.not.contain('some value')
26-
})
2733
})

‎test/specs/mounting-options/scopedSlots.spec.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { describeWithShallowAndMount, vueVersion, itDoNotRunIf } from '~resources/utils'
1+
import {
2+
describeWithShallowAndMount,
3+
vueVersion,
4+
itDoNotRunIf,
5+
isRunningPhantomJS
6+
} from '~resources/utils'
27
import ComponentWithScopedSlots from '~resources/components/component-with-scoped-slots.vue'
38

49
describeWithShallowAndMount('scopedSlots', (mountingMethod) => {
@@ -14,7 +19,7 @@ describeWithShallowAndMount('scopedSlots', (mountingMethod) => {
1419
}
1520
})
1621

17-
itDoNotRunIf(vueVersion < 2.5,
22+
itDoNotRunIf(vueVersion < 2.5 || isRunningPhantomJS,
1823
'mounts component scoped slots', () => {
1924
const wrapper = mountingMethod(ComponentWithScopedSlots, {
2025
slots: { default: '<span>123</span>' },
@@ -41,7 +46,7 @@ describeWithShallowAndMount('scopedSlots', (mountingMethod) => {
4146
}
4247
)
4348

44-
itDoNotRunIf(vueVersion < 2.5,
49+
itDoNotRunIf(vueVersion < 2.5 || isRunningPhantomJS,
4550
'throws exception when it is seted to a template tag at top', () => {
4651
const fn = () => {
4752
mountingMethod(ComponentWithScopedSlots, {
@@ -55,7 +60,7 @@ describeWithShallowAndMount('scopedSlots', (mountingMethod) => {
5560
}
5661
)
5762

58-
itDoNotRunIf(vueVersion >= 2.5,
63+
itDoNotRunIf(vueVersion >= 2.5 || isRunningPhantomJS,
5964
'throws exception when vue version < 2.5', () => {
6065
const fn = () => {
6166
mountingMethod(ComponentWithScopedSlots, {

‎test/specs/mounting-options/slots.spec.js

+36-32
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
describeWithMountingMethods,
77
vueVersion,
88
itSkipIf,
9-
itDoNotRunIf
9+
itDoNotRunIf,
10+
isRunningPhantomJS
1011
} from '~resources/utils'
1112

1213
describeWithMountingMethods('options.slots', (mountingMethod) => {
@@ -53,7 +54,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
5354
})
5455

5556
itDoNotRunIf(
56-
process.env.TEST_ENV === 'node',
57+
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
5758
'mounts component with default slot if passed string in slot object', () => {
5859
const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: '<span />' }})
5960
if (mountingMethod.name === 'renderToString') {
@@ -64,7 +65,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
6465
})
6566

6667
itDoNotRunIf(
67-
process.env.TEST_ENV === 'node' || vueVersion < 2.3,
68+
process.env.TEST_ENV === 'node' || vueVersion < 2.3 || isRunningPhantomJS,
6869
'works correctly with class component', () => {
6970
const wrapper = mountingMethod(ComponentAsAClass, { slots: { default: '<span />' }})
7071
if (mountingMethod.name === 'renderToString') {
@@ -91,26 +92,28 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
9192
expect(fn).to.throw().with.property('message', message)
9293
})
9394

94-
it('mounts component with default slot if passed string in slot object', () => {
95-
if (mountingMethod.name === 'renderToString') {
96-
return
97-
}
98-
const wrapper1 = mountingMethod(ComponentWithSlots, { slots: { default: 'foo<span>123</span>{{ foo }}' }})
99-
expect(wrapper1.find('main').html()).to.equal('<main>foo<span>123</span>bar</main>')
100-
const wrapper2 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}2' }})
101-
expect(wrapper2.find('main').html()).to.equal('<main><p>1</p>bar2</main>')
102-
const wrapper3 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}<p>2</p>' }})
103-
expect(wrapper3.find('main').html()).to.equal('<main><p>1</p>bar<p>2</p></main>')
104-
const wrapper4 = mountingMethod(ComponentWithSlots, { slots: { default: '123' }})
105-
expect(wrapper4.find('main').html()).to.equal('<main>123</main>')
106-
const wrapper5 = mountingMethod(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }})
107-
expect(wrapper5.find('main').html()).to.equal('<main>1bar2</main>')
108-
wrapper5.trigger('keydown')
109-
const wrapper6 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p><p>2</p>' }})
110-
expect(wrapper6.find('main').html()).to.equal('<main><p>1</p><p>2</p></main>')
111-
const wrapper7 = mountingMethod(ComponentWithSlots, { slots: { default: '1<p>2</p>3' }})
112-
expect(wrapper7.find('main').html()).to.equal('<main>1<p>2</p>3</main>')
113-
})
95+
itDoNotRunIf(
96+
isRunningPhantomJS,
97+
'mounts component with default slot if passed string in slot object', () => {
98+
if (mountingMethod.name === 'renderToString') {
99+
return
100+
}
101+
const wrapper1 = mountingMethod(ComponentWithSlots, { slots: { default: 'foo<span>123</span>{{ foo }}' }})
102+
expect(wrapper1.find('main').html()).to.equal('<main>foo<span>123</span>bar</main>')
103+
const wrapper2 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}2' }})
104+
expect(wrapper2.find('main').html()).to.equal('<main><p>1</p>bar2</main>')
105+
const wrapper3 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}<p>2</p>' }})
106+
expect(wrapper3.find('main').html()).to.equal('<main><p>1</p>bar<p>2</p></main>')
107+
const wrapper4 = mountingMethod(ComponentWithSlots, { slots: { default: '123' }})
108+
expect(wrapper4.find('main').html()).to.equal('<main>123</main>')
109+
const wrapper5 = mountingMethod(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }})
110+
expect(wrapper5.find('main').html()).to.equal('<main>1bar2</main>')
111+
wrapper5.trigger('keydown')
112+
const wrapper6 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p><p>2</p>' }})
113+
expect(wrapper6.find('main').html()).to.equal('<main><p>1</p><p>2</p></main>')
114+
const wrapper7 = mountingMethod(ComponentWithSlots, { slots: { default: '1<p>2</p>3' }})
115+
expect(wrapper7.find('main').html()).to.equal('<main>1<p>2</p>3</main>')
116+
})
114117

115118
itSkipIf(mountingMethod.name === 'renderToString',
116119
'throws error if passed string in default slot object and vue-template-compiler is undefined', () => {
@@ -130,7 +133,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
130133
})
131134

132135
itDoNotRunIf(
133-
process.env.TEST_ENV === 'node',
136+
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
134137
'mounts component with default slot if passed string in slot array object', () => {
135138
const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: ['<span />'] }})
136139
if (mountingMethod.name === 'renderToString') {
@@ -141,7 +144,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
141144
})
142145

143146
itDoNotRunIf(
144-
process.env.TEST_ENV === 'node',
147+
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
145148
'mounts component with default slot if passed string in slot text array object', () => {
146149
const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: ['{{ foo }}<span>1</span>', 'bar'] }})
147150
if (mountingMethod.name === 'renderToString') {
@@ -241,7 +244,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
241244
}
242245
})
243246

244-
itDoNotRunIf(process.env.TEST_ENV === 'node',
247+
itDoNotRunIf(process.env.TEST_ENV === 'node' || isRunningPhantomJS,
245248
'mounts component with default slot if passed string in slot object', () => {
246249
const TestComponent = {
247250
name: 'component-with-slots',
@@ -257,7 +260,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
257260
})
258261

259262
itDoNotRunIf(
260-
process.env.TEST_ENV === 'node',
263+
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
261264
'mounts component with named slot if passed string in slot object', () => {
262265
const TestComponent = {
263266
functional: true,
@@ -272,7 +275,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
272275
})
273276

274277
itDoNotRunIf(
275-
process.env.TEST_ENV === 'node',
278+
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
276279
'mounts component with named slot if passed string in slot object in array', () => {
277280
const TestComponent = {
278281
functional: true,
@@ -287,7 +290,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
287290
})
288291

289292
itDoNotRunIf(
290-
process.env.TEST_ENV === 'node',
293+
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
291294
'mounts component with named slot if passed string in slot object in array', () => {
292295
const TestComponent = {
293296
functional: true,
@@ -302,7 +305,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
302305
})
303306

304307
itDoNotRunIf(
305-
process.env.TEST_ENV === 'node',
308+
process.env.TEST_ENV === 'node' || isRunningPhantomJS,
306309
'mounts component with named slot if passed string in slot object in array', () => {
307310
const TestComponent = {
308311
functional: true,
@@ -382,8 +385,9 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
382385
require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave
383386
})
384387

385-
itDoNotRunIf(mountingMethod.name === 'renderToString',
386-
'afd', () => {
388+
itDoNotRunIf(
389+
mountingMethod.name === 'renderToString' || isRunningPhantomJS,
390+
'does not error when triggering a click in a slot', () => {
387391
const Parent = {
388392
name: 'Parent',
389393
template: `

0 commit comments

Comments
 (0)
Please sign in to comment.