#Circular dependency on test from import files order (not import order on module)

2 messages · Page 1 of 1 (latest)

vapid grove
#

Hello folks!

I've spent the past days wondering on a very strange scenario that is occurring on my project and currently I'm able to identify the problem, but I found myself completely lost on the actual understanding of it. So, I have a simple test setup, shown on figure 1. This worked just fine, until I imported the ShippingModule on another module of my application, from this import onwards my test started returning the circular dependency error (figure 2). If I remove the import of ShippingModule from the other module, it works fine.

After analyzing with tools like medge and dependency-cruise, I wasn't able to find any circular dependency between the two modules, so I decided to change the importing of the ShippingModule to importing only the providers needed from it, but the error remained.

After this, by accident I changed the import order of my files in the test file, and for my surprise, the test executed successfully. So I rolled all my changes back (came back with the import of ShippingModule on the other module) and only changed the import order of files on my test file, and it worked. The change is shown on figure 3. What happens is that if I import ShippingFactory before ShippingModule, my test fails with circular dependency error (if ShippingModule is imported by other module). Indeed, ShippingFactory is part of ShippingModule, but on the setup of my testingModule (figure 1) I thought I was respecting this relation.

It's also worth to mention that this only happens on my test execution, my server bootstraps just fine and without any warnings.

Can anyone help me understand why the import order of my files would imply on this?

Thanks!

vapid grove
#

To bring more clarity, these are the modules involved. The problem only occurs when I import ShippingModule on CartModule.