testdouble.js icon indicating copy to clipboard operation
testdouble.js copied to clipboard

Switch global to globalThis

Open NullVoxPopuli opened this issue 4 years ago • 2 comments
trafficstars

Description

This is a bit of a resurrection of: https://github.com/testdouble/testdouble.js/issues/438, in that browsers are not able to use testdouble.js without a global "polyfill", like the following:

<script>
    // testdouble doesn't natively support the browser as it assumes
    // that a `global` identifier will be available, but that is not the case for browsers
    window.global = globalThis;
</script>

Just checking the compatibility table over here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

it looks like globalThis is supported everywhere that matters?

Is it possible to drop usage of global?

This is probably also related to: https://github.com/testdouble/testdouble.js/issues/434

Environment

  • [ ] node -v output:
  • [ ] npm -v (or yarn --version) output:
  • [ ] npm ls testdouble (or yarn list testdouble) version:

Chrome and Firefox v90+

importing testdouble causes an error, because of this code:

const DEFAULTS = {
  ignoreWarnings: false,
  promiseConstructor: global.Promise,
  suppressErrors: false
};

NullVoxPopuli avatar Oct 03 '21 17:10 NullVoxPopuli

Seems good

searls avatar Oct 04 '21 12:10 searls

We might want to drop support for Node 10 at the same time since MDN says globalThis was added in v12. If I'm tracking my Node changes correctly, v10 went EOL on 2021-04-30.

rosston avatar Oct 04 '21 13:10 rosston