1. @html-validate/jest-config
Jest sharable preset used by the various HTML-validate packages
@html-validate/jest-config
Package: @html-validate/jest-config
Created by: html-validate
Last modified: Fri, 05 Apr 2024 23:19:27 GMT
Version: 3.10.0
License: MIT
Downloads: 10,890
Repository: git+https://gitlab.com/html-validate/jest-config.git

Install

npm install @html-validate/jest-config
yarn add @html-validate/jest-config

@html-validate/jest-config

HTML-Validate jest preset.

Jest is configured to:

  • Run tests from *.spec.[jt]s.
  • Collect coverage from .js and .ts in src and ignore tests (**/*.spec.[jt]s) and index (**/index.[jt]s).
  • Report results as junit in temp/jest.xml.
  • Transform typescript with ts-jest.
  • Transform js with babel-jest if babel is detected.
  • Ignores spec-files from Cypress.

Install

npm install --save-dev @html-validate/jest-config

Usage

In your package.json file:

 {
  "jest": {
    "preset": "@html-validate/jest-config"
  }
}

Presets

Preset Description
@html-validate/jest-config Alias for presets/default
@html-validate/jest-config/presets/default Default preset
@html-validate/jest-config/presets/esm Experimental ESM support

Transpiling ESM in node_modules/

If you need to import and use ESM-only libraries you need to install @babel/core. You do not need a babel.config.jsor.babelrcas the preset passes the required configuration directly tobabel-jest`.

npm install --save-dev @babel/core

When babel is detect the preset sets transformIgnorePatterns to transpile everything under node_modules.
You can include a more specific list of packages to transform (potential speed gain) by manually setting transformIgnorePatterns:

Optionally you can set transformIgnorePatterns in package.json:

  {
   "jest": {
     "preset": "@html-validate/jest-config",
+    "transformIgnorePatterns": ["node_modules/(?!(foo|bar|baz)/)"]
   }
 }

This will transform only the foo, bar and baz packages.

Importing HTML as string

Importing *.html is supported by jest configuration but requires additional typescript config by creating a declaration:

shim-html.d.ts:

 declare module "*.html" {
  const value: string;
  export default value;
}

tsconfig.json

This preset searches the project folder for typescript configuration in the following order:

  1. tsconfig.jest.json
  2. tsconfig.json

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code