Ava: I have tests that passed - now I get: Couldn't find any files to test

Created on 14 Aug 2018  Â·  22Comments  Â·  Source: avajs/ava

Hi,

I have tests in a project that passed.
No changes to them, same location etc.

But when I run test now I get: 1 error "Couldn't find any files to test"

How can I resolve this? the test files are still where they have always been

bug

Most helpful comment

I'm also experiencing a similar issue while trying to setup testing with

  • ava v0.25.0
  • ts-node v7.0.1
  • typescript v3.0.3

on a 64-bit windows 10 machine working from WSL.

The error message is exactly the same and attempting to specify files like so npm test src/app.test.ts or ava src/app.test.ts doesn't change anything.

Currently I've resolved to building the project first before testing but it'd be nice to skip that step. 😄
Here's my setup

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "esModuleInterop": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "baseUrl": ".",
    "outDir": "dist",
    "noImplicitAny": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "include": [
    "src/**/*"
  ]
}

package.json

"scripts": {
    "test": "ava"
}
"ava": {
    "files": [
      "src/**/*.test.ts"
    ],
    "compileEnhancements": false,
    "extensions": [
      "ts"
    ],
    "require": [
      "ts-node/register"
    ]
  }

Any help would really be appreciated 🙂

PS: Omitting the files option from package.json also doesn't change a thing.

-----------------------------------------------------UPDATE-------------------------------------------------------

Thanks @novemberborn . It works with the latest beta at the time of writing v1.0.0-beta.8 .

All 22 comments

Can confirm other team member also getting same issue, so its not something thats gone wrong in my local directory

Which version are you using now? Where you using a different version before? Which one?

Could you share your AVA config so we can see how you're specifying the files?

I have a pretty basic setup, not specifying files they match default globs.
one is in src/helpers/validation/dob.validatior.test.js for example.
tried also specifying just that path, same error.

"ava": "^0.25.0"

"ava": {
    "require": [
      "babel-register"
    ],
    "babel": "inherit"
  }

Last week I had the tests passing and haven't changed anything in regards to tests since.
I could understand if maybe somethings gone wrong with my local machine, but a coworker who has never run the test command before also tried and also got the error.

here's a test file sample - tho the problem is its not being found

import { test } from 'ava';
import dob from './dob.validator';

test('dob() creates a dob validator', t => {
  t.is(typeof dob, 'function');
  const validator = dob();
  t.is(typeof validator, 'function');
});

test('validator will only allow valid yyyy-mm-dd strings', t => {
  const validator = dob();
  t.true(validator(null));
  t.true(validator(''));
  t.false(validator(0));
  t.false(validator(new Date()));
  t.false(validator('1st of January 1970'));
  t.true(validator('1970-01-01'));
});

test('validator will only allow valid days', t => {
  const validator = dob();
  t.false(validator('2000-01-00'));
  t.false(validator('2000-01-32'));
  t.true(validator('2000-01-31'));
  t.false(validator('2000-04-31'));
  t.true(validator('2000-04-30'));
  t.true(validator('2018-02-28'));
  t.true(validator('2020-02-29'));
});

test('validator will only allow valid months', t => {
  const validator = dob();
  t.false(validator('2000-00-01'));
  t.false(validator('2000-13-13'));
  t.true(validator('2000-12-01'));
});

test('validator will only allow dates with years >= minYear if specified', t => {
  const validator = dob('1900');
  t.false(validator('1899-12-31'));
  t.false(validator('0000-01-01'));
  t.true(validator('1980-05-20'));
});

test('validator will only allow dates with years <= maxYear if specified', t => {
  const validator = dob(null, '2000');
  t.false(validator('2001-01-01'));
  t.true(validator('1999-12-31'));
  // obviously it's best to also use minYear
  // most of the time unless you want 2000 year olds etc.
  t.true(validator('0000-01-01'));
});

I can ls dir structure from same root as the test command and see .test files:

image

Aha! As of beta 7, import { test } from 'ava'; should be import test from 'ava';.

That should have been reported though. I've opened https://github.com/avajs/ava/issues/1906 to track the issue.

(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)

I couldn't quite reproduce this behavior, but https://github.com/avajs/ava/pull/1923 improves the output for the default reporter when there's files without tests.

I don't see how the import would make a difference, if its no longer { test } then I would just get errors when i try to use tests, ava is simply not finding *.test.js files anywhere in my project.

I even throw an error in a *.test.js file and get nothing - surely if is was found there would be something in the console?

I see you have node >=8.9.4 listed in engines - which is what Im using (I usually use newer but the other dev has set it up with unrelated packages that need 8.9.4)

I did try import test from 'ava' but like I said its more like the test files themselves are never found even tho Im leaving the default glob patterns (I only have "test": "ava" in my package.json)

update:

I updated ava and used import test from 'ava' and created a test at same level as package.json

import test from 'ava';
test(t => t.fail());

That works... however it still doesn't reach any other tests for example in my src/ folder...

