From 497ac802fc48669b1cd2b370372efbea4212a18d Mon Sep 17 00:00:00 2001 From: liabru Date: Mon, 9 Mar 2020 21:05:05 +0000 Subject: [PATCH] add window global, stub require and handle bad values in test tools --- test/ExampleWorker.js | 4 +++- test/TestTools.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/ExampleWorker.js b/test/ExampleWorker.js index e30d6f63..093d7eef 100644 --- a/test/ExampleWorker.js +++ b/test/ExampleWorker.js @@ -4,6 +4,7 @@ const stubBrowserFeatures = M => { const noop = () => ({ collisionFilter: {}, mouse: {} }); + M.Common._requireGlobal = name => global[name]; M.Render.create = () => ({ options: {}, bounds: { min: { x: 0, y: 0 }, max: { x: 800, y: 600 }}}); M.Render.run = M.Render.lookAt = noop; M.Runner.create = M.Runner.run = noop; @@ -30,7 +31,7 @@ const runExample = options => { const consoleOriginal = global.console; global.console = { log: () => {} }; - global.document = {}; + global.document = global.window = { addEventListener: () => {} }; global.decomp = decomp; global.Matter = Matter; @@ -76,6 +77,7 @@ const runExample = options => { } global.console = consoleOriginal; + global.window = undefined; global.document = undefined; global.decomp = undefined; global.Matter = undefined; diff --git a/test/TestTools.js b/test/TestTools.js index 3a6a302f..5688bb34 100644 --- a/test/TestTools.js +++ b/test/TestTools.js @@ -118,7 +118,9 @@ const worldCaptureIntrinsicBase = (obj, depth=0) => { }; const similarity = (a, b) => { - const distance = Math.sqrt(a.reduce((sum, _val, i) => sum + Math.pow(a[i] - b[i], 2), 0)); + const distance = Math.sqrt(a.reduce( + (sum, _val, i) => sum + Math.pow((a[i] || 0) - (b[i] || 0), 2), 0) + ); return 1 / (1 + (distance / a.length)); };