testdouble.js: browser does not have `global` defined. Should this be `globalThis`?
Description
I want to load my tests. š
Issue

Environment
-
node -voutput: Chrome (no node) -
npm -v(oryarn --version) output: (doesnāt matter?) -
npm ls testdouble(oryarn list testdouble) version:testdouble@3.12.5
I donāt yet have time to do any digging, so Iām skiping the repro stuff below. Just wanted to report this for now in case something obvious is happening.
Iāve been able to get passed this error with:
<script>
window.global = window;
</script>
but is this a hack? is this build-environment-dependent? idk
Failing Test
- Fork the repo
- Add a failing test (probably to the `/regression/srcā directory)
- Submit a pull request for the failing test or link to your branch here
Example Repo
- Create a minimal repository that reproduces the issue
- Make sure that a fresh clone can run only
npm itand observe the issue - Link to that repo here
Runkit Notebook
- Create a Runkit notebook
- Invoke
var td = require('testdouble')at the top - Verify the behavior your issue is concerned with by clicking āRunā
- Link to the Runkit here
Code-fenced Examples
var td = require('testdouble')
// Your steps here.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (9 by maintainers)
@NullVoxPopuli I read the thread and agree that this is an issue. We are using the
browserfield currently so that people can use the library in a CJS compatible format when targeting browsers by duck-punching/replacing specific browser-incompatible files (as discussed in the spec). Browserify itself also looks at that key to successfully build the package without including sources thatāll explode on impact with a browser JS environment.So, because weāre already using the key for that purpose, we canāt also use it as a way to signal where the generated/gitignored bundle is to potential clients. As a result I donāt think thereās yet another to signal to tools āhey this is where the fully bundled JS distribution is with a global set on window, etcā.
Iām going to close this for now, but if at some point someone submits a PR that makes this better for everyone without breaking anything, Iād absolutely welcome it!
cc/ @jasonkarns in this year of 2020, is there yet an agreed up on correct way to indicate a browser distribution in package.json?
I imagine
require('testdouble/dist/testdouble')orimport 'testdouble/dist/testdouble'? Else you could just add its relative path vianode_modulesto yourtests/index.htmlfile in a script tag as you are doing with other assets