Skip to content

Commit 92080ff

Browse files
committed
fix named require in test
1 parent aa1e4e7 commit 92080ff

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

package-lock.json

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"json-stringify-pretty-compact": "^2.0.0",
2828
"matter-tools": "^0.12.3",
2929
"matter-wrap": "^0.2.0",
30+
"mock-require": "^3.0.3",
3031
"pathseg": "^1.2.0",
3132
"poly-decomp": "^0.3.0",
3233
"puppeteer-core": "^5.5.0",

test/ExampleWorker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
const stubBrowserFeatures = M => {
66
const noop = () => ({ collisionFilter: {}, mouse: {} });
7-
M.Common._requireGlobal = name => global[name];
87
M.Render.create = () => ({ options: {}, bounds: { min: { x: 0, y: 0 }, max: { x: 800, y: 600 }}});
98
M.Render.run = M.Render.lookAt = noop;
109
M.Runner.create = M.Runner.run = noop;
@@ -20,6 +19,7 @@ const reset = M => {
2019
M.Body._nextCategory = 0x0001;
2120
};
2221

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

33-
global.document = global.window = { addEventListener: () => {} };
33+
mock('matter-js', Matter);
3434
global.Matter = Matter;
35+
36+
global.document = global.window = { addEventListener: () => {} };
3537
global.console = {
3638
log: (...args) => {
3739
logs.push(args.join(' '));
@@ -83,6 +85,7 @@ const runExample = options => {
8385
global.window = undefined;
8486
global.document = undefined;
8587
global.Matter = undefined;
88+
mock.stopAll();
8689

8790
return {
8891
name: options.name,

0 commit comments

Comments
 (0)