Skip to content

Resolve "Add some way to mock and spy on default ES modules"

Mike Greiling requested to merge 30998-add-babel-rewire-plugin into master

This MR adds babel-plugin-rewire to our babel config and defines a spyOnDependencies method to allow one to temporarily inject a jasmine spy in the place of an import within in another module.

Problems:

  • although this new method has worked in the test cases of stop_jobs_modal_spec.js and delete_milestone_modal_spec.js, there appear to be additional side effects. merely adding this plugin seems to be causing several tests which were passing before to no longer pass.
  • the sourcemaps for our test files appears to be broken with this plugin. stack traces point to locations that are several lines away from where an exception has taken place.

Remaining work:

  • research the cause of the above problems and determine if they are show-stoppers
  • finish refactoring cases where we're abusing import * from 'foo'; to inject jasmine spies into utility modules imported elsewhere.

Closes #30998 (closed)

Merge request reports