Support/Jest

[Jest] jest.config.mjs에 대하여 파헤치기 Part.1

개발자 나르 2022. 10. 14. 21:50
반응형

jest.config.mjs이 길어서 잘라서 파헤쳐보겠습니다.

jest.config.mjs part 1.

/*
 * For a detailed explanation regarding each configuration property, visit:
 * https://jestjs.io/docs/configuration
 */

export default {
  // All imported modules in your tests should be mocked automatically
  // automock: false,

  // Stop running tests after `n` failures
  // bail: 0,

  // The directory where Jest should store its cached dependency information
  // cacheDirectory: "/private/var/folders/76/n_0g4rp95jd3lq1dj606kkym0000gn/T/jest_dx",

  // Automatically clear mock calls, instances, contexts and results before every test
  // clearMocks: false,

  // Indicates whether the coverage information should be collected while executing the test
  // collectCoverage: false,

  // An array of glob patterns indicating a set of files for which coverage information should be collected
  // collectCoverageFrom: undefined,

  // The directory where Jest should output its coverage files
  // coverageDirectory: undefined,

  // An array of regexp pattern strings used to skip coverage collection
  // coveragePathIgnorePatterns: [
  //   "/node_modules/"
  // ],

  // Indicates which provider should be used to instrument code for coverage
  // coverageProvider: "babel",

  // A list of reporter names that Jest uses when writing coverage reports
  // coverageReporters: [
  //   "json",
  //   "text",
  //   "lcov",
  //   "clover"
  // ],

  // An object that configures minimum threshold enforcement for coverage results
  // coverageThreshold: undefined,

  // A path to a custom dependency extractor
  // dependencyExtractor: undefined,

  // Make calling deprecated APIs throw helpful error messages
  // errorOnDeprecated: false,

  // The default configuration for fake timers
  // fakeTimers: {
  //   "enableGlobally": false
  // },

  // Force coverage collection from ignored files using an array of glob patterns
  // forceCoverageMatch: [],

  // A path to a module which exports an async function that is triggered once before all test suites
  // globalSetup: undefined,

  // A path to a module which exports an async function that is triggered once after all test suites
  // globalTeardown: undefined,

  // A set of global variables that need to be available in all test environments
  // globals: {},

  // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
  // maxWorkers: "50%",

  // An array of directory names to be searched recursively up from the requiring module's location
  // moduleDirectories: [
  //   "node_modules"
  // ],

  // An array of file extensions your modules use
  /*moduleFileExtensions: [
     "js",
     "mjs",
     "cjs",
     "jsx",
     "ts",
     "tsx",
     "json",
     "node"
   ],*/

  // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
  // moduleNameMapper: {},

  // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
  // modulePathIgnorePatterns: [],

  // Activates notifications for test results
  // notify: false,
  • automock (type: boolean , default: false)
더보기
All imported modules in your tests should be mocked automatically

테스트에서 가져온 모든 모듈은 mocked 이 되는 옵션
  • bail (type: number | boolean{0 === false, 1 === true) , default: 0)
더보기
Stop running tests after `n` failures

기본적으로 Jest는 모든 테스트를 수행하고 완료 시 콘솔에 모든 오류를 생성한다. bail 옵션을 사용하면 n번 째 실패 후 테스트 실행을 멈출 수 있는 옵션

  • cacheDirectory (type: String, default: "/tmp/<path>")
더보기
The directory where Jest should store its cached dependency information
 
Jest가 캐시된 종속성 정보를 저장하는 디렉토리를 사용자 지정할 수 있는 옵션
  • clearMocks (type: boolean, default: false)
더보기
Automatically clear mock calls, instances, contexts and results before every test
 
모든 테스트 전에 모의 호출, 인스턴스, 컨텍스트, 결과를 자동으로 지울 수 있는 옵션
  • collectCoverage (type: boolean, default: false)
더보기
Indicates whether the coverage information should be collected while executing the test
 
테스트를 실행하는 동안 커버리지 정보를 수집하는지에 대한 옵션
  • collectCoverageFrom (type: Array, default: undefined)
더보기
An array of glob patterns indicating a set of files for which coverage information should be collected

커버리지 정보를 수집해야 하는 파일 세트를 나타내는 glob 패턴 의 배열입니다 . 파일이 지정된 glob 패턴과 일치하는 경우 이 파일에 대한 테스트가 없고 테스트 제품군에 필요하지 않은 경우에도 해당 파일에 대한 커버리지 정보가 수집하는 옵션
※ collectCoverage 가 true거나 CLI에 Jest --coverage를 호출해야 가능!

  • coverageDirectory (type: String, default: undefined)
더보기
The directory where Jest should output its coverage files

Jest가 해당 커버리지를 출력해야하는 디렉토리를 설정하는 옵션
  • coveragePathIgnorePattern (type: Array<String>, default: "/node_modules/")
더보기
An array of regexp pattern strings used to skip coverage collection
 
커버리지 수집을 건너뛰는 데에 사용하는 정규 표현식 패턴의 배열을 설정하는 옵션
  • coverageProvider (type: string, choose: babel or v8)
더보기
Indicates which provider should be used to instrument code for coverage

커버리지를 위한 코드를 계측하는데에 사용하는 공급자를 설정하는 옵션
  • coverageReporters (type: Array<string | [ string, option ]>, default: ["clover", "json", "lcov", "text"])
더보기
A list of reporter names that Jest uses when writing coverage reports

Jest에서 커버리지의 기록을 작성하는 확장자 명을 설정하는 옵션
  • coverageThreshold (type: object, default: undefined)
더보기
An object that configures minimum threshold enforcement for coverage results

커버리지 결과를 위한 최소 임계값 적용을 구성하는 객체를 설정하는 옵션
  • dependencyExtractor (type: string, default: undefined)
더보기
A path to a custom dependency extractor

사용자 지정 종속성 추출기이고, 이 추출 함수는 코드에서 종속성과 이터러블을 반환해야한다.
추출 기능이 있는 객체를 내보내는 노드 모듈이여야 하고, 그 모듈은 로직이 변경되었고 이에 의존하는 캐시된 아티팩트가 폐기되어야 하는지를 결정하기 위해 캐시 키를 생성하는 getCacheKey 함수를 포함할 수도 있다.
  • errorOnDeprecated (type: boolean, default: false)
더보기
Make calling deprecated APIs throw helpful error messages

더이상 사용하지 않는 API를 호출하면 오류 메세지를 보내는 옵션
  • fakeTimers (type: object, default: {} )
더보기
The default configuration for fake timers

코드 조각이 테스트에서 기다리지 싶지 않은 긴 시간 제한을 설정하는 가짜 타이머에 대한 옵션
  • forceCoverageMatch (type: array<string>, default: [''] )
더보기
Force coverage collection from ignored files using an array of glob patterns

glob 패턴 배열을 사용하여 무시된 파일에서 강제 커버리지를 수집하는 옵션
  • globalSetup (type: string, default: undefined)
더보기
A path to a module which exports an async function that is triggered once before all test suites

모든 테스트 스위트 전에 한번 트리거 되는 동기 또는 비동기 함수를 내보내는 모듈에 대한 경로를 설정하는 옵션
  • globalTeardown (type: string, default: undefined)
더보기
A path to a module which exports an async function that is triggered once after all test suites

모든 테스트 스위트 후에 한 번 트리거 되는 동기 또는 비동기 함수를 내보내는 모듈에 대한 경로를 설정하는 옵션
  • globals (type: object, default: {} )
더보기
A set of global variables that need to be available in all test environments

모든 테스트 환경에서 사용할 수 있어야 하는 전역 변수의 집합을 설정하는 옵션
  • maxWorkers (type: number | string , default: '50%')
더보기
The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.

테스트를 사용하는 최대 작업자의 수를 설정하는 옵션
  • moduleDirectories (type: array<string>, default: ["node_modules"])
더보기
An array of directory names to be searched recursively up from the requiring module's location

필요한 모듈의 위치에서 재귀적으로 검색할 디렉토리 이름의 배열을 설정하는 옵션
  • moduleFileExtensions (type: array<string>, default: ["js", "mjs", "cjs", "jsx", "ts", "tsx", "json", "node"]
더보기
An array of file extensions your modules use

모듈이 사용하는 파일 확장자명의 배열을 설정하는 옵션
  • moduleNameMapper (type: object<string, string | array<string>>, default: null)
더보기
A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module

단일 모듈로 리소스를 제거할 수 있도록 하는 정규식에서 모듈 이름 또는 모듈 이름 배열을 설정하는 옵션
  • modulepathIgnorePattern (type: array<string>, default: [] )
더보기
An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader

모듈 로더에 '보이는' 것으로 간주되기 전에 모든 모듈 경로와 일치하는 정규 표현식 패턴 문자열의 배열을 설정하는 옵션

 

  • notify (type: boolean, default: false)
더보기
An enum that specifies notification mode. Requires { notify: true }

테스트 결과에 대한 기본 OS 알림을 활성화하는 옵션
알림을 표시하려면 Jest가 추가로 설치해야 하는 node-notifier 패키지가 필요함

 

 

glob 패턴은 뭘까...?

다음 시간에...

 

출처: https://jestjs.io/docs/configuration

 

Configuring Jest · Jest

The Jest philosophy is to work great by default, but sometimes you just need more configuration power.

jestjs.io

 

반응형