Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP-1061 Import modules in the order they were specified in config #102

Merged
merged 1 commit into from
Oct 23, 2015
Merged

CP-1061 Import modules in the order they were specified in config #102

merged 1 commit into from
Oct 23, 2015

Conversation

ahelmberger
Copy link
Contributor

We would like to make the order, in which modules are loaded, deterministic. They should be imported in the order specified in karma.conf.js. E.g. given this configuration:

jspm: {
  serveFiles: ['**/*'],
  loadFiles: ['polyfills.js', '**/*.specs.js']
}

The current implementation would attempt to load all modules simultaneously. This can lead to different behavior between test runs, especially in the above case, where the first module adds some global polyfills other modules rely on.

With this changeset, all files specified in the loadFiles array will be imported sequentially.

From a perfomance perspective: we could not notice any difference between simultaneous/sequential import, tested in a project with about 400 tests and about 170 modules.

// Load everything specified in loadFiles in the specified order
var promiseChain = karma.config.jspm.expandedFiles.reduce(function (prev, next) {
return prev.then(function () {
return System.import(extractModuleName(next));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to use the System['import'] syntax from above for IE8 compatibility

@trentgrover-wf
Copy link
Collaborator

@evanweible-wf
Copy link
Contributor

+1 once Trent's comment has been addressed

@rmconsole2-wf
Copy link

@ahelmberger This pull request has merge conflicts, please resolve.

@ahelmberger
Copy link
Contributor Author

Thanks for the feedback, I rebased on the current master and used the IE8-compatible syntax.

@alexcastillo
Copy link
Contributor

+1

@trentgrover-wf
Copy link
Collaborator

+1
@maxwellpeterson-wf @jayudey-wf

// Promise comes from the systemjs polyfills
Promise.all(promises).then(function() {
// Load everything specified in loadFiles in the specified order
var promiseChain = karma.config.jspm.expandedFiles.reduce(function (prev, next) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're still aiming to support IE8, we can't use reduce here. @trentgrover-wf thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to maintain that backwards compatibility (though I'm not sure how many users still require it). could just include the polyfill:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Polyfill

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, I could convert the reduce functionality into a for loop. No need for including the polyfill just for one call. Please let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let's go with that. Including a polyfill could theoretically cause some tests to pass that shouldn't in older browsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took a little longer, I've updated the branch. It should work also in older browsers now.

@jayudey-wf jayudey-wf changed the title Import modules in the order they were specified in config CP-1061 Import modules in the order they were specified in config Oct 12, 2015
@maxwellpeterson-wf
Copy link
Contributor

+1

@jayudey-wf
Copy link
Contributor

QA Resource Approval: +10

  • Testing instruction (gathered from Max Peterson)
  • Dev +1's
  • Dev/QA +10 with detail of what was tested
    • verified that tasks were still working with this version of karma-jspm installed
  • Unit test created/updated
  • All unit tests pass

Merging into master.

jayudey-wf added a commit that referenced this pull request Oct 23, 2015
CP-1061 Import modules in the order they were specified in config
@jayudey-wf jayudey-wf merged commit 7abacf6 into computmaxer:master Oct 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants