or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

config-management.mdindex.mdmulti-project.mdplugin-system.mdpreset-config.mdproject-configuration.mdtest-execution.md
tile.json

tessl/npm-nx--jest

Nx plugin for Jest testing with executors, generators, and configuration utilities for monorepo testing workflows.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@nx/jest@21.4.x

To install, run

npx @tessl/cli install tessl/npm-nx--jest@21.4.0

index.mddocs/

Nx Jest Plugin

The Nx Jest Plugin provides comprehensive Jest testing capabilities for Nx monorepos, including test executors, configuration generators, and plugin infrastructure. It enables advanced features like affected testing, test parallelization, and intelligent caching within the Nx ecosystem.

Package Information

  • Package Name: @nx/jest
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @nx/jest

Core Imports

import { 
  configurationGenerator, 
  jestInitGenerator,
  addPropertyToJestConfig,
  removePropertyFromJestConfig,
  jestConfigObjectAst,
  getJestProjectsAsync
} from "@nx/jest";

For CommonJS:

const { 
  configurationGenerator, 
  jestInitGenerator,
  addPropertyToJestConfig,
  removePropertyFromJestConfig,
  jestConfigObjectAst,
  getJestProjectsAsync
} = require("@nx/jest");

Plugin and preset imports:

import { createNodes, createNodesV2, JestPluginOptions } from "@nx/jest/plugin";
import { nxPreset } from "@nx/jest/preset";

Basic Usage

import { configurationGenerator, jestInitGenerator } from "@nx/jest";
import { Tree } from '@nx/devkit';

// Initialize Jest in workspace
await jestInitGenerator(tree, {
  skipFormat: false,
  addPlugin: true
});

// Add Jest configuration to specific project
await configurationGenerator(tree, {
  project: "my-project",
  testEnvironment: "jsdom",
  supportTsx: true
});

Architecture

The Nx Jest Plugin is structured around several key components:

  • Executors: Test runner implementation with batch execution support
  • Generators: Project setup, initialization, and configuration tools
  • Plugin System: Nx plugin infrastructure for automatic project detection and configuration
  • Configuration Utilities: Tools for programmatically managing Jest config files
  • Preset System: Pre-configured Jest settings optimized for Nx workspaces

Capabilities

Test Execution

Jest test runner executor with support for batch execution, affected testing, and Nx-specific optimizations.

interface JestExecutorOptions {
  codeCoverage?: boolean;
  config?: string;
  detectOpenHandles?: boolean;
  logHeapUsage?: boolean;
  detectLeaks?: boolean;
  jestConfig: string;
  testFile?: string;
  bail?: boolean | number;
  ci?: boolean;
  color?: boolean;
  clearCache?: boolean;
  findRelatedTests?: string;
  forceExit?: boolean;
  json?: boolean;
  maxWorkers?: number | string;
  onlyChanged?: boolean;
  changedSince?: string;
  outputFile?: string;
  passWithNoTests?: boolean;
  randomize?: boolean;
  runInBand?: boolean;
  showConfig?: boolean;
  silent?: boolean;
  testNamePattern?: string;
  testPathIgnorePatterns?: string[];
  testPathPatterns?: string[];
  colors?: boolean;
  reporters?: string[];
  verbose?: boolean;
  coverageReporters?: string[];
  coverageDirectory?: string;
  testResultsProcessor?: string;
  updateSnapshot?: boolean;
  useStderr?: boolean;
  watch?: boolean;
  watchAll?: boolean;
  testLocationInResults?: boolean;
  testTimeout?: number;
  setupFile?: string; // @deprecated
}

Test Execution

Project Configuration

Generators for initializing Jest in workspaces and adding Jest configuration to individual projects.

function configurationGenerator(
  tree: Tree, 
  options: JestProjectSchema
): Promise<GeneratorCallback>;

function jestInitGenerator(
  tree: Tree, 
  options: JestInitSchema
): Promise<GeneratorCallback>;

interface JestProjectSchema {
  project: string;
  targetName?: string;
  supportTsx?: boolean;
  setupFile?: 'angular' | 'web-components' | 'react-native' | 'react-router' | 'none';
  skipSerializers?: boolean;
  testEnvironment?: 'node' | 'jsdom' | 'none';
  skipFormat?: boolean;
  addPlugin?: boolean;
  compiler?: 'tsc' | 'babel' | 'swc';
  skipPackageJson?: boolean;
  js?: boolean;
  runtimeTsconfigFileName?: string;
  addExplicitTargets?: boolean;
  babelJest?: boolean; // @deprecated
  skipSetupFile?: boolean; // @deprecated
  keepExistingVersions?: boolean;
}

interface JestInitSchema {
  skipFormat?: boolean;
  skipPackageJson?: boolean;
  keepExistingVersions?: boolean;
  updatePackageScripts?: boolean;
  addPlugin?: boolean;
}

Project Configuration

Configuration Management

Utilities for programmatically modifying Jest configuration files with AST-based manipulation.

function addPropertyToJestConfig(
  host: Tree,
  path: string,
  propertyName: string | string[],
  value: unknown,
  options?: { valueAsString: boolean }
): void;

function removePropertyFromJestConfig(
  host: Tree,
  path: string,
  propertyName: string | string[]
): void;

function jestConfigObjectAst(configString: string): ts.ObjectLiteralExpression;

Configuration Management

Plugin System

Nx plugin infrastructure for automatic Jest project detection and configuration inference.

interface JestPluginOptions {
  targetName?: string;
  ciTargetName?: string;
  ciGroupName?: string;
  disableJestRuntime?: boolean;
}

function createNodes(
  configFilePath: string,
  options: JestPluginOptions | undefined,
  context: CreateNodesContext
): CreateNodesResult;

function createNodesV2(
  configFilePath: string,
  options: JestPluginOptions | undefined,
  context: CreateNodesContextV2
): Promise<CreateNodesResult>;

Plugin System

Multi-Project Support

Utilities for working with Jest multi-project configurations in Nx workspaces.

function getJestProjectsAsync(): Promise<string[]>;

Multi-Project Support

Preset Configuration

Pre-configured Jest settings optimized for Nx workspaces with TypeScript support.

interface NxJestPreset {
  testMatch: string[];
  resolver: string;
  moduleFileExtensions: string[];
  coverageReporters: string[];
  transform: Record<string, [string, any]>;
  testEnvironment: string;
  testEnvironmentOptions: {
    customExportConditions: string[];
  };
}

const nxPreset: NxJestPreset;

Preset Configuration

Types

Core Type Definitions

interface Tree {
  // Nx Tree interface for file system operations
}

interface GeneratorCallback {
  // Function returned by generators for post-execution tasks
  (): Promise<void> | void;
}

interface ExecutorContext {
  // Nx executor context with project and workspace information
}

interface CreateNodesContext {
  // Context for plugin node creation
}

interface CreateNodesContextV2 {
  // Enhanced context for plugin node creation v2
}

interface CreateNodesResult {
  // Result object for created plugin nodes
}

type NormalizedJestProjectSchema = JestProjectSchema & {
  rootProject: boolean;
  isTsSolutionSetup: boolean;
};