testdouble.js: browser does not have `global` defined. Should this be `globalThis`?

Description

I want to load my tests. 😃

Issue

image

Environment

  • node -v output: Chrome (no node)
  • npm -v (or yarn --version) output: (doesn’t matter?)
  • npm ls testdouble (or yarn 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 it and 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)

Most upvoted comments

@NullVoxPopuli I read the thread and agree that this is an issue. We are using the browser field 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') or import 'testdouble/dist/testdouble'? Else you could just add its relative path via node_modules to your tests/index.html file in a script tag as you are doing with other assets