0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-15 16:38:43 -05:00

fix named require in test

This commit is contained in:
liabru 2021-01-31 17:32:47 +00:00
parent aa1e4e7738
commit 92080ff49b
3 changed files with 37 additions and 2 deletions

31
package-lock.json generated
View file

@ -2821,6 +2821,12 @@
} }
} }
}, },
"get-caller-file": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz",
"integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==",
"dev": true
},
"jest": { "jest": {
"version": "25.5.4", "version": "25.5.4",
"resolved": "https://registry.npmjs.org/jest/-/jest-25.5.4.tgz", "resolved": "https://registry.npmjs.org/jest/-/jest-25.5.4.tgz",
@ -7618,6 +7624,25 @@
"integrity": "sha512-Gp3tETlN6uZftc1Jnv1sogQd8uB2Xh4c5bQ18qKR6KOMfUlsS8vztrC1vDrZS8eg4MuwE1AgZEcwxI41BSW6oQ==", "integrity": "sha512-Gp3tETlN6uZftc1Jnv1sogQd8uB2Xh4c5bQ18qKR6KOMfUlsS8vztrC1vDrZS8eg4MuwE1AgZEcwxI41BSW6oQ==",
"dev": true "dev": true
}, },
"mock-require": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/mock-require/-/mock-require-3.0.3.tgz",
"integrity": "sha512-lLzfLHcyc10MKQnNUCv7dMcoY/2Qxd6wJfbqCcVk3LDb8An4hF6ohk5AztrvgKhJCqj36uyzi/p5se+tvyD+Wg==",
"dev": true,
"requires": {
"get-caller-file": "^1.0.2",
"normalize-path": "^2.1.1"
}
},
"normalize-path": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz",
"integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=",
"dev": true,
"requires": {
"remove-trailing-separator": "^1.0.1"
}
},
"pathseg": { "pathseg": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/pathseg/-/pathseg-1.2.0.tgz", "resolved": "https://registry.npmjs.org/pathseg/-/pathseg-1.2.0.tgz",
@ -8080,6 +8105,12 @@
} }
} }
}, },
"remove-trailing-separator": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz",
"integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=",
"dev": true
},
"webpack": { "webpack": {
"version": "4.46.0", "version": "4.46.0",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-4.46.0.tgz", "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.46.0.tgz",

View file

@ -27,6 +27,7 @@
"json-stringify-pretty-compact": "^2.0.0", "json-stringify-pretty-compact": "^2.0.0",
"matter-tools": "^0.12.3", "matter-tools": "^0.12.3",
"matter-wrap": "^0.2.0", "matter-wrap": "^0.2.0",
"mock-require": "^3.0.3",
"pathseg": "^1.2.0", "pathseg": "^1.2.0",
"poly-decomp": "^0.3.0", "poly-decomp": "^0.3.0",
"puppeteer-core": "^5.5.0", "puppeteer-core": "^5.5.0",

View file

@ -4,7 +4,6 @@
const stubBrowserFeatures = M => { const stubBrowserFeatures = M => {
const noop = () => ({ collisionFilter: {}, mouse: {} }); 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.create = () => ({ options: {}, bounds: { min: { x: 0, y: 0 }, max: { x: 800, y: 600 }}});
M.Render.run = M.Render.lookAt = noop; M.Render.run = M.Render.lookAt = noop;
M.Runner.create = M.Runner.run = noop; M.Runner.create = M.Runner.run = noop;
@ -20,6 +19,7 @@ const reset = M => {
M.Body._nextCategory = 0x0001; M.Body._nextCategory = 0x0001;
}; };
const mock = require('mock-require');
const { engineCapture } = require('./TestTools'); const { engineCapture } = require('./TestTools');
const MatterDev = stubBrowserFeatures(require('../src/module/main')); const MatterDev = stubBrowserFeatures(require('../src/module/main'));
const MatterBuild = stubBrowserFeatures(require('../build/matter')); const MatterBuild = stubBrowserFeatures(require('../build/matter'));
@ -30,8 +30,10 @@ const runExample = options => {
const consoleOriginal = global.console; const consoleOriginal = global.console;
const logs = []; const logs = [];
global.document = global.window = { addEventListener: () => {} }; mock('matter-js', Matter);
global.Matter = Matter; global.Matter = Matter;
global.document = global.window = { addEventListener: () => {} };
global.console = { global.console = {
log: (...args) => { log: (...args) => {
logs.push(args.join(' ')); logs.push(args.join(' '));
@ -83,6 +85,7 @@ const runExample = options => {
global.window = undefined; global.window = undefined;
global.document = undefined; global.document = undefined;
global.Matter = undefined; global.Matter = undefined;
mock.stopAll();
return { return {
name: options.name, name: options.name,