Closed poelstra closed 6 years ago
Have tested this on Win10 & Node 8.5.0 and works fine (all tests pass) but I feel I don't have enough expertise to asses the implications code-wise. @rikkertkoppes ?
Implications are only in tests, so rather limited. It looks like a solid improvement.
For the longer term however, I would opt to completely remove requirejs and use webpack or something instead
Thanks Rikkert. Fully agree with replacing with webpack or so some day. Not for now, though :)
@kmeesters Please wait with merging.
I'm adding a bit of functionality to support common (client + server) code. Also adding some tests for the stuff I already did, plus these new things.
@kmeesters Done, the tests should make it more clear what the intention of the changes are, too. Feel free to merge :)
Test (Firefox 49.0.0 (Windows 10 0.0.0): Executed 298 of 314 (skipped 16) SUCCESS (1.888 secs / 1.528 secs)) Node 8.5.0
It appeared (while working on #281 and on refactoring ranking out to common code) that something is fairly broken with the way the
factory()
function is used in our tests.The original idea was to replace RequireJS while running the tests, in order to allow passing e.g. mocks as dependencies for the modules. (Note that Angular itself provides a similar mechanism, too.)
The way
factory()
worked, though, is that it cached the first invocation, which means that any later invocations would get that module with a potentially different set of dependencies. These could be mocked dependencies, or could even be missing, because there was no check for such missing dependencies.Specifically, e.g. adding a dependency in e.g. ng-scores worked fine in 'real life', but fails mysteriously in tests. This appears to be caused because another tests already instantiated ng-scores, but failed to pass this new reference, and that instance was then cached.
This PR fixes this by making any call to factory return a new 'eco system' of modules (all of them are re-instantiated). However, because there is only one instance of angular, any angular modules defined as such will overwrite each other, so the calls to
factory()
must directly precede the actual tests. Hence the move tobeforeEach()
.As a side-effect, a missing dependency in ng-scores was found, which is now fixed.
Note that modules that use the
$fs
service are changed to have a dummy-module forservices/fs
, which is fine in that case, because the mocked$fs
doesn't useservices/fs
.