Yes, I'll try my best to explain it.
TL;DR: Being able to specify urlRoot allows for pact testing Angular service requests that can't otherwise be tested when the application's base URL is set by Tomcat.
I'm currently using the karma-pact plugin to run pact tests through karma. The way the application is set up is like this:
angular-cli is used to compile the UI.
- Tomcat is used to serve the contents of the dist directory.
- Tomcat sets the application's base URL from
/ to /someBaseUrl.
In the Angular services, I have to make sure that all request URLs don't start with /:
// When the application is run through Tomcat, this URL becomes `/someBaseUrl/request/url` <--- correct
this.http.get<any>("request/url")
// If the URL is incorrectly prepended with `/`, this URL becomes `/request/url` <--- incorrect
this.http.get<any>("/request/url")
When testing locally using ng serve, using either URL works since both get proxied to /someBaseUrl/request/url. This isn't the case when running the application through Tomcat since there's no proxy involved.
A pact test is able to catch an error like this, but with the way the application is architected, it can't. The reasons why this doesn't work are:
- Pact test requests are made from the karma server
localhost:9876
- Regardless of if the Angular service prepends the request URL with
/, the result is the same:
localhost:9876 + request/url = localhost:9876/request/url
localhost:9876 + /request/url = localhost:9876/request/url <--- pact test won't detect that the request was prepended with `/`
To the pact test, everything looks fine, but when the application is deployed and tested, any requests prepended with / will result in 404s.
Being able to specify a base for the karma server would allow the pact tests to properly detect the difference:
localhost:9876/someBaseUrl + request/url = localhost:9876/someBaseUrl/request/url
localhost:9876/someBaseUrl + /request/url = localhost:9876/request/url <--- pact test will detect this as a failure