Skip to content

Commit

Permalink
added option to pass in individual globs to unit test watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerdinacan committed Mar 6, 2019
1 parent 8bc23e0 commit 9d0cf40
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions client/karma/karma.config.mocha.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
/**
* Runs mocha tests
*
* Individual files can be run by passing in a comma-delimited list
* of globs for the karma config like this:
*
* env KARMA_TESTS="Tags.test.js,something.js,doodads.js" npm run test-watch
*/

const baseKarmaConfig = require("./karma.config.base");


// Unless we have an environment variable picking out
// a specified set of files, this is what's going to run
const defaultFiles = [
// component/module tests
"**/*.test.js",
// pre-existing rules definition tests
"**/mocha/tests/*_tests.js"
]

// allows running just a set list of files
function getTestFiles(testFiles) {
let patterns = testFiles ? testFiles.split(",").map(checkGlobPrefix) : defaultFiles;
return patterns.map(pattern => ({ pattern, watched: true}));
}

// prefixes user-supplied glob with directory wildcard
function checkGlobPrefix(glob) {
if (!glob.startsWith("**/")) {
return `**/${glob}`;
}
return glob;
}

module.exports = function (config) {

// assemble test files, can run individuals by specifying
// globs on command line
let files = [
"../../node_modules/@babel/polyfill/dist/polyfill.js",
...getTestFiles(process.env.KARMA_TESTS)
];

let settings = Object.assign({}, baseKarmaConfig, {
files: [
"../../node_modules/@babel/polyfill/dist/polyfill.js",
{ pattern: "**/*.test.js", watched: true },
{ pattern: "**/mocha/tests/*_tests.js" }
],
files,
preprocessors: {
"**/*.js": ["webpack"]
},
Expand Down

0 comments on commit 9d0cf40

Please sign in to comment.