Some portions of the Greasemonkey code base are wrapped in immediately invoked functions (IIFs) in order to privately scope function definitions and variables. For example the script registry defines many variables that are scoped only to the IIF. For the rest of this we'll stick with the registry as our example.
The goal of unit tests is to control as much external state as possible so that we're only testing singular items. Unfortunately, with the scoping problems this isn't the case in the current registry tests. In order to check if a script exists all tests are relying on an external function `scriptsToRunAt`. Ideally the test would just check the object directly. Further, both tests in the file are dependent on `_saveUserScript`. Again, it would be ideal if the script was injected into the `userScripts` object (database could be mocked or preloaded with good data, or moved to a separate function that can be `sinon.stub` and therefore assumed good for the purpose of tests not related to that function).
One solution is to do the same thing that occured with `_saveUserScript` and `_loadUserScripts`, and that's export the object. And by extension anything that is required for testing would be exported (anywhere in the file). If it's not needed for testing then it, rightly, doesn't need to be exported. Since Greasemonkey is a closed system I feel that doing the above is a valid solution. Closed system meaning, Greasemonkey isn't a 'library' wherein some external provider that calls into it and directly accesses or creates Greasemonkey objects, unlike an AngularJS module or some-such.
Alternatively, exposing these references could be done conditionally, only inside the development environment. This method is more complex than the previous one. And it would rely on modifying the `package.sh` script to account for the conditionals, or move to using something like grunt.