But according to your docs one of the patterns in the default globs is: **/*.test.js shouldnt that find *.test.js files in my src/ folder and any folder in my entire project?

Yea makes sense that the problem is something else. Looking at https://github.com/avajs/ava/issues/1903#issuecomment-412838425 again, I noticed the test file is inside a helpers directory. I don't think that'll work, see #909.

However, I don't know of any change since 0.25 that would impact this specifically.

I assume there are other files that suddenly aren't being picked up? Could you share some example file paths?

Hi it must be that it is in the project helpers/ directory.

However, it was working with files in the helpers/ directory fine.
Is there ways around that? The exisiting project already had a src/helpers/ directory

Even if its because helpers/ is ignored why did it work previously? I made no changes and they have always been in helpers

Is there ways around that?

Not at the moment, but I've been considering a stop-gap measure to at least make the helper matching configurable.

Even if its because helpers/ is ignored why did it work previously? I made no changes and they have always been in helpers

I'm curious about that, too. Is it just the test files in src/helpers that aren't working, or are there other files as well? Could you share some example file paths?

@novemberborn I have the same problem - my directory is /dest/blabal/blabla/helpers/filename.js and this folder just skipped even if I specify files section at config to check exactly this helpers folder. So the problem is in helpers pattern.

Can I help you somehow?

@havenchyk yea, sorry about that. #909 is the issue to track. As I mentioned above I've been wanting a way to change the glob patterns for helpers (including so you can disable it). This is part of a larger, complicated story with many trade-offs… which I haven't had time to properly summarize. Thanks for the offer though, perhaps keep an eye on the globbing issues for the time being?

@novemberborn, out of curiosity, what is the reasoning that led to helpers folder being excluded?

@ericmorand it's supposed to make it easier to group them in say test/helpers, but the current pattern is too aggressive and we haven't yet tackled that problem.

I'm also experiencing a similar issue while trying to setup testing with

  • ava v0.25.0
  • ts-node v7.0.1
  • typescript v3.0.3

on a 64-bit windows 10 machine working from WSL.

The error message is exactly the same and attempting to specify files like so npm test src/app.test.ts or ava src/app.test.ts doesn't change anything.

Currently I've resolved to building the project first before testing but it'd be nice to skip that step. 😄
Here's my setup

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "esModuleInterop": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "baseUrl": ".",
    "outDir": "dist",
    "noImplicitAny": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "include": [
    "src/**/*"
  ]
}

package.json

"scripts": {
    "test": "ava"
}
"ava": {
    "files": [
      "src/**/*.test.ts"
    ],
    "compileEnhancements": false,
    "extensions": [
      "ts"
    ],
    "require": [
      "ts-node/register"
    ]
  }

Any help would really be appreciated 🙂

PS: Omitting the files option from package.json also doesn't change a thing.

-----------------------------------------------------UPDATE-------------------------------------------------------

Thanks @novemberborn . It works with the latest beta at the time of writing v1.0.0-beta.8 .

@wmik try with the latest beta instead.

Same problem here but with beta 8
ava: 1.0.0-beta.8
ts-node: 7.0.1
typescript: 3.0.3

Says Couldn't find any files to test regardless of the files pattern.

tsconfig:

{
  "compilerOptions": {
    "target": "es2017",
    "outDir": "dist",
    "rootDir": "",
    "moduleResolution": "node",
    "module": "commonjs",
    "sourceMap": true,
    "declaration": true,
    "importHelpers": true,
    "listFiles": false,
    "traceResolution": false,
    "pretty": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2017",
      "dom",
      "esnext"
    ],
    "types": [
      "node"
    ],
    "baseUrl": "."
  },
  "include": [
    "**/*.ts"
  ],
  "exclude": [
    "node_modules/"
  ],
  "compileOnSave": false
}

ava.config.js:

export default {
  "ava": {
    "compileEnhancements": false,
    "extensions": [
      "ts"
    ],
    "require": [
      "ts-node/register"
    ],
    "files": [
      "tests/**/*.test.ts"
    ]
  }
}

My project looks like this:

server/...
tests/
-- user.test.ts
tests/helpers
    some helper files here

helpers are filtered out by default, consider another name of the folder. Maybe also try another pattern like tests/*.test.ts

My helpers folder doesn't include any tests, that should't prevent ava from finding my test files right?

tests/*.test.ts didn't find anything either.

But it seems like it runs the compiled files in dist/ automatically (I noticed because they were leftover files from my old compiling typescript method of running the tests).

If I delete dist/ then it won't find any files to test. The only place I have dist is in the tsconfig file. Maybe ava checks the tsconfig file and tries to look for files in the outDir folder but won't find any cause I deleted dist/ ?

@Christilut
Try putting the ava configuration object at the top level in the ava.config.js

export default {
  "compileEnhancements": false,
  "extensions": [
    "ts"
  ],
  "require": [
    "ts-node/register"
  ],
  "files": [
    "tests/**/*.test.ts"
  ]
}

Ah thanks! Missed that during the upgrade :)

Sorry @Christilut, this is a bit confusing. We should detect the ava key in the exported config. I've opened https://github.com/avajs/ava/issues/1943. Perhaps something you'd be interested in tackling?


I'm closing this since I don't think there's anything that isn't already covered by other issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

avaly picture avaly  Â·  4Comments

pocesar picture pocesar  Â·  3Comments

niftylettuce picture niftylettuce  Â·  4Comments

fregante picture fregante  Â·  3Comments

sindresorhus picture sindresorhus  Â·  4Comments