Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Karma, how do I exclude all files that match a pattern except for those within a specific sub-folder?

Tags:

I have a simple AngularJs application setup, that looks a bit like this:

client     vendor         angular         bootstrap         jquery         ...     app.module.js     app.controller.js     ... node_modules     angular-mocks     ... 

I'm setting up a karma.conf.js file and I want to include angular\angular.js from vendor. I don't want to include anything else from vendor.

Here is what I have in the relevant karma.conf.js sections:

files: [     'client/vendor/angular/angular.js',     'client/**/*.js',     'client/**/*.spec.js' ], exclude: [     'client/vendor/**/*.js' ], 

The problem I have is simple: I'm including angular.js explicitly in files, but it is then being excluded in the exclude section pattern.

How can I exclude all of client/vendor except for angular/angular.js (and perhaps others later)? The client directory contains a lot of files, sub-folders, etc, that include my own .js files, so it's not easy to just move everything I want to include into a folder of its own, for example.

like image 778
Kirk Larkin Avatar asked Feb 21 '15 21:02

Kirk Larkin


1 Answers

Try this:

client/vendor/**/!(angular).js 

Example

More filenames can be excluded like this:

client/vendor/**/!(angular|angular-route).js 

The patterns used here are called globs.

Here is a short guide to glob functionality in node from node-globs on GH.

like image 80
Mosho Avatar answered Nov 18 '22 21:11

Mosho