karma-runner / karma-runner/karma

Inconsistent trailing slash for config.basePath

Open
#2,525 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

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

- provide a consistent basePath slash behavior (i.e. always end with or without a slash for root dirs and non-root dirs), or
- that Karma should provide a way in the browser environment to know whether base needs an extra slash or not, or
- that the Karma http server shouldn't care, and just use path.join in source_files.js.

### Expected behaviour
* basePath consistently ends with either a trailing slash, or without, or correctly joins paths regardless of the slash, allowing the reuse of a Karma configuration across different developer machines with different checkout drives.

### Actual behaviour
* On Windows, the basePath resolves to a path without a slash, except for the root folder of a drive. It is then not possible to create a dependency path in the client that consistently works across both variations.

### Environment Details
* Windows 10
- Karma version (output of `karma --version`): 0.13.22
- Relevant part of your `karma.config.js` file: `config.set({basePath: '../../..',`

### 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:\)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.