jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.27k stars 6.47k forks source link

testMatch not working as expected #7036

Open DaveStein opened 6 years ago

DaveStein commented 6 years ago

🐛 Bug Report

The regex is not working as I expected within testMatch argument.

To Reproduce

Steps to reproduce the behavior:

I thought I was passing the argument incorrectly via CLI so I started messing with the defaults in jest itself and found something odd.

If I change the default testMatch to this, it still works: testMatch: ['**/?(*.)+(test).js'],

If I change it to this, it finds no tests: testMatch: ['**/?(*.)+test.js'],

Expected behavior

I would expect this to work, without adding a capturing group

In [REMOVED]
  107 files checked.
  testMatch: **/?(*.)+test.js - 0 matches
  testPathIgnorePatterns: /node_modules/ - 107 matches
Pattern:  - 0 matches

Link to repl or repo (highly encouraged)

N/A

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.3
    CPU: x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
  Binaries:
    Node: 8.10.0 - /usr/local/bin/node
    npm: 6.1.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^23.3.0 => 23.4.0 
SimenB commented 6 years ago

@thymikee thoughts?

thymikee commented 6 years ago

Does it happen on latest jest too? I'd need to take a closer look if this is a micromatch bug or something we escape maybe.

DaveStein commented 6 years ago

Updated.

  System:
    OS: macOS High Sierra 10.13.3
    CPU: x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
  Binaries:
    Node: 8.10.0 - /usr/local/bin/node
    npm: 6.1.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0

Line 98 of Defaults.js: testMatch: ['**/?(*.)+(test).js'], = found tests testMatch: ['**/?(*.)+test.js'] = same bug

I copy pasted from the file, rather than deleting the parenthesis in this comment just to be super paranoid.

image

Saibamen commented 5 years ago

Similar: https://github.com/facebook/jest/issues/7441 and https://github.com/facebook/create-react-app/issues/5935

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

Saibamen commented 2 years ago

.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

Saibamen commented 1 year ago

,

jcubic commented 10 months ago

It seems that 'testMatch' in config doesn't work at all (at least with ts-jest).

Adding default value from documentation:

'testMatch': [ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ],

give this output:

  16 files checked.
  testMatch: src/__tests__/*.spec.ts - 0 matches
  testPathIgnorePatterns: /node_modules/ - 16 matches
  testRegex:  - 0 matches
Pattern:  - 0 matches