basePath has trailing slash for root dir, but no trailing slash for non-root dir

Skip to first unread message

Rick Riemer

Dec 20, 2016, 2:53:13 PM12/20/16
to karma-users
I'm trying to build a Karma configuration that runs across different developer and build machines.

The issue I'm running into is that it seems that there is no consistent way to make the base path either always end with a trailing slash or always have no trailing slash. What I've found is that the base path is built using Node's path.resolve(...) method (in config.js). Node's documentation mentions that path.resolve() will have directories never end with a slash, unless the path indicates the root directory. In my environment some developers map their version control snapshot to a drive letter on Windows, making path.resolve() yield something like: X:/ (trailing slash), where for other locations it maps to something like C:/snapshot (no trailing slash) or /var/jenkins/project/workspace (no trailing slash).

No matter what I configure for config.basePath (with and without slashes), the path will always be normalized using the above logic. Thus, when I attempt to build my imports on the browser side, I sometimes have to map to http://localhost:9876/base/mypath, and sometimes to http://localhost:9876/basemypath (no intemediate slash). There seems to be no way to determine on the browser side whether I need to include the slash on the machine under test, and if I choose one mapping it will fail for the other case.

My gut feel is that Karma should either
  1. provide a consistent basePath slash behavior (i.e. always end with or without a slash for root dirs and non-root dirs), or 
  2. that Karma should provide a way in the browser environment to know whether base needs an extra slash or not, or 
  3. that the Karma http server shouldn't care, and just use path.join in source_files.js.
Did anyone encounter this behavior and have a solution with the current release? Or should I submit an issue on Github?


Rick Riemer
Reply all
Reply to author
0 new messages