How to skip a file from executing in jest?

Viewed 2016

I am working on integration tests with jest where i have a 20 test files under a folder. I need to make sure three files in that folder need not to be executed while running the tests. i tried with testPathIgnorePatterns but it only works for folders and not for files. how to do that?

jest.config.js

/**
 * @file Jest Integration Test Configuration File
 */

module.exports = {
  roots: ['../../tests'],
  testRegex: '_*_integration.test.(js|ts|tsx)?$',
  globals: {
    'ts-jest': {
      tsconfig: 'tsconfig.json',
    },
  },
  moduleFileExtensions: ['ts', 'js'],
  transform: {
    '^.+\\.(ts|tsx)$': 'ts-jest',
  },
  testPathIgnorePatterns: ['tests/api/modules/m3/sample.test.ts'],
  testEnvironment: 'node',
  reporters: [
    'default',
    [
      '../../node_modules/jest-html-reporter',
      {
        pageTitle: 'Integration Test Report',
        outputPath: 'tests/reports/integration-test-report.html',
        includeFailureMsg: true,
      },
    ],
  ],
};

2 Answers

How about using --testPathIgnorePatterns cli option?

yarn test --testPathIgnorePatterns=user.test.ts

If for multi files, can use below.

yarn test --testPathIgnorePatterns=filename1 filename2

You can use the collectCoverageFrom parameter of Zest json like this,

collectCoverageFrom: ['path-to-file1','path-to-file2'],

Note: This option requires collectCoverage to be set to true or Jest to be invoked with --coverage.

Refer documentation

In documentation, they specified a pattern but it works file static file paths too.

Related