From 70cf9030d20b6f88be2a266de7c2947bc478a62c Mon Sep 17 00:00:00 2001 From: Dan Siwiec Date: Mon, 31 Aug 2015 23:46:03 -0700 Subject: [PATCH] feat(config): Pass CLI arguments to `karma.config.js`. Closes #1561 --- lib/config.js | 1 + test/unit/config.spec.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/config.js b/lib/config.js index 57cf4aa04..e305e46ba 100644 --- a/lib/config.js +++ b/lib/config.js @@ -300,6 +300,7 @@ var parseConfig = function (configFilePath, cliOptions) { } var config = new Config() + config.set(cliOptions) try { configModule(config) diff --git a/test/unit/config.spec.js b/test/unit/config.spec.js index 58e769392..2c78ab2f9 100644 --- a/test/unit/config.spec.js +++ b/test/unit/config.spec.js @@ -38,6 +38,7 @@ describe('config', () => { '/home/config4.js': wrapCfg({port: 123, autoWatch: true, basePath: '/abs/base'}), '/home/config6.js': wrapCfg({reporters: 'junit'}), '/home/config7.js': wrapCfg({browsers: ['Chrome', 'Firefox']}), + '/home/config8.js': config => config.set({ files: config.suite === 'e2e' ? ['tests/e2e.spec.js'] : ['tests/unit.spec.js'] }), '/conf/invalid.js': () => { throw new SyntaxError('Unexpected token =') }, '/conf/exclude.js': wrapCfg({exclude: ['one.js', 'sub/two.js']}), '/conf/absolute.js': wrapCfg({files: ['http://some.com', 'https://more.org/file.js']}), @@ -144,6 +145,14 @@ describe('config', () => { expect(config.browsers).to.deep.equal(['Safari']) }) + it('should have access to cli options in the config file', () => { + var config = e.parseConfig('/home/config8.js', {suite: 'e2e'}) + expect(patternsFrom(config.files)).to.deep.equal([resolveWinPath('/home/tests/e2e.spec.js')]) + + config = e.parseConfig('/home/config8.js', {}) + expect(patternsFrom(config.files)).to.deep.equal([resolveWinPath('/home/tests/unit.spec.js')]) + }) + it('should resolve files and excludes to overriden basePath from cli', () => { var config = e.parseConfig('/conf/both.js', {port: 456, autoWatch: false, basePath: '/xxx'})