diff options
author | Lukas Eipert <leipert@gitlab.com> | 2018-07-27 16:55:14 +0200 |
---|---|---|
committer | Lukas Eipert <leipert@gitlab.com> | 2018-07-27 16:57:37 +0200 |
commit | e5ffef14618fe981fc9f674cf915b782b7f906ab (patch) | |
tree | 0dffbf92e2911bdf0acf5e8c68958f4108f9bd8e | |
parent | de1b64e83d66652e21e8b2ccf562e547d72458b0 (diff) | |
download | gitlab-ce-3871-get-karma-file-filter-to-work-again.tar.gz |
get `-f` to work again for EE files3871-get-karma-file-filter-to-work-again
-rw-r--r-- | config/karma.config.js | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/config/karma.config.js b/config/karma.config.js index 84810332dc2..e4d367174ab 100644 --- a/config/karma.config.js +++ b/config/karma.config.js @@ -6,6 +6,7 @@ const argumentsParser = require('commander'); const webpackConfig = require('./webpack.config.js'); const ROOT_PATH = path.resolve(__dirname, '..'); +const SPECS_PATH = /^(?:\.[\\\/])?spec[\\\/]javascripts[\\\/]/; function fatalError(message) { console.error(chalk.red(`\nError: ${message}\n`)); @@ -34,9 +35,23 @@ const specFilters = argumentsParser ) .parse(process.argv).filterSpec; -if (specFilters.length) { - const specsPath = /^(?:\.[\\\/])?spec[\\\/]javascripts[\\\/]/; +const createContext = (specFiles, regex, suffix) => { + if (specFiles.length < 1) { + return; + } + const newContext = specFiles.reduce((context, file) => { + const relativePath = file.replace(SPECS_PATH, ''); + context[file] = `./${relativePath}`; + return context; + }, {}); + + webpackConfig.plugins.push( + new webpack.ContextReplacementPlugin(regex, path.join(ROOT_PATH, suffix), newContext) + ); +}; + +if (specFilters.length) { // resolve filters let filteredSpecFiles = specFilters.map(filter => glob @@ -57,23 +72,12 @@ if (specFilters.length) { fatalError('Your filter did not match any test files.'); } - if (!filteredSpecFiles.every(file => specsPath.test(file))) { + if (!filteredSpecFiles.every(file => SPECS_PATH.test(file))) { fatalError('Test files must be located within /spec/javascripts.'); } - const newContext = filteredSpecFiles.reduce((context, file) => { - const relativePath = file.replace(specsPath, ''); - context[file] = `./${relativePath}`; - return context; - }, {}); - - webpackConfig.plugins.push( - new webpack.ContextReplacementPlugin( - /spec[\\\/]javascripts$/, - path.join(ROOT_PATH, 'spec/javascripts'), - newContext - ) - ); + const CE_FILES = filteredSpecFiles.filter(file => !file.startsWith('ee')); + createContext(CE_FILES, /spec[\\\/]javascripts$/, 'spec/javascripts'); } // Karma configuration |