Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1ff0540

Browse files
committedJul 22, 2018
chore(release): add dist files
1 parent 9ae83e4 commit 1ff0540

File tree

4 files changed

+12056
-13259
lines changed

4 files changed

+12056
-13259
lines changed
 

‎packages/server-test-utils/dist/vue-server-test-utils.js

Lines changed: 338 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,56 @@ var cheerio = _interopDefault(require('cheerio'));
1010

1111
//
1212

13-
function startsWithTag (str) {
14-
return str && str.trim()[0] === '<'
13+
function createVNodes (
14+
vm,
15+
slotValue
16+
) {
17+
var el = vueTemplateCompiler.compileToFunctions(("<div>" + slotValue + "</div>"));
18+
var _staticRenderFns = vm._renderProxy.$options.staticRenderFns;
19+
// version < 2.5
20+
if (!vm._renderProxy._staticTrees) {
21+
vm._renderProxy._staticTrees = [];
22+
}
23+
vm._renderProxy.$options.staticRenderFns = el.staticRenderFns;
24+
var vnode = el.render.call(vm._renderProxy, vm.$createElement);
25+
vm._renderProxy.$options.staticRenderFns = _staticRenderFns;
26+
return vnode.children
1527
}
1628

1729
function createVNodesForSlot (
18-
h,
30+
vm,
1931
slotValue,
2032
name
2133
) {
22-
if (typeof slotValue === 'string' && !startsWithTag(slotValue)) {
23-
return slotValue
34+
var vnode;
35+
if (typeof slotValue === 'string') {
36+
var vnodes = createVNodes(vm, slotValue);
37+
vnode = vnodes[0];
38+
} else {
39+
vnode = vm.$createElement(slotValue);
40+
}
41+
if (vnode.data) {
42+
vnode.data.slot = name;
43+
} else {
44+
vnode.data = { slot: name };
2445
}
25-
26-
var el =
27-
typeof slotValue === 'string' ? vueTemplateCompiler.compileToFunctions(slotValue) : slotValue;
28-
29-
var vnode = h(el);
30-
vnode.data.slot = name;
3146
return vnode
3247
}
3348

3449
function createSlotVNodes (
35-
h,
50+
vm,
3651
slots
3752
) {
3853
return Object.keys(slots).reduce(function (acc, key) {
3954
var content = slots[key];
4055
if (Array.isArray(content)) {
41-
var nodes = content.map(function (slotDef) { return createVNodesForSlot(h, slotDef, key); });
56+
var nodes = content.map(
57+
function (slotDef) { return createVNodesForSlot(vm, slotDef, key); }
58+
);
4259
return acc.concat(nodes)
4360
}
4461

45-
return acc.concat(createVNodesForSlot(h, content, key))
62+
return acc.concat(createVNodesForSlot(vm, content, key))
4663
}, [])
4764
}
4865

@@ -82,7 +99,10 @@ var vueVersion = Number(
8299

83100
//
84101

85-
function addMocks (mockedProperties, Vue$$1) {
102+
function addMocks (
103+
mockedProperties,
104+
Vue$$1
105+
) {
86106
Object.keys(mockedProperties).forEach(function (key) {
87107
try {
88108
Vue$$1.prototype[key] = mockedProperties[key];
@@ -127,6 +147,26 @@ function addEventLogger (vue) {
127147

128148
//
129149

150+
function isVueComponent (component) {
151+
if (typeof component === 'function' && component.options) {
152+
return true
153+
}
154+
155+
if (component === null || typeof component !== 'object') {
156+
return false
157+
}
158+
159+
if (component.extends || component._Ctor) {
160+
return true
161+
}
162+
163+
if (typeof component.template === 'string') {
164+
return true
165+
}
166+
167+
return typeof component.render === 'function'
168+
}
169+
130170
function componentNeedsCompiling (component) {
131171
return (
132172
component &&
@@ -136,13 +176,20 @@ function componentNeedsCompiling (component) {
136176
)
137177
}
138178

139-
function templateContainsComponent (template, name) {
179+
function templateContainsComponent (
180+
template,
181+
name
182+
) {
140183
return [capitalize, camelize, hyphenate].some(function (format) {
141184
var re = new RegExp(("<" + (format(name)) + "\\s*(\\s|>|(/>))"), 'g');
142185
return re.test(template)
143186
})
144187
}
145188

189+
function isPlainObject (obj) {
190+
return Object.prototype.toString.call(obj) === '[object Object]'
191+
}
192+
146193
//
147194

148195
function compileTemplate (component) {
@@ -170,36 +217,46 @@ function compileTemplate (component) {
170217

171218
//
172219

173-
function isVueComponent$1 (comp) {
174-
return comp && (comp.render || comp.template || comp.options)
220+
function isVueComponentStub (comp) {
221+
return comp && comp.template || isVueComponent(comp)
175222
}
176223

177224
function isValidStub (stub) {
178225
return (
179226
(!!stub && typeof stub === 'string') ||
180227
stub === true ||
181-
isVueComponent$1(stub)
228+
isVueComponentStub(stub)
182229
)
183230
}
184231

185-
function getCoreProperties (component) {
232+
function resolveComponent (obj, component) {
233+
return obj[component] ||
234+
obj[hyphenate(component)] ||
235+
obj[camelize(component)] ||
236+
obj[capitalize(camelize(component))] ||
237+
obj[capitalize(component)] ||
238+
{}
239+
}
240+
241+
function getCoreProperties (componentOptions) {
186242
return {
187-
attrs: component.attrs,
188-
name: component.name,
189-
on: component.on,
190-
key: component.key,
191-
ref: component.ref,
192-
props: component.props,
193-
domProps: component.domProps,
194-
class: component.class,
195-
staticClass: component.staticClass,
196-
staticStyle: component.staticStyle,
197-
style: component.style,
198-
normalizedStyle: component.normalizedStyle,
199-
nativeOn: component.nativeOn,
200-
functional: component.functional
243+
attrs: componentOptions.attrs,
244+
name: componentOptions.name,
245+
on: componentOptions.on,
246+
key: componentOptions.key,
247+
ref: componentOptions.ref,
248+
props: componentOptions.props,
249+
domProps: componentOptions.domProps,
250+
class: componentOptions.class,
251+
staticClass: componentOptions.staticClass,
252+
staticStyle: componentOptions.staticStyle,
253+
style: componentOptions.style,
254+
normalizedStyle: componentOptions.normalizedStyle,
255+
nativeOn: componentOptions.nativeOn,
256+
functional: componentOptions.functional
201257
}
202258
}
259+
203260
function createStubFromString (
204261
templateString,
205262
originalComponent,
@@ -217,21 +274,34 @@ function createStubFromString (
217274
throwError('options.stub cannot contain a circular reference');
218275
}
219276

220-
return Object.assign({}, getCoreProperties(originalComponent),
277+
var componentOptions = typeof originalComponent === 'function'
278+
? originalComponent.extendOptions
279+
: originalComponent;
280+
281+
return Object.assign({}, getCoreProperties(componentOptions),
221282
vueTemplateCompiler.compileToFunctions(templateString))
222283
}
223284

224-
function createBlankStub (originalComponent) {
225-
var name = (originalComponent.name) + "-stub";
285+
function createBlankStub (
286+
originalComponent,
287+
name
288+
) {
289+
var componentOptions = typeof originalComponent === 'function'
290+
? originalComponent.extendOptions
291+
: originalComponent;
292+
var tagName = name + "-stub";
226293

227294
// ignoreElements does not exist in Vue 2.0.x
228295
if (Vue.config.ignoredElements) {
229-
Vue.config.ignoredElements.push(name);
296+
Vue.config.ignoredElements.push(tagName);
230297
}
231298

232-
return Object.assign({}, getCoreProperties(originalComponent),
299+
return Object.assign({}, getCoreProperties(componentOptions),
233300
{render: function render (h) {
234-
return h(name)
301+
return h(
302+
tagName,
303+
!componentOptions.functional && this.$slots.default
304+
)
235305
}})
236306
}
237307

@@ -254,78 +324,98 @@ function createComponentStubs (
254324
if (typeof stub !== 'string') {
255325
throwError("each item in an options.stubs array must be a " + "string");
256326
}
257-
components[stub] = createBlankStub({ name: stub });
327+
var component = resolveComponent(originalComponents, stub);
328+
329+
components[stub] = createBlankStub(component, stub);
258330
});
259331
} else {
260-
Object.keys(stubs).forEach(function (stub) {
261-
if (stubs[stub] === false) {
332+
var stubsObject = (stubs);
333+
Object.keys(stubsObject).forEach(function (stubName) {
334+
var stub = stubsObject[stubName];
335+
if (stub === false) {
262336
return
263337
}
264-
if (!isValidStub(stubs[stub])) {
338+
339+
if (!isValidStub(stub)) {
265340
throwError(
266341
"options.stub values must be passed a string or " + "component"
267342
);
268343
}
269-
if (stubs[stub] === true) {
270-
components[stub] = createBlankStub({ name: stub });
344+
345+
if (stub === true) {
346+
var component = resolveComponent(originalComponents, stubName);
347+
components[stubName] = createBlankStub(component, stubName);
271348
return
272349
}
273350

274-
if (componentNeedsCompiling(stubs[stub])) {
275-
compileTemplate(stubs[stub]);
351+
if (typeof stub !== 'string' && componentNeedsCompiling(stub)) {
352+
compileTemplate(stub);
276353
}
277354

278-
if (originalComponents[stub]) {
355+
if (originalComponents[stubName]) {
279356
// Remove cached constructor
280-
delete originalComponents[stub]._Ctor;
281-
if (typeof stubs[stub] === 'string') {
282-
components[stub] = createStubFromString(
283-
stubs[stub],
284-
originalComponents[stub],
285-
stub
357+
delete originalComponents[stubName]._Ctor;
358+
if (typeof stub === 'string') {
359+
components[stubName] = createStubFromString(
360+
stub,
361+
originalComponents[stubName],
362+
stubName
286363
);
287364
} else {
288-
components[stub] = Object.assign({}, stubs[stub],
289-
{name: originalComponents[stub].name});
365+
var stubObject = (stub);
366+
components[stubName] = Object.assign({}, stubObject,
367+
{name: originalComponents[stubName].name});
290368
}
291369
} else {
292-
if (typeof stubs[stub] === 'string') {
370+
if (typeof stub === 'string') {
293371
if (!vueTemplateCompiler.compileToFunctions) {
294372
throwError(
295373
"vueTemplateCompiler is undefined, you must pass " +
296374
"precompiled components if vue-template-compiler is " +
297375
"undefined"
298376
);
299377
}
300-
components[stub] = Object.assign({}, vueTemplateCompiler.compileToFunctions(stubs[stub]));
378+
components[stubName] = Object.assign({}, vueTemplateCompiler.compileToFunctions(stub));
301379
} else {
302-
components[stub] = Object.assign({}, stubs[stub]);
380+
var stubObject$1 = (stub);
381+
components[stubName] = Object.assign({}, stubObject$1);
303382
}
304383
}
305384
});
306385
}
307386
return components
308387
}
309388

310-
function deleteMountingOptions (options) {
311-
delete options.attachToDocument;
312-
delete options.mocks;
313-
delete options.slots;
314-
delete options.localVue;
315-
delete options.stubs;
316-
delete options.context;
317-
delete options.clone;
318-
delete options.attrs;
319-
delete options.listeners;
320-
delete options.propsData;
389+
//
390+
391+
var MOUNTING_OPTIONS = [
392+
'attachToDocument',
393+
'mocks',
394+
'slots',
395+
'localVue',
396+
'stubs',
397+
'context',
398+
'clone',
399+
'attrs',
400+
'listeners',
401+
'propsData'
402+
];
403+
404+
function extractInstanceOptions (
405+
options
406+
) {
407+
var instanceOptions = Object.assign({}, options);
408+
MOUNTING_OPTIONS.forEach(function (mountingOption) {
409+
delete instanceOptions[mountingOption];
410+
});
411+
return instanceOptions
321412
}
322413

323414
//
324415

325416
function isValidSlot (slot) {
326417
return (
327-
Array.isArray(slot) ||
328-
(slot !== null && typeof slot === 'object') ||
418+
isVueComponent(slot) ||
329419
typeof slot === 'string'
330420
)
331421
}
@@ -342,25 +432,17 @@ function requiresTemplateCompiler (slot) {
342432

343433
function validateSlots (slots) {
344434
Object.keys(slots).forEach(function (key) {
345-
if (!isValidSlot(slots[key])) {
346-
throwError(
347-
"slots[key] must be a Component, string or an array " + "of Components"
348-
);
349-
}
350-
351-
requiresTemplateCompiler(slots[key]);
435+
var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]];
352436

353-
if (Array.isArray(slots[key])) {
354-
slots[key].forEach(function (slotValue) {
355-
if (!isValidSlot(slotValue)) {
356-
throwError(
357-
"slots[key] must be a Component, string or an array " +
358-
"of Components"
359-
);
360-
}
361-
requiresTemplateCompiler(slotValue);
362-
});
363-
}
437+
slot.forEach(function (slotValue) {
438+
if (!isValidSlot(slotValue)) {
439+
throwError(
440+
"slots[key] must be a Component, string or an array " +
441+
"of Components"
442+
);
443+
}
444+
requiresTemplateCompiler(slotValue);
445+
});
364446
});
365447
}
366448

@@ -387,7 +469,7 @@ function createFunctionalComponent (
387469
mountingOptions.context.children.map(
388470
function (x) { return (typeof x === 'function' ? x(h) : x); }
389471
)) ||
390-
createSlotVNodes(h, mountingOptions.slots || {})
472+
createSlotVNodes(this, mountingOptions.slots || {})
391473
)
392474
},
393475
name: component.name,
@@ -397,6 +479,105 @@ function createFunctionalComponent (
397479

398480
//
399481

482+
function isDestructuringSlotScope (slotScope) {
483+
return slotScope[0] === '{' && slotScope[slotScope.length - 1] === '}'
484+
}
485+
486+
function getVueTemplateCompilerHelpers () {
487+
var vue = new Vue();
488+
var helpers = {};
489+
var names = [
490+
'_c',
491+
'_o',
492+
'_n',
493+
'_s',
494+
'_l',
495+
'_t',
496+
'_q',
497+
'_i',
498+
'_m',
499+
'_f',
500+
'_k',
501+
'_b',
502+
'_v',
503+
'_e',
504+
'_u',
505+
'_g'
506+
];
507+
names.forEach(function (name) {
508+
helpers[name] = vue._renderProxy[name];
509+
});
510+
return helpers
511+
}
512+
513+
function validateEnvironment () {
514+
if (window.navigator.userAgent.match(/PhantomJS/i)) {
515+
throwError(
516+
"the scopedSlots option does not support PhantomJS. " +
517+
"Please use Puppeteer, or pass a component."
518+
);
519+
}
520+
if (vueVersion < 2.5) {
521+
throwError("the scopedSlots option is only supported in " + "vue@2.5+.");
522+
}
523+
}
524+
525+
function validateTempldate (template) {
526+
if (template.trim().substr(0, 9) === '<template') {
527+
throwError(
528+
"the scopedSlots option does not support a template " +
529+
"tag as the root element."
530+
);
531+
}
532+
}
533+
534+
function createScopedSlots (
535+
scopedSlotsOption
536+
) {
537+
var scopedSlots = {};
538+
if (!scopedSlotsOption) {
539+
return scopedSlots
540+
}
541+
validateEnvironment();
542+
var helpers = getVueTemplateCompilerHelpers();
543+
var loop = function ( name ) {
544+
var template = scopedSlotsOption[name];
545+
validateTempldate(template);
546+
var render = vueTemplateCompiler.compileToFunctions(template).render;
547+
var domParser = new window.DOMParser();
548+
var _document = domParser.parseFromString(template, 'text/html');
549+
var slotScope = _document.body.firstChild.getAttribute(
550+
'slot-scope'
551+
);
552+
var isDestructuring = isDestructuringSlotScope(slotScope);
553+
scopedSlots[name] = function (props) {
554+
var obj;
555+
556+
if (isDestructuring) {
557+
return render.call(Object.assign({}, helpers, props))
558+
} else {
559+
return render.call(Object.assign({}, helpers, ( obj = {}, obj[slotScope] = props, obj)))
560+
}
561+
};
562+
};
563+
564+
for (var name in scopedSlotsOption) loop( name );
565+
return scopedSlots
566+
}
567+
568+
//
569+
570+
function compileTemplateForSlots (slots) {
571+
Object.keys(slots).forEach(function (key) {
572+
var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]];
573+
slot.forEach(function (slotValue) {
574+
if (componentNeedsCompiling(slotValue)) {
575+
compileTemplate(slotValue);
576+
}
577+
});
578+
});
579+
}
580+
400581
function createInstance (
401582
component,
402583
options,
@@ -406,6 +587,18 @@ function createInstance (
406587
// Remove cached constructor
407588
delete component._Ctor;
408589

590+
// mounting options are vue-test-utils specific
591+
//
592+
// instance options are options that are passed to the
593+
// root instance when it's instantiated
594+
//
595+
// component options are the root components options
596+
var componentOptions = typeof component === 'function'
597+
? component.extendOptions
598+
: component;
599+
600+
var instanceOptions = extractInstanceOptions(options);
601+
409602
if (options.mocks) {
410603
addMocks(options.mocks, _Vue);
411604
}
@@ -426,10 +619,6 @@ function createInstance (
426619

427620
addEventLogger(_Vue);
428621

429-
var instanceOptions = Object.assign({}, options);
430-
431-
deleteMountingOptions(instanceOptions);
432-
433622
var stubComponents = createComponentStubs(
434623
// $FlowIgnore
435624
component.components,
@@ -449,9 +638,9 @@ function createInstance (
449638
);
450639
}
451640
});
452-
Object.keys(component.components || {}).forEach(function (c) {
641+
Object.keys(componentOptions.components || {}).forEach(function (c) {
453642
if (
454-
component.components[c].extendOptions &&
643+
componentOptions.components[c].extendOptions &&
455644
!instanceOptions.components[c]
456645
) {
457646
if (options.logModifiedComponents) {
@@ -464,7 +653,9 @@ function createInstance (
464653
"option."
465654
);
466655
}
467-
instanceOptions.components[c] = _Vue.extend(component.components[c]);
656+
instanceOptions.components[c] = _Vue.extend(
657+
componentOptions.components[c]
658+
);
468659
}
469660
});
470661

@@ -482,6 +673,8 @@ function createInstance (
482673
});
483674

484675
if (options.slots) {
676+
compileTemplateForSlots(options.slots);
677+
// $FlowIgnore
485678
validateSlots(options.slots);
486679
}
487680

@@ -496,52 +689,66 @@ function createInstance (
496689
options.provide = function () { return obj; };
497690
}
498691

499-
var Parent = _Vue.extend({
500-
provide: options.provide,
501-
render: function render (h) {
502-
var slots = options.slots
503-
? createSlotVNodes(h, options.slots)
504-
: undefined;
505-
return h(
506-
Constructor,
507-
{
508-
ref: 'vm',
509-
props: options.propsData,
510-
on: options.listeners,
511-
attrs: options.attrs
512-
},
513-
slots
514-
)
515-
}
516-
});
692+
var scopedSlots = createScopedSlots(options.scopedSlots);
693+
694+
if (options.parentComponent && !isPlainObject(options.parentComponent)) {
695+
throwError(
696+
"options.parentComponent should be a valid Vue component " +
697+
"options object"
698+
);
699+
}
700+
701+
var parentComponentOptions = options.parentComponent || {};
702+
parentComponentOptions.provide = options.provide;
703+
parentComponentOptions.render = function (h) {
704+
var slots = options.slots
705+
? createSlotVNodes(this, options.slots)
706+
: undefined;
707+
return h(
708+
Constructor,
709+
{
710+
ref: 'vm',
711+
props: options.propsData,
712+
on: options.listeners,
713+
attrs: options.attrs,
714+
scopedSlots: scopedSlots
715+
},
716+
slots
717+
)
718+
};
719+
var Parent = _Vue.extend(parentComponentOptions);
517720

518721
return new Parent()
519722
}
520723

521724
//
522725

523-
function getOptions (key, options, config) {
524-
if (options || (config[key] && Object.keys(config[key]).length > 0)) {
525-
if (options instanceof Function) {
526-
return options
527-
} else if (Array.isArray(options)) {
528-
return options.concat( Object.keys(config[key] || {}))
529-
} else if (!(config[key] instanceof Function)) {
530-
return Object.assign({}, config[key],
531-
options)
532-
} else {
726+
function getOption (option, config) {
727+
if (option || (config && Object.keys(config).length > 0)) {
728+
if (option instanceof Function) {
729+
return option
730+
} else if (Array.isArray(option)) {
731+
return option.concat( Object.keys(config || {}))
732+
} else if (config instanceof Function) {
533733
throw new Error("Config can't be a Function.")
734+
} else {
735+
return Object.assign({}, config,
736+
option)
534737
}
535738
}
536739
}
537740

538741
function mergeOptions (options, config) {
742+
var mocks = (getOption(options.mocks, config.mocks));
743+
var methods = (
744+
(getOption(options.methods, config.methods)));
745+
var provide = ((getOption(options.provide, config.provide)));
539746
return Object.assign({}, options,
540747
{logModifiedComponents: config.logModifiedComponents,
541-
stubs: getOptions('stubs', options.stubs, config),
542-
mocks: getOptions('mocks', options.mocks, config),
543-
methods: getOptions('methods', options.methods, config),
544-
provide: getOptions('provide', options.provide, config),
748+
stubs: getOption(options.stubs, config.stubs),
749+
mocks: mocks,
750+
methods: methods,
751+
provide: provide,
545752
sync: !!(options.sync || options.sync === undefined)})
546753
}
547754

‎packages/test-utils/dist/vue-test-utils.iife.js

Lines changed: 3906 additions & 4376 deletions
Large diffs are not rendered by default.

‎packages/test-utils/dist/vue-test-utils.js

Lines changed: 3906 additions & 4376 deletions
Large diffs are not rendered by default.

‎packages/test-utils/dist/vue-test-utils.umd.js

Lines changed: 3906 additions & 4376 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.