Skip to content

Commit

Permalink
fix named require in test
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jan 31, 2021
1 parent aa1e4e7 commit 92080ff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"json-stringify-pretty-compact": "^2.0.0",
"matter-tools": "^0.12.3",
"matter-wrap": "^0.2.0",
"mock-require": "^3.0.3",
"pathseg": "^1.2.0",
"poly-decomp": "^0.3.0",
"puppeteer-core": "^5.5.0",
Expand Down
7 changes: 5 additions & 2 deletions test/ExampleWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

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 @@ -20,6 +19,7 @@ const reset = M => {
M.Body._nextCategory = 0x0001;
};

const mock = require('mock-require');
const { engineCapture } = require('./TestTools');
const MatterDev = stubBrowserFeatures(require('../src/module/main'));
const MatterBuild = stubBrowserFeatures(require('../build/matter'));
Expand All @@ -30,8 +30,10 @@ const runExample = options => {
const consoleOriginal = global.console;
const logs = [];

global.document = global.window = { addEventListener: () => {} };
mock('matter-js', Matter);
global.Matter = Matter;

global.document = global.window = { addEventListener: () => {} };
global.console = {
log: (...args) => {
logs.push(args.join(' '));
Expand Down Expand Up @@ -83,6 +85,7 @@ const runExample = options => {
global.window = undefined;
global.document = undefined;
global.Matter = undefined;
mock.stopAll();

return {
name: options.name,
Expand Down

0 comments on commit 92080ff

Please sign in to comment.