Skip to content

Instantly share code, notes, and snippets.

@gscoppino
Last active January 14, 2016 23:41
Show Gist options
  • Save gscoppino/8b7e6b401ab73e98d8c0 to your computer and use it in GitHub Desktop.
Save gscoppino/8b7e6b401ab73e98d8c0 to your computer and use it in GitHub Desktop.
Karma with support for test all and test module
/**
* Assuming karma.conf.js like:
* ====================================
* module.exports = function (config) {
config.set({
files: [
'my',
'required',
'files'
]
});
};
* ====================================
**/
// Use Minimist to parse CLI args
var argv = minimist(process.argv.slice(2));
// Get Config
var KarmaSettings;
var KarmaStub = {
set: function (config) {
KarmaSettings = config;
}
};
require('./karma.conf.js')(KarmaStub);
// The actual Gulp task.
gulp.task('test', function () {
if (argv.m) {
KarmaSettings.files.pop(); // Pop last index which should be the one including the spec files.
KarmaSettings.files.push(path.join('src', argv.m, '**', '*.spec.js'));
} else {
// Leave settings as is: with run all tests.
}
new KarmaServer({
configFile: './karma.conf.js',
files: KarmaSettings.files
}).start();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment