Repository navigation
Closed
Labels
Milestone
Description
I'm trying to run tests which (es6)import from the npm jasmine-marbles library. I've tried a few options but have had no luck. Importing other libraries like core-js/es6/object seem to have the exact same issue.
This library has:
- index.js - CommonJS, this is the main/default npm file
- bundles/jasmine-marbles.umd.js - UMD, including the AMD definition without a name
- src/*.{js,d.ts} - compiled source in CommonJS style
Ideally just putting @npm//jasmine-marbles into the ts_library(name=test_lib) would be all that's required. This would require converting/wrapping the CommonJS module before concatenating.
From what I've found:
- Putting
@npm//jasmine-marblesinto the test_libts_library(deps)does nothing. There is no reference to it inwindow.__karma__.files, it is not in the concatjs file. This causes aGET /jasmine-marbles.js404. - Putting
@npm//node_modules/jasmine-marbles:index.jsin thets_web_test_suite(deps)causes "ReferenceError: exports is not defined" because this CommonJS file is just placed into the concatjs file (it needs a wrapper to defineexportsandrequire). - Putting
@npm//node_modules/jasmine-marbles:bundles/jasmine-marbles.umd.jsin thets_web_test_suite(deps)and mapping "jasmine-marbles" to this usingrequire.config(...). This gets it into thewindow.__karma__.filesand the concatjs file, but the AMD (within UMD) does not contain the optional name param so it fails with the requirejs "Mismatched anonymous define() module" error.
It doesn't even get to the point where it is tries to load this file and using therequire.configalias etc.
Normally r.js or similar tools concatenating the files would insert the name param. Interesting to note that the ngrx/store umd file already has this first param, which I think is wrong? - Putting any of those
@npm/*into thets_web_test_suite(runtime_deps)fails with "labels in runtime_deps must be created by ts_library"
So, I think...
- npm deps like
@npm//jasmine-marblesnot being listed in__karma__.filesand concatjs seems like a bug? - CommonJS modules should be wrapped in a
define(name, ["require", "exports"], function(require, exports) { ... }). - AMD should have the name inserted into the
definecall. - UMD should do one of the above 2.
I'll try creating a test repo if this isn't clear...
Activity
Toxicable commentedon Mar 8, 2019
Just came accross this issue myself
made a reproduction here: https://github.com/Toxicable/bazel_web_test_bugs
Without this being fixed
karma_web_testis unusable for us since we cant use 3rd party libsToxicable commentedon May 31, 2019
Would be solved by this #761
Since it would be able to pre process npm deps from esm into umd
bryanjlee commentedon Sep 19, 2019
Feel free to file a new issue if you can still reproduce this.