diff --git a/tests/unit/setup.js b/tests/unit/setup.js index d01ca2fd36b743215dcdb60fcfaaba22334eec0e..e88dd090742b520d921b2c72a13ea2e9f3092531 100644 --- a/tests/unit/setup.js +++ b/tests/unit/setup.js @@ -2,51 +2,64 @@ const path = require('path') const glob = require('glob') global.EVENTS = [ - 'touchstart', - 'touchmove', - 'touchcancel', - 'touchend', - 'click', //tap=>click - 'longpress', - 'longtap', - 'transitionend', - 'animationstart', - 'animationiteration', - 'animationend', - 'touchforcechange' + 'touchstart', + 'touchmove', + 'touchcancel', + 'touchend', + 'click', //tap=>click + 'longpress', + 'longtap', + 'transitionend', + 'animationstart', + 'animationiteration', + 'animationend', + 'touchforcechange' ] global.COMPONENTS = [] glob.sync('../../src/core/view/components/**/*/index.vue', { - nodir: true, - cwd: __dirname + nodir: true, + cwd: __dirname }).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', { - nodir: true, - cwd: __dirname + nodir: true, + cwd: __dirname }).forEach(file => { - global.COMPONENTS.push(path.basename(path.dirname(file))) + global.COMPONENTS.push(path.basename(path.dirname(file))) }) let lastTime = 0 global.requestAnimationFrame = function(callback, element) { - const currTime = new Date().getTime() - const timeToCall = Math.max(0, 16.7 - (currTime - lastTime)); - const id = global.setTimeout(function() { - callback(currTime + timeToCall) - }, timeToCall) - lastTime = currTime + timeToCall - return id + const currTime = new Date().getTime() + const timeToCall = Math.max(0, 16.7 - (currTime - lastTime)); + const id = global.setTimeout(function() { + callback(currTime + timeToCall) + }, timeToCall) + lastTime = currTime + timeToCall + return id } global.cancelAnimationFrame = function(id) { - clearTimeout(id) + clearTimeout(id) } 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 + } +}