Skip to content
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

Warning: Could not find any test files matching pattern: #2895

Closed
wzup opened this issue Jun 20, 2017 · 10 comments
Closed

Warning: Could not find any test files matching pattern: #2895

wzup opened this issue Jun 20, 2017 · 10 comments

Comments

@wzup
Copy link

wzup commented Jun 20, 2017

Why the plugin doesn't see files when files 100% exist in my test folder?
I want to run test for certain files only.
How do I do it with mocha?

My set up:

// test folder. Files are the same. Changed name for the sake of showing you an error
/test
    nock.js
    nock_test.js

// package.json
"scripts": { "test": "mocha" }

None of these work. All throw the same error:

$ npm test nock
$ npm test nock.js
$ npm test nock_test
$ npm test nock_test.js

Error:

Warning: Could not find any test files matching pattern: nock
Warning: Could not find any test files matching pattern: nock.js
Warning: Could not find any test files matching pattern: nock_test
Warning: Could not find any test files matching pattern: nock_test.js
No test files found
npm ERR! Test failed. See above for more details.

How it can be? No test files matching pattern? It is not even a pattern! It is exactly a file name.
How to run it?

@ScottFreeCode
Copy link
Contributor

You should be writing test/nock.js/test/test_nock.js instead of just nock.js/test_nock.js. Please let us know if that resolves your issue!

(Mocha supports putting your test files in other folders than test; for example, some projects put test files in the same folders as corresponding source files and with the same name except using .test.js or .spec.js instead of .js at the end of the test file's name. It's a tradeoff between cleanliness of source directories vs ease of association of test and source, but the important thing is Mocha supports both and therefore won't prevent the one by turning lib/someModule.spec.js into test/lib/someModule.spec.js.)

@ScottFreeCode ScottFreeCode added the status: waiting for author waiting on response from OP - more information needed label Jun 24, 2017
@ScottFreeCode ScottFreeCode added the type: question support question label Sep 4, 2017
@rintran720
Copy link

In my project:

  • Tree:
    project
    ------build
    ------node_modules
    ------src
    -----------components
    ------------------A.js
    ------------------A.spec.js
    ------test
    -----------setup.js
    ------package.json
  • Test script:
    "test": "mocha --compilers js:babel-core/register -r ./test/setup.js './src/**/*.spec.js*'"
  • Dependencies:
    "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-1": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "chai": "^4.1.2",
    "enzyme": "^2.9.1",
    "html-webpack-plugin": "^2.30.1",
    "jsdom": "^11.2.0",
    "mocha": "^3.5.3",
    "react-addons-test-utils": "^15.6.0",
    "webpack": "^3.5.6",
    "webpack-dev-server": "^2.8.1"
    },
    "dependencies": {
    "react": "^15.6.1",
    "react-dom": "^15.6.1"
    }

When i run npm test:

Warning: Could not find any test files matching pattern: './src/**/.spec.js'

        Please, help me!

@ykadosh
Copy link

ykadosh commented Oct 30, 2017

It looks like mocha is including the single quotes in the pattern itself. I was able to get around it by using escaped double quotes:

"test": "mocha --compilers js:babel-core/register -r ./test/setup.js \"./src/**/*.spec.js*\""

@Aarbel
Copy link

Aarbel commented Dec 26, 2017

Hi ! I have same issue, but here with Circle CI 2.0 (Ubuntu 14.04)

Works fine on MacOSX and Ubuntu 16.04, how could i solve this error with Circle CI environment ? Seems to be a Mocha trick... Thanks a lot !

In my term :

$ eslint .
$ mocha "./src/migrations/index.test.js" --require babel-core/register
Warning: Could not find any test files matching pattern: ./src/migrations/index.test.js
No test files found
error Command failed with exit code 1.

My package.json :

...
"test-migrations": "mocha \"./src/migrations/index.test.js\" --require babel-core/register",
"test": "yarn run lint && yarn run test-migrations && mocha \"./src/index.test.js\" --require babel-core/register",
...

@xurei
Copy link

xurei commented Apr 4, 2018

I have a similar issue :

mocha --opts "/c/my-project/mocha.opts" "/c/my-project/src/rest_test/**/*.tsx"

Doesn't work.
However, this does :

mocha --opts "/c/my-project/mocha.opts" "c:/my-project/src/rest_test/**/*.tsx"

(notice the /c/ becoming c:/)
The options path is alright with a unix-notation, but not the test files path.

@boneskull
Copy link
Contributor

@xurei's is the only thing I've seen here that could be an actual Mocha bug. I'll try to reproduce this.

@boneskull boneskull added unconfirmed-bug and removed status: waiting for author waiting on response from OP - more information needed type: question support question labels Apr 7, 2018
@boneskull
Copy link
Contributor

@xurei What shell are you using?

If you're in PowerShell, glob (which interprets your glob-containing path, because it's in double-quotes) expects your paths to look like your second example; the first example is not a valid path, AFAICT.

If you're in bash on Windows, then either should work, at least in my limited testing.

@xurei
Copy link

xurei commented Apr 10, 2018

@boneskull I'm using Git BASH

@MuhammadJamaluddin
Copy link

MuhammadJamaluddin commented Feb 14, 2019

My package.json has this:
"test": "mocha server/spec/server-spec.js; RES=$?; kill %1; exit $RES"
And my file structure is:

server
    spec
        server-spec.js

And, of course, I'm currently in the root directory where the server directory is located, but when I run npm test I get that error:
Warning: Could not find any test files matching pattern: server/spec/server-spec.js;
I'm using a Windows OS. I've tried cmd.exe (Cygwin is installed and added to the environment variables) & Git Bash, but I get the same result... Any idea?

@plroebuck
Copy link
Contributor

@MuhammadJamaluddin, you should be able to just have:

"scripts": {
  "test": "mocha server/spec/server-spec.js"
}

Depending on what version of mocha you're using, you may see something helpful in the debug output by using cross-env and launching it like this:

$ npm install --save-dev cross-env
"scripts": {
  "test": "cross-env DEBUG=* mocha server/spec/server-spec.js"
}

Or use a glob and just see what mocha finds... JIC you misspelled something...

"scripts": {
  "test": "cross-env DEBUG=* mocha 'server/**/*.js'"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants