0

I am trying to run some Mocha tests within my Node.js app.

Here is my folder structure:

compute/ folder1/ app/ tests/ mytest.js folder2/ app/ tests/ mytest2.js 

I got a package.json in both with mocha installed.

When I try to start a test with yarn test, I got an error

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

No test files found

How can I manage to run it?

Because my folders' names are "tests" and not "test" as in the default and they are not at source.

1 Answer 1

1

When you don't use the default folders, you need to specify them as arguments. An example follows:

mocha "folder{1,2}/**/tests/*.js" 

If you want to run with only npm test/yarn test, then you need to update your package.json file like following:

 "scripts": { "test": "mocha \"folder{1,2}/**/tests/*.js\"", }, 
Sign up to request clarification or add additional context in comments.

4 Comments

Ok and if I change the folder name by "test", mocha will run all my tests into subdirectories ?
I updated my folders to "test" and in package.json got "test" : "mocha" but it is still not working
can you update your question with the related lines from package.json.
Oh ok I got it, it works, I did bad with the link when I tried to run the command "mocha folder1/..."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.