Skip to content

Commit

Permalink
add window global, stub require and handle bad values in test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Mar 9, 2020
1 parent 3fd674d commit 497ac80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion test/ExampleWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -76,6 +77,7 @@ const runExample = options => {
}

global.console = consoleOriginal;
global.window = undefined;
global.document = undefined;
global.decomp = undefined;
global.Matter = undefined;
Expand Down
4 changes: 3 additions & 1 deletion test/TestTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

Expand Down

0 comments on commit 497ac80

Please sign in to comment.