2

I have been trying to run some tests located in its own folder using Jest but it claims that no tests have been found.

The file structure is as follows:

.
└── repo-folder/
    ├── ...
    └── tests/
        ├── integration/
        │   └── ...
        └── unit/
            ├── 1.test.ts
            ├── 2.test.ts
            ├── ...
            └── 4.test.ts

What I want to do is to run the unit tests without running the integration tests. To do this I have tried using the Jest CLI command (from package.json):

jest --roots=./tests/unit

However, this results in the following error:

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /home/myusername/repos/repo-folder
  4 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 4 matches
  testPathIgnorePatterns: build - 0 matches
  testRegex:  - 0 matches
Pattern:  - 0 matches

I have tried a few different flags for Jest such as --testPathPattern or just adding the file path as an argument at the end of the command, though this actually found all test files in the root directory. I found a similar previous question Jest No Tests found but in my own Jest config only the build directory for the TypeScript build is ignored.

The project uses ts-jest and jest-extended if that may somehow cause any issues for Jest. My jest.config.js looks like this:

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
    clearMocks: true,
    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
    roots: ['<rootDir>'],
    transform: {
        '^.+\\.ts?$': 'ts-jest',
    },
    setupFilesAfterEnv: ['jest-extended'],
    globals: {
        'ts-jest': {
            diagnostics: false,
            isolatedModules: true,
        },
    },
    preset: 'ts-jest',
    testEnvironment: 'node',
    coverageProvider: 'v8',
    testPathIgnorePatterns: ['build'],
};
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Simon
  • 83
  • 3
  • Can you try to run this in the cli ```NODE_ENV=local jest --config jest.conf.js -i tests/unit``` – Ovidijus Parsiunas Apr 22 '22 at 11:16
  • @OvidijusParsiunas it did not work, same error but it looked through all test files so `testMatch` gave me more matches. Apart form that it was pretty much the same error. – Simon Apr 22 '22 at 11:24
  • `testMatch: ... - 4 matches`. Let's write your test in your test file (ex: 1.test.ts) – hoangdv Apr 23 '22 at 02:22

0 Answers0