diff --git a/src/Tween.js b/src/Tween.js index 7899d51..d9a8336 100644 --- a/src/Tween.js +++ b/src/Tween.js @@ -8,10 +8,10 @@ */ // performance.now polyfill -( function ( root ) { +( function () { - if ( 'performance' in root === false ) { - root.performance = {}; + if ( 'performance' in window === false ) { + window.performance = {}; } // IE 8 @@ -19,16 +19,16 @@ return new Date().getTime(); } ); - if ( 'now' in root.performance === false ) { - var offset = root.performance.timing && root.performance.timing.navigationStart ? performance.timing.navigationStart - : Date.now(); + if ( 'now' in window.performance === false ) { + var offset = window.performance.timing && window.performance.timing.navigationStart ? window.performance.timing.navigationStart + : Date.now(); - root.performance.now = function () { + window.performance.now = function () { return Date.now() - offset; }; } -} )( this ); +} )(); var TWEEN = TWEEN || ( function () { diff --git a/test/unit/nodeunitheadless.js b/test/unit/nodeunitheadless.js index ee4a30f..acafc21 100644 --- a/test/unit/nodeunitheadless.js +++ b/test/unit/nodeunitheadless.js @@ -1,17 +1,12 @@ +// Make the tests work outside of browsers. The included polyfill will +// automatically include a perf.now() implementation +global.window = {}; + // We will unit test both the original library and the minified version var TWEEN_uncompressed = require('../../src/Tween.js'); var TWEEN_min = require('../../build/tween.min.js'); var getTests = require('./tests'); -// Make the tests work outside of browsers. -global.window = { - performance: { - now: function() { - return Date.now(); - } - } -}; - module.exports = { 'tween': getTests(TWEEN_uncompressed), 'tween_min': getTests(TWEEN_min)