Nx plugin for Jest testing with executors, generators, and configuration utilities for monorepo testing workflows.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Nx plugin infrastructure for automatic Jest project detection and configuration inference. The plugin system enables Nx to automatically discover Jest configurations and create appropriate build targets without manual configuration.
Functions for creating Nx plugin nodes that automatically detect and configure Jest projects.
/**
* Create nodes for Jest plugin (v1 API)
* @param configFilePath - Path to Jest configuration file
* @param options - Plugin configuration options
* @param context - Nx plugin creation context
* @returns Plugin node creation result
*/
function createNodes(
configFilePath: string,
options: JestPluginOptions | undefined,
context: CreateNodesContext
): CreateNodesResult;
/**
* Create nodes for Jest plugin (v2 API with enhanced performance)
* @param configFilePath - Path to Jest configuration file
* @param options - Plugin configuration options
* @param context - Enhanced plugin creation context
* @returns Promise resolving to plugin node creation result
*/
function createNodesV2(
configFilePath: string,
options: JestPluginOptions | undefined,
context: CreateNodesContextV2
): Promise<CreateNodesResult>;Configuration interface for customizing Jest plugin behavior.
interface JestPluginOptions {
/** Name of the primary test target (default: 'test') */
targetName?: string;
/** Name of the CI-optimized test target (default: 'test-ci') */
ciTargetName?: string;
/** Name for grouping atomized tasks on CI */
ciGroupName?: string;
/**
* Disable jest-config and jest-runtime for faster but potentially less accurate configuration loading
* @default false
*/
disableJestRuntime?: boolean;
}Usage Examples:
// nx.json plugin configuration
{
"plugins": [
{
"plugin": "@nx/jest/plugin",
"options": {
"targetName": "test",
"ciTargetName": "test-ci",
"ciGroupName": "jest-tests"
}
}
]
}Context objects provided to plugin node creation functions.
interface CreateNodesContext {
/** Workspace root directory */
workspaceRoot: string;
/** Configuration file being processed */
configFiles: string[];
/** Nx.json configuration */
nxJsonConfiguration: NxJsonConfiguration;
}
interface CreateNodesContextV2 extends CreateNodesContext {
/** Enhanced context with additional metadata */
readonly configFiles: readonly string[];
/** Plugin-specific cache directory */
cacheDir: string;
}
interface CreateNodesResult {
/** Map of project names to their configurations */
projects?: Record<string, ProjectConfiguration>;
/** External node dependencies */
externalNodes?: Record<string, ProjectConfiguration>;
}The Jest plugin is automatically registered when added to nx.json:
{
"plugins": [
"@nx/jest/plugin"
]
}Or with custom options:
{
"plugins": [
{
"plugin": "@nx/jest/plugin",
"options": {
"targetName": "test",
"ciTargetName": "ci-test",
"disableJestRuntime": false
}
}
]
}The plugin automatically detects Jest projects by searching for configuration files:
jest.config.jsjest.config.tsjest.config.mjsjest.config.cjsjest.config.jsonConfiguration File Processing:
// The plugin processes Jest configuration files like:
export default {
displayName: 'my-lib',
preset: '../../jest.preset.js',
testEnvironment: 'node',
coverageDirectory: '../../coverage/libs/my-lib',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
};The plugin automatically generates test targets for detected Jest projects:
{
"name": "my-lib",
"targets": {
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/my-lib/jest.config.ts",
"passWithNoTests": true
}
},
"test-ci": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/my-lib/jest.config.ts",
"ci": true,
"codeCoverage": true
}
}
}
}The plugin infers configuration from Jest config files:
testEnvironment settingtestMatch and testPathIgnorePatternsmoduleNameMapper and resolver settingstransform configurationExample Inference:
// From jest.config.ts:
export default {
testEnvironment: 'jsdom',
coverageDirectory: '../../coverage/apps/my-app',
testMatch: ['<rootDir>/src/**/*.spec.ts'],
};
// Plugin generates:
{
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/my-app/jest.config.ts"
},
"outputs": ["{workspaceRoot}/coverage/apps/my-app"]
}
}The plugin includes several performance optimizations:
Runtime Optimization:
// When disableJestRuntime is true, the plugin uses faster but simpler config parsing
{
"plugin": "@nx/jest/plugin",
"options": {
"disableJestRuntime": true // Faster but potentially less accurate
}
}The plugin handles monorepo setups with multiple Jest projects:
// Root jest.config.ts for multi-project setup
export default {
projects: [
'<rootDir>/apps/*/jest.config.ts',
'<rootDir>/libs/*/jest.config.ts'
]
};The plugin creates individual targets for each discovered project while maintaining the multi-project relationship.
The plugin includes comprehensive error handling:
The plugin integrates with core Nx features:
Install with Tessl CLI
npx tessl i tessl/npm-nx--jest