A better solution, which does allow one to upgrade to a more recent version of mapbox-gl, is defined here: https://stackoverflow.com/a/68468204/13702327
This allowed me to upgrade from [email protected] (where the above problem did not occur) to [email protected] (where it did). All without changing the version of node, which is at 18.x.
Note that in your test source structure you must define this before reaching code which loads any import of 'mapbox-gl'. If your mapbox-dependent code is structured in libraries, and your tests depend on those libraries, this will be when the library's index.ts is loaded - even in a test which does not specifically depend upon a mapbox-depending entity with that library.
So, per the linked answer, best to define it in a test-setup file.