@@ -90,9 +90,19 @@ function module(ignore, func) {
9090 }
9191 }
9292
93- function run_all ( reporter ) {
94- for ( var i = 0 ; i < allTests . length ; ++ i ) {
95- var test = allTests [ i ] ;
93+ function run_tests ( reporter , filter = undefined ) {
94+ let testsToRun = allTests ;
95+ if ( filter ) {
96+ const filterRegex = new RegExp ( filter ) ;
97+ testsToRun = allTests . filter ( ( t ) => filterRegex . test ( t . name ) ) ;
98+ if ( ! testsToRun . length ) {
99+ throw new Error ( `no tests match the given filter: ${ filter } ` )
100+ }
101+ console . log ( `running ${ testsToRun . length } of ${ allTests . length } tests that match filter: ${ filter } ` )
102+ } else {
103+ console . log ( `running ${ allTests . length } test` )
104+ }
105+ for ( const test of testsToRun ) {
96106 reporter ( {
97107 type : 'test-start' ,
98108 name : test . name
@@ -552,9 +562,7 @@ function module(ignore, func) {
552562 }
553563 }
554564
555- ( function ( ) {
556- var g = 'undefined' === typeof window ? globalThis : window ;
557-
565+ ( function ( ) {
558566 // synonyms
559567 assert . equals = assert . equal ;
560568 assert . notEquals = assert . notEqual ;
@@ -563,45 +571,47 @@ function module(ignore, func) {
563571 assert [ 'undefined' ] = assert . equal . bind ( null , undefined ) ;
564572 assert . notUndefined = assert . notEqual . bind ( null , undefined ) ;
565573
566- g . registerSuperFixture = registerSuperFixture ;
567- g . test = test ;
568- g . run_all = run_all ;
569- g . fixture = fixture ;
570- // g .repr = IMVU.repr;
571- g . AssertionError = AssertionError ;
572- g . assert = assert ;
573- g . test = test ;
574- g . TEST_MAX_OUTPUT_SIZE = 1024 ;
575-
576- g . setTimeout = function ( fn , time ) {
574+ globalThis . registerSuperFixture = registerSuperFixture ;
575+ globalThis . test = test ;
576+ globalThis . run_tests = run_tests ;
577+ globalThis . fixture = fixture ;
578+ // globalThis .repr = IMVU.repr;
579+ globalThis . AssertionError = AssertionError ;
580+ globalThis . assert = assert ;
581+ globalThis . test = test ;
582+ globalThis . TEST_MAX_OUTPUT_SIZE = 1024 ;
583+
584+ globalThis . setTimeout = function ( fn , time ) {
577585 if ( time === 1 || time === 0 ) {
578586 fn ( ) ;
579587 return 0 ;
580588 }
581589 throw new AssertionError ( "Don't call setTimeout in tests. Use fakes." ) ;
582590 } ;
583591
584- g . setInterval = function ( ) {
592+ globalThis . setInterval = function ( ) {
585593 throw new AssertionError ( "Don't call setInterval in tests. Use fakes." ) ;
586594 } ;
587595
588596 Math . random = function ( ) {
589597 throw new AssertionError ( "Don't call Math.random in tests. Use fakes." ) ;
590598 } ;
591599
592- g . requestAnimationFrame = function ( ) {
600+ globalThis . requestAnimationFrame = function ( ) {
593601 throw new AssertionError ( "Don't call requestAnimationFrame in tests. Use fakes." ) ;
594602 } ;
595- } ) ( ) ;
603+ } ) ( ) ;
596604
597605// Emscripten runner starts all tests from this function.
598606// IMVU runner uses a separate runner & reporting mechanism.
599607function run_all_tests ( ) {
600608 function report_to_stdout ( msg ) {
601- if ( msg . type === "test-complete" )
602- console . log ( msg . name + ": " + msg . verdict ) ;
609+ if ( msg . type === "test-complete" ) {
610+ console . log ( `${ msg . name } : ${ msg . verdict } ` ) ;
611+ }
603612 }
604- run_all ( report_to_stdout ) ;
613+ const filter = process . env [ 'EMBIND_TESTS' ] ;
614+ run_tests ( report_to_stdout , filter ) ;
605615}
606616
607617// Signal the embind test suite that it is being run from the Emscripten python test runner and not the
0 commit comments