提交 a291945f 编写于 作者: fxy060608's avatar fxy060608

fix(test): add polyfill

上级 676ab63b
...@@ -2,51 +2,64 @@ const path = require('path') ...@@ -2,51 +2,64 @@ const path = require('path')
const glob = require('glob') const glob = require('glob')
global.EVENTS = [ global.EVENTS = [
'touchstart', 'touchstart',
'touchmove', 'touchmove',
'touchcancel', 'touchcancel',
'touchend', 'touchend',
'click', //tap=>click 'click', //tap=>click
'longpress', 'longpress',
'longtap', 'longtap',
'transitionend', 'transitionend',
'animationstart', 'animationstart',
'animationiteration', 'animationiteration',
'animationend', 'animationend',
'touchforcechange' 'touchforcechange'
] ]
global.COMPONENTS = [] global.COMPONENTS = []
glob.sync('../../src/core/view/components/**/*/index.vue', { glob.sync('../../src/core/view/components/**/*/index.vue', {
nodir: true, nodir: true,
cwd: __dirname cwd: __dirname
}).forEach(file => { }).forEach(file => {
global.COMPONENTS.push(path.basename(path.dirname(file))) global.COMPONENTS.push(path.basename(path.dirname(file)))
}) })
glob.sync('../../src/platforms/' + process.env.UNI_PLATFORM + '/view/components/**/*/index.vue', { glob.sync('../../src/platforms/' + process.env.UNI_PLATFORM + '/view/components/**/*/index.vue', {
nodir: true, nodir: true,
cwd: __dirname cwd: __dirname
}).forEach(file => { }).forEach(file => {
global.COMPONENTS.push(path.basename(path.dirname(file))) global.COMPONENTS.push(path.basename(path.dirname(file)))
}) })
let lastTime = 0 let lastTime = 0
global.requestAnimationFrame = function(callback, element) { global.requestAnimationFrame = function(callback, element) {
const currTime = new Date().getTime() const currTime = new Date().getTime()
const timeToCall = Math.max(0, 16.7 - (currTime - lastTime)); const timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
const id = global.setTimeout(function() { const id = global.setTimeout(function() {
callback(currTime + timeToCall) callback(currTime + timeToCall)
}, timeToCall) }, timeToCall)
lastTime = currTime + timeToCall lastTime = currTime + timeToCall
return id return id
} }
global.cancelAnimationFrame = function(id) { global.cancelAnimationFrame = function(id) {
clearTimeout(id) clearTimeout(id)
} }
require('jsdom-global')(undefined, { require('jsdom-global')(undefined, {
pretendToBeVisual: true pretendToBeVisual: true
}) })
//fake
HTMLCanvasElement.prototype.getContext = function getContext() {
return {}
}
window.Date = Date
localStorage = {
getItem: function(key) {
return this[key]
},
setItem: function(key, value) {
this[key] = value
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册