karma-runner / karma

Spectacular Test Runner for JavaScript
http://karma-runner.github.io
MIT License
11.96k stars 1.71k forks source link

Inconsistent trailing slash for config.basePath #2525

Open Ricq opened 7 years ago

Ricq commented 7 years ago

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

Expected behaviour

Actual behaviour

Environment Details

Steps to reproduce the behaviour

  1. Setup a Karma run on Windows, hosted in a version control snapshot in some subdirectory (e.g. c:\dev)
  2. Run the exact same code in a root directory checkout (e.g.: x:)
Ricq commented 7 years ago

Note: I've submitted this issue after having submitted a Google Groups question and a Gitter question some weeks ago, both of which were not responded to.