javascript - How does this pattern work: 'teste2e***.spec.js'? - Stack Overflow

I saw this pattern used in a configuration file for protractor.specs: ['teste2e***.spec.js'

I saw this pattern used in a configuration file for protractor.

specs: [
  'test/e2e/**/*.spec.js'
]

To mean it means "all files inside test/e2e". What kind of pattern is this? I think it's not regex because of those unescaped slashes. Especially, why is there ** in the middle, not just test/e2e/*.spec.js?

I tried using the search engine, but did not find anything useful probably because the asterisks don't work very well in search engines.

I saw this pattern used in a configuration file for protractor.

specs: [
  'test/e2e/**/*.spec.js'
]

To mean it means "all files inside test/e2e". What kind of pattern is this? I think it's not regex because of those unescaped slashes. Especially, why is there ** in the middle, not just test/e2e/*.spec.js?

I tried using the search engine, but did not find anything useful probably because the asterisks don't work very well in search engines.

Share Improve this question edited Dec 22, 2018 at 19:26 Alexander O'Mara 60.6k19 gold badges172 silver badges181 bronze badges asked Dec 31, 2015 at 22:22 user69715user69715 8949 silver badges16 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 7

What kind of pattern is this?

It is called "glob". The module glob is a popular implementation for Node, and appears to be the one used by Protractor.

Especially, why is there "**" in the middle, not just "test/e2e/*.spec.js"?

** means it can match sub-directories. It's like a wildcard for sub-directories.

For example, test/e2e/*.spec.js would match test/e2e/example.spec.js, but not test/e2e/subdir/example.spec.js. However test/e2e/**/*.spec.js matches both.

It is called "glob" syntax. Glob is a tool which allows files to be specified using a series of wildcards.

  • *.js means "everything in a folder with a js extension.
  • ** means "descendant files/folders.
  • **/*.js means "descendant files with a js extension in descendant folders."
  • test/e2e/**/*.spec.js' means the above, starting in the test/e2e/ directory.

So, for example, given this file system:

test/e2e/foo/a.spec.js <-- matches
test/e2e/foo/butter.js <-- does not include "spec.js"
test/e2e/bar/something.spec.js <-- matches
test/other/something-different.spec.js <-- not in /test/e2e

The final pattern would match:

test/e2e/foo/a.spec.js
test/e2e/bar/something.spec.js

It's a globbing pattern. Most javascript things using globbing patterns seem to be based around the glob npm package. It's worth taking a look at the documentation as there are some handy hints in there for when you have more plex situations.

The path you are asking about will match any file ending .spec.js in any subdirectory under test/e2e

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743711450a4494253.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信