Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basePath does not work properly in some circumstances #1636

Open
ghost opened this issue Oct 17, 2015 · 1 comment
Open

basePath does not work properly in some circumstances #1636

ghost opened this issue Oct 17, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 17, 2015

I am running karma using gulp. This is a gulp task module I require:

var karma = require("karma");

module.exports = function (done) {
    new karma.Server({
        configFile: '../../../karma.conf.js',
        singleRun: true
    }, function (exitCode) {
        done();
    }).start();
};

The module file is on path root/tasks/test/karma.js. I have a root/karma.conf.js as you can see... It contains this:

module.exports = function (config) {
    config.set({
        basePath: __dirname,
        frameworks: ['jasmine'],
        files: [
            {pattern: 'src/nodelist.js', included: true},
            {pattern: 'tests/*.js', included: true}
        ],
        exclude: [],
        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Firefox'],
        captureTimeout: 6000,
        singleRun: false
    });
};

It works now properly, but when I try to use basePath: "root", then it sets the basePath to root/../../../ which I think is because the configFile: '../../../karma.conf.js', part of the gulp task. I use win7 x64. Any idea why this happens?

@devoto13
Copy link
Collaborator

I would say it is a bug in Karma, which we should fix. This will be a breaking change though.

What happens is that Karma resolves the relative basePath relative to the configuration file directory (http://karma-runner.github.io/6.3/config/configuration-file.html#basepath). The directory of the configuration file is ../../../, hence the basePath is resolved to root/../../... This part works as intended.

The bug is that when using Karma programmatically the configuration file path is resolved relative to the node_modules/karma/lib instead of CWD, hence you have to set it as ../../../karma.conf.js instead of ./karma.conf.js. So we should change this part, which will, in turn, resolve the problem with basePath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant