Commit 35d754f6 authored by Lukas Eipert's avatar Lukas Eipert

read which testfiles to run from CLI

parent 8e664114
...@@ -16,9 +16,14 @@ if (webpackConfig.plugins) { ...@@ -16,9 +16,14 @@ if (webpackConfig.plugins) {
webpackConfig.plugins = []; webpackConfig.plugins = [];
} }
var ignoreUpTo = process.argv.indexOf('config/karma.config.js') + 1;
var testFiles = process.argv.slice(ignoreUpTo).filter(arg => {
return !arg.startsWith('--');
});
webpackConfig.plugins.push( webpackConfig.plugins.push(
new webpack.DefinePlugin({ new webpack.DefinePlugin({
TEST_FILE: JSON.stringify(process.env.TEST_FILE), TEST_FILES: JSON.stringify(testFiles),
}) })
); );
......
...@@ -70,20 +70,22 @@ beforeEach(() => { ...@@ -70,20 +70,22 @@ beforeEach(() => {
}); });
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
let testFile = TEST_FILE; let testFile = TEST_FILES;
if (testFile) { if (testFile instanceof Array && testFile.length > 0) {
console.log(`Running only ${testFile}`); console.log(`Running only tests: ${testFile}`);
testFile = testFile.replace(/^spec\/javascripts\//, ''); testFile = testFile.map(path => path.replace(/^spec\/javascripts\//, '').replace(/\.js$/, ''));
testFile = testFile.replace(/\.js$/, ''); } else {
console.log('Running all tests');
testFile = [];
} }
const axiosDefaultAdapter = getDefaultAdapter(); const axiosDefaultAdapter = getDefaultAdapter();
// render all of our tests // render all of our tests
const testsContext = require.context('.', true, /_spec$/); const testsContext = require.context('.', true, /_spec$/);
testsContext.keys().forEach(function (path) { testsContext.keys().forEach(function(path) {
try { try {
if (!testFile || path.indexOf(testFile) > -1) { if (testFile.length === 0 || testFile.some(p => path.includes(p))) {
testsContext(path); testsContext(path);
} }
} catch (err) { } catch (err) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment