diff --git a/config/karma.config.js b/config/karma.config.js index 15f027c164c58c5ea62c38282234b845943d5687..61f02294157bfc75073165e48ac1be5622b5ee65 100644 --- a/config/karma.config.js +++ b/config/karma.config.js @@ -1,5 +1,6 @@ var path = require('path'); var webpack = require('webpack'); +var argumentsParser = require('commander'); var webpackConfig = require('./webpack.config.js'); var ROOT_PATH = path.resolve(__dirname, '..'); @@ -14,14 +15,21 @@ if (webpackConfig.plugins) { }); } -var ignoreUpTo = process.argv.indexOf('config/karma.config.js') + 1; -var testFiles = process.argv.slice(ignoreUpTo).filter(arg => { - return !arg.startsWith('--'); -}); +var testFiles = argumentsParser + .option( + '-f, --filter-spec [filter]', + 'Filter run spec files by path. Multiple filters are like a logical OR.', + (val, memo) => { + memo.push(val); + return memo; + }, + [] + ) + .parse(process.argv).filterSpec; webpackConfig.plugins.push( new webpack.DefinePlugin({ - 'process.env.TEST_FILES': JSON.stringify(testFiles) , + 'process.env.TEST_FILES': JSON.stringify(testFiles), }) ); diff --git a/doc/development/testing_guide/frontend_testing.md b/doc/development/testing_guide/frontend_testing.md index 37653758e57899228be52eb2f1a0f7511c4884d8..0a6f402d5d2583456c823ddb6a04e48d1b09c80d 100644 --- a/doc/development/testing_guide/frontend_testing.md +++ b/doc/development/testing_guide/frontend_testing.md @@ -165,18 +165,18 @@ excluded tests (with `fdescribe` or `xdescribe`) to get karma to run only the tests you want while you're working on a specific feature, but make sure to remove these directives when you commit your code. -It is also possible to only run karma on specific folders or files by simply -appending the file name to the karma command: +It is also possible to only run karma on specific folders or files by filtering +the run tests via the argument `--filter-spec` or short `-f`: ```bash # Run all files yarn karma-start # Run specific spec files -yarn karma-start profile/account/components/update_username_spec.js +yarn karma-start --filter-spec profile/account/components/update_username_spec.js # Run specific spec folder -yarn karma-start profile/account/components/ -# Run all specs in vue_shared and vue_mr_widget -yarn karma-start /vue_shared/ /vue_mr_widget/ +yarn karma-start --filter-spec profile/account/components/ +# Run all specs which path contain vue_shared or vie +yarn karma-start -f vue_shared -f vue_mr_widget ``` ## RSpec feature integration tests diff --git a/package.json b/package.json index 763b0345e7c6ccdd29bd6f499f205dd6823a0cbb..7bac672a0b27bdc1adbccb9426af4a80c9f1f381 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ "axios-mock-adapter": "^1.10.0", "babel-eslint": "^8.0.2", "babel-plugin-istanbul": "^4.1.5", + "commander": "^2.15.1", "eslint": "^3.18.0", "eslint-config-airbnb-base": "^10.0.1", "eslint-import-resolver-webpack": "^0.8.3", diff --git a/yarn.lock b/yarn.lock index 243b83f44717d07a1466b8326448d76bc37ff86d..c4d682016a08fbd11b2c55d4cef069b66995b1c5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1859,9 +1859,9 @@ combined-stream@1.0.6, combined-stream@^1.0.5, combined-stream@~1.0.5: dependencies: delayed-stream "~1.0.0" -commander@^2.13.0, commander@^2.9.0: - version "2.14.1" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.1.tgz#2235123e37af8ca3c65df45b026dbd357b01b9aa" +commander@^2.13.0, commander@^2.15.1, commander@^2.9.0: + version "2.15.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" commondir@^1.0.1: version "1.0.1"