Skip to content

Commit ae73ef4

Browse files
committed
chore: v1
1 parent 4a77a11 commit ae73ef4

File tree

4 files changed

+1016
-194
lines changed

4 files changed

+1016
-194
lines changed

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

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
66

77
var Vue = _interopDefault(require('vue'));
88
var vueTemplateCompiler = require('vue-template-compiler');
9-
var vueServerRenderer = require('vue-server-renderer');
109
var testUtils = require('@vue/test-utils');
1110
var testUtils__default = _interopDefault(testUtils);
11+
var vueServerRenderer = require('vue-server-renderer');
1212
var cheerio = _interopDefault(require('cheerio'));
1313

1414
//
@@ -1701,6 +1701,18 @@ var semver_40 = semver.prerelease;
17011701
var semver_41 = semver.intersects;
17021702
var semver_42 = semver.coerce;
17031703

1704+
var VUE_VERSION = Number(
1705+
((Vue.version.split('.')[0]) + "." + (Vue.version.split('.')[1]))
1706+
);
1707+
1708+
var BEFORE_RENDER_LIFECYCLE_HOOK = semver.gt(Vue.version, '2.1.8')
1709+
? 'beforeCreate'
1710+
: 'beforeMount';
1711+
1712+
var CREATE_ELEMENT_ALIAS = semver.gt(Vue.version, '2.1.5')
1713+
? '_c'
1714+
: '_h';
1715+
17041716
//
17051717

17061718
function throwError(msg) {
@@ -1768,6 +1780,15 @@ var isPhantomJS = UA && UA.includes && UA.match(/phantomjs/i);
17681780
var isEdge = UA && UA.indexOf('edge/') > 0;
17691781
var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
17701782

1783+
function warnDeprecated(method, fallback) {
1784+
if ( fallback === void 0 ) fallback = '';
1785+
1786+
if (!testUtils.config.showDeprecationWarnings) { return }
1787+
var msg = method + " is deprecated and will removed in the next major version";
1788+
if (fallback) { msg += " " + fallback; }
1789+
warn(msg);
1790+
}
1791+
17711792
//
17721793

17731794
function addMocks(
@@ -1822,18 +1843,6 @@ function addEventLogger(_Vue) {
18221843
});
18231844
}
18241845

1825-
var VUE_VERSION = Number(
1826-
((Vue.version.split('.')[0]) + "." + (Vue.version.split('.')[1]))
1827-
);
1828-
1829-
var BEFORE_RENDER_LIFECYCLE_HOOK = semver.gt(Vue.version, '2.1.8')
1830-
? 'beforeCreate'
1831-
: 'beforeMount';
1832-
1833-
var CREATE_ELEMENT_ALIAS = semver.gt(Vue.version, '2.1.5')
1834-
? '_c'
1835-
: '_h';
1836-
18371846
function addStubs(_Vue, stubComponents) {
18381847
var obj;
18391848

@@ -1846,6 +1855,33 @@ function addStubs(_Vue, stubComponents) {
18461855

18471856
//
18481857

1858+
function isDomSelector(selector) {
1859+
if (typeof selector !== 'string') {
1860+
return false
1861+
}
1862+
1863+
try {
1864+
if (typeof document === 'undefined') {
1865+
throwError(
1866+
"mount must be run in a browser environment like " +
1867+
"PhantomJS, jsdom or chrome"
1868+
);
1869+
}
1870+
} catch (error) {
1871+
throwError(
1872+
"mount must be run in a browser environment like " +
1873+
"PhantomJS, jsdom or chrome"
1874+
);
1875+
}
1876+
1877+
try {
1878+
document.querySelector(selector);
1879+
return true
1880+
} catch (error) {
1881+
return false
1882+
}
1883+
}
1884+
18491885
function isVueComponent(c) {
18501886
if (isConstructor(c)) {
18511887
return true
@@ -1911,6 +1947,14 @@ function isPlainObject(c) {
19111947
return Object.prototype.toString.call(c) === '[object Object]'
19121948
}
19131949

1950+
function isHTMLElement(c) {
1951+
if (typeof HTMLElement === 'undefined') {
1952+
return false
1953+
}
1954+
// eslint-disable-next-line no-undef
1955+
return c instanceof HTMLElement
1956+
}
1957+
19141958
function makeMap(str, expectsLowerCase) {
19151959
var map = Object.create(null);
19161960
var list = str.split(',');
@@ -2297,7 +2341,7 @@ function createStubFromComponent(
22972341

22982342
// DEPRECATED: converts string stub to template stub.
22992343
function createStubFromString(templateString, name) {
2300-
warn('String stubs are deprecated and will be removed in future versions');
2344+
warnDeprecated('Using a string for stubs');
23012345

23022346
if (templateContainsComponent(templateString, name)) {
23032347
throwError('options.stub cannot contain a circular reference');
@@ -2644,6 +2688,10 @@ function mergeOptions(
26442688
) {
26452689
var mocks = (getOption(options.mocks, config.mocks));
26462690
var methods = (getOption(options.methods, config.methods));
2691+
if (methods && Object.keys(methods).length) {
2692+
warnDeprecated('overwriting methods via the `methods` property');
2693+
}
2694+
26472695
var provide = (getOption(options.provide, config.provide));
26482696
var stubs = (getStubs(options.stubs, config.stubs));
26492697
// $FlowIgnore
@@ -2702,6 +2750,20 @@ function vueExtendUnsupportedOption(option) {
27022750
var UNSUPPORTED_VERSION_OPTIONS = ['mocks', 'stubs', 'localVue'];
27032751

27042752
function validateOptions(options, component) {
2753+
if (
2754+
options.attachTo &&
2755+
!isHTMLElement(options.attachTo) &&
2756+
!isDomSelector(options.attachTo)
2757+
) {
2758+
throwError(
2759+
"options.attachTo should be a valid HTMLElement or CSS selector string"
2760+
);
2761+
}
2762+
if ('attachToDocument' in options) {
2763+
warn(
2764+
"options.attachToDocument is deprecated in favor of options.attachTo and will be removed in a future release"
2765+
);
2766+
}
27052767
if (options.parentComponent && !isPlainObject(options.parentComponent)) {
27062768
throwError(
27072769
"options.parentComponent should be a valid Vue component options object"

0 commit comments

Comments
 (0)