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

Mocha reports 'No test files found' since mocha 6 (with ts-node) #3772

Closed
4 tasks done
evert opened this issue Feb 25, 2019 · 11 comments
Closed
4 tasks done

Mocha reports 'No test files found' since mocha 6 (with ts-node) #3772

evert opened this issue Feb 25, 2019 · 11 comments

Comments

@evert
Copy link

evert commented Feb 25, 2019

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

Since the upgrade to mocha 6 my tests no longer work. I ensures that it wasn't any other package update that caused this issue by keeping all my dependencies identical except mocha 5 / 6.

The configuration I use in `mocha.opts' is as follows:

--recursive
--require ts-node/register
--exit
test/**/*.ts

The error I get from running ./node_modules/.bin/mocha is 'No test files found

I realize that this issue might not be caused by mocha, but it seemed like a good first place to ask. Could something have changed that would cause something like ts-node to fail?

@plroebuck
Copy link
Contributor

It's a 6.0 bug (#3763), fix is in process.
Workaround until then by repeating the spec glob:

"package.json":

{
  "scripts": {
    "test": "mocha 'test/**/*.ts'"
  }
}

@evert
Copy link
Author

evert commented Feb 25, 2019

Thanks for the quick response. Super appreciate this project!

@umakanth-pendyala
Copy link

I have a similar kind of problem. Please take a look at the following link.
https://stackoverflow.com/questions/64173341/unable-to-find-server-js-file-while-testing-with-mocha

@jef
Copy link

jef commented Jan 17, 2021

This still exists today unfortunately.

@evert
Copy link
Author

evert commented Jan 17, 2021

It doesn't, I use this configuration and it's perfect:

  "mocha": {
    "require": [
      "ts-node/register",
    ],
    "recursive": true,
    "extension": [
      "ts",
      "js",
      "tsx"
    ],
  }

@jef
Copy link

jef commented Jan 17, 2021

Oh, I'm sorry. I didn't mean to necrobump this, especially since it's not the right issue I was looking at 😢

Thanks for replying and adding your example!

@ComFreek
Copy link

ComFreek commented Feb 19, 2021

For me, the problem was that I didn't specify spec (e.g. spec: ["**/*.spec.ts"]). Instead due to confusion, I specified watch-files: ["**/*.spec.ts"], which certainly is a good setting, too, but it's really spec that determines which files are used for tests.

If you leave spec undefined, the default value is used, which I presume to be test. If you're not using a dedicated test folder (as I was), no files will be found, hence the error message "No test files found".

@mgonzalez121690
Copy link

@ComFreek I really appreciate your comment... I only added this on my mocha config and works fine :D

@c4nzin
Copy link

c4nzin commented Feb 9, 2023

"test": "mocha 'test/**/*.ts'"

Thanks man you are life saver ! :D

@mcbriandavids
Copy link

This was the solution to this error i had when a run test coverage script
"Error: No test files found: "./tests/""
{
"scripts": {
"test": "mocha 'test/**/
.ts'"
}
}

@mcbriandavids
Copy link

"test": "mocha ./tests/**/* --timeout 20000 --exit",
"coverage": "nyc npm run test"

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

8 participants