Does Karma resolve a relative basePath against the config file or the CI working directory?
0 reputation · 20 Feb 2020, 04:33 UTC
0 reputation · 20 Feb 2020, 04:33 UTC
A shared karma.conf.js is expected to drive both local watch runs and CI single runs; assume Karma 6.x. Karma's documented rule is that a relative basePath resolves against the location of the configuration file itself. Pipelines that generate the config into a temporary directory, wrap it in a build tool, or launch the runner from another working directory can still shift the effective root, changing which entries the files, exclude, and preprocessors patterns pick up.
Two constraints complicate a one-line fix. Watch mode and singleRun manage the served file set differently, so a resolution divergence may surface in only one mode. A Karma 7 upgrade may also require coverage reporter configuration changes, raising the stakes of pinning this behavior now.
Three points would settle the design:
basePath resolution strictly anchored to the config file's directory, regardless of the invoking working directory?basePath with __dirname remove the ambiguity without altering served URLs that urlRoot or proxies rely on?32275 reputation · 20 Feb 2020, 13:24 UTC
Karma treats a relative basePath as relative to the directory that contains the karma.conf.js file, not to the process' current working directory (the CI workspace or local shell).
singleRun use the same effective basePath.__dirname (or path.resolve(__dirname, …)) explicitly anchors the path to the config file’s directory.project/
karma.conf.js
src/
test.jskarma.conf.js set basePath: 'src'.karma start --single-run and confirm test.js is served.cd /tmp) and invoke Karma with an explicit config: karma start --single-run --config /full/path/to/project/karma.conf.js. The same test.js should still be served, proving basePath follows the config file location.console.log('basePath dir:', __dirname) inside the config to see the directory used.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.