Skip to content

Commit 0bf0ceb

Browse files
authored
test: use build/dist for e2e testing (#421)
* test: use build/dist for e2e testing to prevent errors due to wrong build configs * test: use wrong build conf to test the test * test: exclude dist for babel-loader in test build * chore: optimize more for ie9 prefer not to use language features which needs to be transpiled for ie9. Eg for..of to forEach and no spreads * fix: continue
1 parent 04b2692 commit 0bf0ceb

File tree

10 files changed

+114
-96
lines changed

10 files changed

+114
-96
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
- attach-project
7777
- run:
7878
name: E2E SSR Tests
79-
command: yarn test:e2e-ssr
79+
command: yarn build && yarn test:e2e-ssr
8080
- persist_to_workspace:
8181
root: ~/project
8282
paths:

scripts/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function rollupConfig({
4040
delimiters: ['', ''],
4141
values: {
4242
// replaceConfig needs to have some values
43-
'const polyfill = process.env.NODE_ENV === \'test\'': 'const polyfill = false',
43+
'const polyfill = process.env.NODE_ENV === \'test\'': 'const polyfill = true',
4444
}
4545
}
4646

src/client/load.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ export function addCallback (query, callback) {
3030
export function addCallbacks ({ tagIDKeyName }, type, tags, autoAddListeners) {
3131
let hasAsyncCallback = false
3232

33-
for (const tag of tags) {
33+
tags.forEach((tag) => {
3434
if (!tag[tagIDKeyName] || !tag.callback) {
35-
continue
35+
return
3636
}
3737

3838
hasAsyncCallback = true
3939
addCallback(`${type}[data-${tagIDKeyName}="${tag[tagIDKeyName]}"]`, tag.callback)
40-
}
40+
})
4141

4242
if (!autoAddListeners || !hasAsyncCallback) {
4343
return hasAsyncCallback
@@ -60,7 +60,7 @@ export function addListeners () {
6060
}
6161

6262
export function applyCallbacks (matchElement) {
63-
for (const [query, callback] of callbacks) {
63+
callbacks.forEach(([query, callback]) => {
6464
const selector = `${query}[onload="this.__vm_l=1"]`
6565

6666
let elements = []
@@ -72,13 +72,13 @@ export function applyCallbacks (matchElement) {
7272
elements = [matchElement]
7373
}
7474

75-
for (const element of elements) {
75+
elements.forEach((element) => {
7676
/* __vm_cb: whether the load callback has been called
7777
* __vm_l: set by onload attribute, whether the element was loaded
7878
* __vm_ev: whether the event listener was added or not
7979
*/
8080
if (element.__vm_cb) {
81-
continue
81+
return
8282
}
8383

8484
const onload = () => {
@@ -105,14 +105,14 @@ export function applyCallbacks (matchElement) {
105105
*/
106106
if (element.__vm_l) {
107107
onload()
108-
continue
108+
return
109109
}
110110

111111
if (!element.__vm_ev) {
112112
element.__vm_ev = true
113113

114114
element.addEventListener('load', onload)
115115
}
116-
}
117-
}
116+
})
117+
})
118118
}

src/client/updateClientMetaInfo.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export default function updateClientMetaInfo (appId, options = {}, newInfo) {
2525

2626
// add load callbacks if the
2727
let addLoadListeners = false
28-
for (const type of tagsSupportingOnload) {
28+
tagsSupportingOnload.forEach((type) => {
2929
if (newInfo[type] && addCallbacks(options, type, newInfo[type])) {
3030
addLoadListeners = true
3131
}
32-
}
32+
})
3333

3434
if (addLoadListeners) {
3535
addListeners()

src/client/updaters/tag.js

+65-68
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import { queryElements, getElementsKey } from '../../utils/elements.js'
1313
export default function updateTag (appId, options = {}, type, tags, head, body) {
1414
const { attribute, tagIDKeyName } = options
1515

16-
const dataAttributes = [tagIDKeyName, ...commonDataAttributes]
16+
const dataAttributes = commonDataAttributes.slice()
17+
dataAttributes.push(tagIDKeyName)
18+
1719
const newElements = []
1820

1921
const queryOptions = { appId, attribute, type, tagIDKeyName }
@@ -36,103 +38,98 @@ export default function updateTag (appId, options = {}, type, tags, head, body)
3638
})
3739
}
3840

39-
if (tags.length) {
40-
for (const tag of tags) {
41-
if (tag.skip) {
42-
continue
43-
}
44-
45-
const newElement = document.createElement(type)
46-
newElement.setAttribute(attribute, appId)
41+
tags.forEach((tag) => {
42+
if (tag.skip) {
43+
return
44+
}
4745

48-
for (const attr in tag) {
49-
/* istanbul ignore next */
50-
if (!tag.hasOwnProperty(attr)) {
51-
continue
52-
}
46+
const newElement = document.createElement(type)
47+
newElement.setAttribute(attribute, appId)
5348

54-
if (attr === 'innerHTML') {
55-
newElement.innerHTML = tag.innerHTML
56-
continue
57-
}
49+
for (const attr in tag) {
50+
/* istanbul ignore next */
51+
if (!tag.hasOwnProperty(attr)) {
52+
continue
53+
}
5854

59-
if (attr === 'json') {
60-
newElement.innerHTML = JSON.stringify(tag.json)
61-
continue
62-
}
55+
if (attr === 'innerHTML') {
56+
newElement.innerHTML = tag.innerHTML
57+
continue
58+
}
6359

64-
if (attr === 'cssText') {
65-
if (newElement.styleSheet) {
66-
/* istanbul ignore next */
67-
newElement.styleSheet.cssText = tag.cssText
68-
} else {
69-
newElement.appendChild(document.createTextNode(tag.cssText))
70-
}
71-
continue
72-
}
60+
if (attr === 'json') {
61+
newElement.innerHTML = JSON.stringify(tag.json)
62+
continue
63+
}
7364

74-
if (attr === 'callback') {
75-
newElement.onload = () => tag[attr](newElement)
76-
continue
65+
if (attr === 'cssText') {
66+
if (newElement.styleSheet) {
67+
/* istanbul ignore next */
68+
newElement.styleSheet.cssText = tag.cssText
69+
} else {
70+
newElement.appendChild(document.createTextNode(tag.cssText))
7771
}
72+
continue
73+
}
7874

79-
const _attr = includes(dataAttributes, attr)
80-
? `data-${attr}`
81-
: attr
75+
if (attr === 'callback') {
76+
newElement.onload = () => tag[attr](newElement)
77+
continue
78+
}
8279

83-
const isBooleanAttribute = includes(booleanHtmlAttributes, attr)
84-
if (isBooleanAttribute && !tag[attr]) {
85-
continue
86-
}
80+
const _attr = includes(dataAttributes, attr)
81+
? `data-${attr}`
82+
: attr
8783

88-
const value = isBooleanAttribute ? '' : tag[attr]
89-
newElement.setAttribute(_attr, value)
84+
const isBooleanAttribute = includes(booleanHtmlAttributes, attr)
85+
if (isBooleanAttribute && !tag[attr]) {
86+
continue
9087
}
9188

92-
const oldElements = currentElements[getElementsKey(tag)]
89+
const value = isBooleanAttribute ? '' : tag[attr]
90+
newElement.setAttribute(_attr, value)
91+
}
9392

94-
// Remove a duplicate tag from domTagstoRemove, so it isn't cleared.
95-
let indexToDelete
96-
const hasEqualElement = oldElements.some((existingTag, index) => {
97-
indexToDelete = index
98-
return newElement.isEqualNode(existingTag)
99-
})
93+
const oldElements = currentElements[getElementsKey(tag)]
10094

101-
if (hasEqualElement && (indexToDelete || indexToDelete === 0)) {
102-
oldElements.splice(indexToDelete, 1)
103-
} else {
104-
newElements.push(newElement)
105-
}
95+
// Remove a duplicate tag from domTagstoRemove, so it isn't cleared.
96+
let indexToDelete
97+
const hasEqualElement = oldElements.some((existingTag, index) => {
98+
indexToDelete = index
99+
return newElement.isEqualNode(existingTag)
100+
})
101+
102+
if (hasEqualElement && (indexToDelete || indexToDelete === 0)) {
103+
oldElements.splice(indexToDelete, 1)
104+
} else {
105+
newElements.push(newElement)
106106
}
107-
}
107+
})
108108

109-
let oldElements = []
110-
for (const current of Object.values(currentElements)) {
111-
oldElements = [
112-
...oldElements,
113-
...current
114-
]
109+
const oldElements = []
110+
for (const type in currentElements) {
111+
Array.prototype.push.apply(oldElements, currentElements[type])
115112
}
116113

117114
// remove old elements
118-
for (const element of oldElements) {
115+
oldElements.forEach((element) => {
119116
element.parentNode.removeChild(element)
120-
}
117+
})
121118

122119
// insert new elements
123-
for (const element of newElements) {
120+
newElements.forEach((element) => {
124121
if (element.hasAttribute('data-body')) {
125122
body.appendChild(element)
126-
continue
123+
return
127124
}
128125

129126
if (element.hasAttribute('data-pbody')) {
130127
body.insertBefore(element, body.firstChild)
131-
continue
128+
return
132129
}
133130

134131
head.appendChild(element)
135-
}
132+
})
136133

137134
return {
138135
oldTags: oldElements,

src/shared/escaping.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export const clientSequences = [
1919
]
2020

2121
// sanitizes potentially dangerous characters
22-
export function escape (info, options, escapeOptions) {
22+
export function escape (info, options, escapeOptions, escapeKeys) {
2323
const { tagIDKeyName } = options
24-
const { doEscape = v => v, escapeKeys } = escapeOptions
24+
const { doEscape = v => v } = escapeOptions
2525
const escaped = {}
2626

2727
for (const key in info) {
@@ -56,13 +56,13 @@ export function escape (info, options, escapeOptions) {
5656
} else if (isArray(value)) {
5757
escaped[key] = value.map((v) => {
5858
if (isPureObject(v)) {
59-
return escape(v, options, { ...escapeOptions, escapeKeys: true })
59+
return escape(v, options, escapeOptions, true)
6060
}
6161

6262
return doEscape(v)
6363
})
6464
} else if (isPureObject(value)) {
65-
escaped[key] = escape(value, options, { ...escapeOptions, escapeKeys: true })
65+
escaped[key] = escape(value, options, escapeOptions, true)
6666
} else {
6767
escaped[key] = value
6868
}

src/shared/log.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const _global = hasGlobalWindow ? window : global
44

55
const console = (_global.console = _global.console || {})
66

7-
export function warn (...args) {
7+
export function warn (str) {
88
/* istanbul ignore next */
99
if (!console || !console.warn) {
1010
return
1111
}
1212

13-
console.warn(...args)
13+
console.warn(str)
1414
}
1515

1616
export const showWarningNotSupported = () => warn('This vue app/component has no vue-meta configuration')

test/fixtures/basic/client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Vue from 'vue'
2-
import VueMeta from '../../../src/browser'
2+
import VueMeta from 'vue-meta'
33
import App from './App.vue'
44
import createRouter from './router'
55

test/fixtures/basic/server.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import Vue from 'vue'
2-
import VueMeta from '../../../src'
2+
import { _import, getVueMetaPath } from '../../utils/build'
33
import App from './App.vue'
44
import createRouter from './router'
55

6-
Vue.use(VueMeta)
6+
export default async function createServerApp () {
7+
const VueMeta = await _import(getVueMetaPath())
78

8-
App.router = createRouter()
9+
Vue.use(VueMeta)
910

10-
export default new Vue(App)
11+
App.router = createRouter()
12+
13+
return new Vue(App)
14+
}

0 commit comments

Comments
 (0)