-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Glob pattern not working as expected #1828
Comments
Note that I can get the desired behavior by modifying my test command thusly:
But this does seem incorrect. |
Use single quotes:
|
Thanks, that worked well. Can you explain why this works? Is the shell trying to interpret this before it hits mocha or something? |
Yes, if you don't use quotes, shell expands the glob pattern before it reaches Mocha. |
Got it, thanks for clarifying. |
no-issue This is because the shell will try to expand the glob if it's not wrapped in strings, which can give different outcomes depending on the globbing supporting by the shell. Passing a string will allow mocha to sort out globbing which is more predictable. Related issue is here: mochajs/mocha#1828
no-issue This is because the shell will try to expand the glob if it's not wrapped in strings, which can give different outcomes depending on the globbing supporting by the shell. Passing a string will allow mocha to sort out globbing which is more predictable. Related issue is here: mochajs/mocha#1828
if you use follow
this will exclude But If you use
it will throw exception wish it's will help others I'm using Windows 10 |
@iamwwc, The Since you're using Windows, its shell doesn't handle extended globs anyway, and the choice of single vs. double quotes should be meaningless. To easily exclude Typescript files within the "testdata" directory (and its subdirectories), try: C:\> mocha --require ts-node/register --exclude 'test/testdata/**' 'test/**/*.ts' If needed, the Directory Structure$ cd /tmp
$ mkdir test
$ touch test/setup.ts
$ mkdir test/subdir1
$ touch test/subdir1/file1.ts
$ mkdir test/subdir2
$ touch test/subdir2/file2a.ts
$ touch test/subdir2/file2b.ts
$ mkdir test/testdata
$ touch test/testdata/tdfile.ts
$ mkdir test/testdata/subdir3
$ touch test/testdata/subdir3/file3.ts
$ find test -type f -print
test/setup.ts
test/subdir1/file1.ts
test/subdir2/file2a.ts
test/subdir2/file2b.ts
test/testdata/subdir3/file3.ts
test/testdata/tdfile.ts TestI patched console.log('files:', files); I left the Typescript registration out here as these are empty files anyway. $ mocha --exclude 'test/testdata/**' 'test/**/*.ts'
files: [ 'test/setup.ts',
'test/subdir1/file1.ts',
'test/subdir2/file2a.ts',
'test/subdir2/file2b.ts' ]
You don't mention what exception you get (nor your directory structure)... References: |
I'm trying to get
That doesn't work anymore when generating ES6 modules. I'd use the But adding those To simplify for now, I've taken out nyc, and I'm trying things like this:
I get no errors this way, but nothing happens either. It's like the My do-nothing (for now) dummy loader looks like this:
I can tell it gets loaded because the I've tried other permutations, but just get errors like I was hoping to see my loader invoked for every |
Integration tests are executed using vue-cli-service with double quotes as following: `vue-cli-service test:unit "tests/integration/**/*.spec.ts"`. Using single quotes (mochajs/mocha#1828) works on macOS and Ubuntu but does not on Windows (tests are not found). Double quotes is the only portable way that works on all three platforms (mochajs/mocha#3136).
Note for ones who still have this problem in 2022 or later. Incorrect, won't work:
Correct:
|
Integration tests are executed using vue-cli-service with double quotes as following: `vue-cli-service test:unit "tests/integration/**/*.spec.ts"`. Using single quotes (mochajs/mocha#1828) works on macOS and Ubuntu but does not on Windows (tests are not found). Double quotes is the only portable way that works on all three platforms (mochajs/mocha#3136).
`passport-server` tests are only matching a single test file, instead of all files in `test` and its subdirectories. This means that the majority (227 of 231) tests for `passport-server` are not being run in CI. Fix is the same as described here: mochajs/mocha#1828 - because the pattern is unquoted, it gets expanded by the shell rather than passed through, and the shell pattern expansion algorithm is different/inferior.
I'm using mocha on a node project. I'd like to run all js files in a
test
directory and its subdirectories. I've added this block to my package.json:This glob pattern ONLY matches files in subdirectories of tests; it does not match top level files. This is confusing to me because the pattern as run through the
glob
module does indeed match as desired. Am I missing something obvious here or is this a bug?The text was updated successfully, but these errors were encountered: