testdouble.js
testdouble.js copied to clipboard
Switch global to globalThis
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 -voutput: - [ ]
npm -v(oryarn --version) output: - [ ]
npm ls testdouble(oryarn 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
};
Seems good
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.