如何在玩笑中跳过文件执行?

我正在使用 jest 进行集成测试,其中一个文件夹下有 20 个测试文件。我需要确保在运行测试时不需要执行该文件夹中的三个文件。我尝试使用testPathIgnorePatterns但它仅适用于文件夹而不适用于文件。怎么做?


笑话配置.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,

      },

    ],

  ],

};


蝴蝶刀刀
浏览 122回答 3
3回答

皈依舞

--testPathIgnorePatterns使用cli 选项怎么样?yarn test --testPathIgnorePatterns=user.test.ts如果对于多个文件,可以使用下面的。yarn test --testPathIgnorePatterns=filename1 filename2

繁花不似锦

对于 Jest 覆盖范围中要忽略的单个文件,请放置以下行/* istanbul ignore next */忽略个别功能,请忽略上面的功能/* istanbul ignore next */const ignoreFunc =()=>{ console.log('This function will be ignored from coverage')}

米琪卡哇伊

collectCoverageFrom您可以像这样使用Zest json 的参数,collectCoverageFrom: ['path-to-file1','path-to-file2'],注意:此选项需要将collectCoverage设置为true或调用Jest--coverage.在文档中,他们指定了一种模式,但它也适用于文件静态文件路径。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript