SystemJS - order of dependency loading

243 views
Skip to first unread message

payto...@gmail.com

unread,
Apr 21, 2016, 10:45:46 AM4/21/16
to SystemJS
I'm struggling with something that I think should be easy - and I'm probably doing something dumb.

I'm setting up a jasmine test suite in the browser, and Jasmine requires you load scripts in a specific order, and that those scripts provide global variables. Yuck, but what are you gonna do.

I've got this working to an extent but it's ugly:

System.import('jasmine-core').
then(function() {
return System.import('jasmine-core/lib/jasmine-core/jasmine-html.js');
}).
then(function() {
return System.import('jasmine-core/lib/jasmine-core/boot')
}).
then(function(a, b) {
// Do the stuff that runs tests

I feel like I should be able to do this:

System.import('jasmine-core').
then(System.import('jasmine-core/lib/jasmine-core/jasmine-html.js')).
then(System.import("jasmine-core/lib/jasmine-core/boot')
}).
then(function(a, b) {

But when I do that the globals are lost and jasmine-html fails. I also suspect there's an even simpler way to do this, perhaps via an array send to the promise, or through the config.js file and maps but the docs don't make it clear. At least to me - all my attempts have failed.

I suspect the experts here will know off the top of their head. Thanks.


Benjamin Strauß

unread,
Apr 23, 2016, 3:40:43 PM4/23/16
to SystemJS, payto...@gmail.com
This is a general problem with promises and old ES5 syntax. It feels a bit verbose. In your second example you call all imports at the same time which results in the mentioned error. The only thing to get around this is to use ES2015 syntax and transpile down to ES5.

System.import('jasmine-core').
    then(() => System.import('jasmine-core/lib/jasmine-core/jasmine-html.js')).
    then(() => System.import('jasmine-core/lib/jasmine-core/boot')).
    then(() => {
});



Reply all
Reply to author
Forward
0 new messages