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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28651306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:11:47  来源:igfitidea点击:

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

javascriptangularjskarma-jasmine

提问by Kirk Larkin

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

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

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

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

我正在设置一个karma.conf.js文件,我想angular\angular.jsvendor. 我不想包含来自vendor.

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

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

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.jsexplicitly in files, but it is then being excluded in the excludesection pattern.

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

How can I exclude all of client/vendorexcept for angular/angular.js(and perhaps others later)? The clientdirectory 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.

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

回答by Mosho

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.

这里使用的模式称为globs

Here is a short guideto glob functionality in node from node-globson GH.

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