Skip to content

Latest commit

 

History

History
93 lines (68 loc) · 2.33 KB

jest.md

File metadata and controls

93 lines (68 loc) · 2.33 KB

Jest

Design

package.json (Design)

{
  "scripts": {
    "test": "jest --config .jestrc.json --passWithNoTests"
  },
  "devDependencies": {
    "@jest/globals": "x.x.x",
    "@types/jest": "x.x.x",
    "jest": "x.x.x",
    "jest-extended": "x.x.x",
    "jest-when": "x.x.x",
    "ts-jest": "x.x.x"
  }
}

jest coverageProvider (Design)

.jestrc.json

{
  "coverageProvider": "v8"
}

jest coverageReporters (Design)

.jestrc.json

{
  "coverageReporters": ["lcov", "text"]
}

ts-jest diagnostics (Design)

.jestrc.json

{
  "transform": {
    "^.+\\.m?[jt]sx?$": [
      "ts-jest",
      {
        "diagnostics": {
          "warnOnly": true
        }
      }
    ]
  }
}

Rationale

package.json (Rationale)

Jest supports configuration defined either in package.json or in a jest.config.js file by default. To keep dependency specific configuration out of the way, it should be kept in its own file. The default jest.config.js means the configuration is stored as code, but this is unnecessary. To minimise complexity, store it as a data object following standard naming conventions, .jestrc.json. Pass this file when executing jest.

Explicitly import Jest methods from @jest/globals. Follow ES Module syntax for consistency and allow smoother migration in the future. Avoid relying on "magic" globals. IDE-agnostic solution.

jest coverageProvider (Rationale)

V8's built-in code coverage is faster and less memory-intensive than the default babel-plugin-istanbul.

Jest introduced the ability to configure coverageProvider in version 25.

jest coverageReporters (Rationale)

The default coverage reporters include a lot of outputs which may not be needed.

Restricting reporters to lcov (which also includes html) and text (to output to the console) based on istanbul's reporters.

ts-jest diagnostics (Rationale)

Report diagnostics, but don't block compilation during development.

ts-jest Diagnostics