使用 Karma,我如何排除除特定子文件夹中的文件之外的所有匹配模式的文件?

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

我有一个简单的 AngularJs 应用程序设置,看起来有点像这样:

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

我正在设置一个 karma.conf.js 文件,我想包含 vendor 中的 angular\angular.js。我不想包含 vendor.

中的任何其他内容

这是我在相关 karma.conf.js 部分中的内容:

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

我遇到的问题很简单:我在 files 中明确包含 angular.js,但它随后被排除在 exclude 部分模式中。

如何排除除 angular/angular.js 之外的所有 client/vendor(可能还有其他人)? client 目录包含许多文件、子文件夹等,其中包括我自己的 .js 文件,因此将我想要包含的所有内容移动到它自己的文件夹中并不容易,例如。

试试这个:

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

Example

可以像这样排除更多文件名:

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

此处使用的模式称为 globs

这是 GH 上 node-globs 节点中 glob 功能的简短 guide