Tree
Tree

Reputation: 31371

How to run jest files that have no .test. in their filename?

I have some tests that are ment to be run aside from all other .test files so I called them .integration.js

how to test all files that have .integration.js?

example file; endpoint.integration.js

Upvotes: 7

Views: 4865

Answers (2)

TOPKAT
TOPKAT

Reputation: 8678

// jest.config.ts

const config: Config = {
    testRegex: ['\\.spec\\.[jt]sx?$'], // match file.spec.ts, file.spec.jsx...
    ...
}
  • the regexp shall be type string and not a real Regexp
  • dots and other regexp special character shall be escaped as well as escape character in the string, that's why we need double escape (eg. \\.)
  • See documentation

Upvotes: 0

Håken Lid
Håken Lid

Reputation: 23064

You can configure custom test file names with the config key testRegex. https://jestjs.io/docs/en/configuration#testregex-string--arraystring

The default is: (/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$

So to only run tests in files like endpoint.integration.js tests, you can use this regex instead: \\.integration\\.js$

You can put this in your configuration either in package.json or jest.config.js.

Or you can use the regex as the first argument to the jest cli command.

jest '\\.integration\\.js$'

Upvotes: 7

Related Questions