44
55const 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' ) ;
2323const { engineCapture } = require ( './TestTools' ) ;
2424const MatterDev = stubBrowserFeatures ( require ( '../src/module/main' ) ) ;
2525const 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