xiaohongshu
xiaohongshu
jest-config-generator
Generate Jest configuration files for JavaScript/TypeScript testing with coverage, mocking, and environment-specific settings. Triggers on "create jest config", "generate jest.config", "jest configuration for", "testing config".
Full skill instructions
Generate optimized Jest configuration files for JavaScript and TypeScript testing projects.
File Output: jest.config.js, jest.config.ts, or jest.config.json
Format: JavaScript module (ESM or CJS) or JSON
Compatibility: Jest 29.x
Immediately generate a complete Jest configuration appropriate for the project type. Include sensible defaults for coverage, transforms, and module resolution.
// jest.config.js
/** @type {import('jest').Config} */
const config = {
// Test environment
testEnvironment: 'node',
// File extensions
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
// Transform TypeScript files
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
isolatedModules: true,
},
],
},
// Test file patterns
testMatch: [
'**/__tests__/**/*.+(ts|tsx|js)',
'**/?(*.)+(spec|test).+(ts|tsx|js)',
],
// Ignore patterns
testPathIgnorePatterns: [
'/node_modules/',
'/dist/',
'/build/',
],
// Module path aliases (match tsconfig paths)
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^@utils/(.*)$': '<rootDir>/src/utils/$1',
'^@models/(.*)$': '<rootDir>/src/models/$1',
},
// Setup files
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
// Coverage configuration
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
'!src/**/index.ts',
'!src/**/*.stories.{ts,tsx}',
'!src/types/**/*',
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
// Performance
maxWorkers: '50%',
cache: true,
cacheDirectory: '<rootDir>/.jest-cache',
// Timeouts
testTimeout: 10000,
// Clear mocks between tests
clearMocks: true,
restoreMocks: true,
// Verbose output
verbose: true,
};
module.exports = config;
// jest.config.js
/** @type {import('jest').Config} */
const config = {
// Use jsdom for DOM testing
testEnvironment: 'jsdom',
// Setup files
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
// Transform
transform: {
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
isolatedModules: true,
},
],
'^.+\\.(js|jsx)$': 'babel-jest',
},
// Module resolution
moduleNameMapper: {
// Handle CSS imports
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
// Handle image imports
'\\.(jpg|jpeg|png|gif|svg|webp)$': '<rootDir>/__mocks__/fileMock.js',
// Path aliases
'^@/(.*)$': '<rootDir>/src/$1',
'^@components/(.*)$': '<rootDir>/src/components/$1',
'^@hooks/(.*)$': '<rootDir>/src/hooks/$1',
'^@utils/(.*)$': '<rootDir>/src/utils/$1',
},
// Test patterns
testMatch: [
'<rootDir>/src/**/__tests__/**/*.{ts,tsx}',
'<rootDir>/src/**/*.{spec,test}.{ts,tsx}',
],
// Ignore
testPathIgnorePatterns: [
'/node_modules/',
'/dist/',
'/.next/',
],
// Transform ignore
transformIgnorePatterns: [
'/node_modules/(?!(uuid|other-esm-package)/)',
],
// Coverage
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
'!src/**/*.stories.{ts,tsx}',
'!src/main.tsx',
'!src/vite-env.d.ts',
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
// Mock behavior
clearMocks: true,
restoreMocks: true,
// Globals
globals: {
'ts-jest': {
isolatedModules: true,
},
},
};
module.exports = config;
// jest.config.js
const nextJest = require('next/jest');
const createJestConfig = nextJest({
// Path to Next.js app
dir: './',
});
/** @type {import('jest').Config} */
const customConfig = {
// Test environment
testEnvironment: 'jest-environment-jsdom',
// Setup files
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
// Module aliases (synced with tsconfig.json)
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^@components/(.*)$': '<rootDir>/src/components/$1',
'^@lib/(.*)$': '<rootDir>/src/lib/$1',
'^@hooks/(.*)$': '<rootDir>/src/hooks/$1',
},
// Test patterns
testMatch: [
'**/__tests__/**/*.[jt]s?(x)',
'**/?(*.)+(spec|test).[jt]s?(x)',
],
// Ignore
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/.next/',
'<rootDir>/e2e/',
],
// Coverage
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'!src/**/*.d.ts',
'!src/**/*.stories.{js,jsx,ts,tsx}',
'!src/app/layout.tsx',
'!src/app/providers.tsx',
],
// Module directories
moduleDirectories: ['node_modules', '<rootDir>/'],
};
module.exports = createJestConfig(customConfig);
// jest.config.js
/** @type {import('jest').Config} */
const config = {
preset: 'ts-jest',
testEnvironment: 'node',
// Root directory
roots: ['<rootDir>/src', '<rootDir>/tests'],
// Transform
transform: {
'^.+\\.ts$': ['ts-jest', { tsconfig: 'tsconfig.json' }],
},
// Test patterns
testMatch: [
'**/tests/**/*.test.ts',
'**/tests/**/*.spec.ts',
'**/__tests__/**/*.ts',
],
// Path mapping
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^@controllers/(.*)$': '<rootDir>/src/controllers/$1',
'^@models/(.*)$': '<rootDir>/src/models/$1',
'^@services/(.*)$': '<rootDir>/src/services/$1',
'^@middleware/(.*)$': '<rootDir>/src/middleware/$1',
'^@utils/(.*)$': '<rootDir>/src/utils/$1',
},
// Setup
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
globalSetup: '<rootDir>/tests/globalSetup.ts',
globalTeardown: '<rootDir>/tests/globalTeardown.ts',
// Coverage
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/index.ts',
'!src/types/**/*',
'!src/migrations/**/*',
],
coverageThreshold: {
global: {
branches: 70,
functions: 80,
lines: 80,
statements: 80,
},
},
// Test isolation
clearMocks: true,
restoreMocks: true,
resetModules: true,
// Timeouts (longer for integration tests)
testTimeout: 30000,
// Force exit after tests complete
forceExit: true,
detectOpenHandles: true,
// Verbose
verbose: true,
};
module.exports = config;
// jest.config.js (root)
/** @type {import('jest').Config} */
const config = {
// Use projects for monorepo
projects: [
'<rootDir>/packages/*/jest.config.js',
'<rootDir>/apps/*/jest.config.js',
],
// Root coverage
collectCoverage: true,
coverageDirectory: '<rootDir>/coverage',
coverageReporters: ['text', 'lcov', 'json-summary'],
// Merge coverage from all projects
collectCoverageFrom: [
'packages/*/src/**/*.{ts,tsx}',
'apps/*/src/**/*.{ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
],
};
module.exports = config;
// packages/shared/jest.config.js
/** @type {import('jest').Config} */
const config = {
displayName: 'shared',
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: '.',
testMatch: ['<rootDir>/src/**/*.test.ts'],
moduleNameMapper: {
'^@shared/(.*)$': '<rootDir>/src/$1',
},
// Use root tsconfig
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{ tsconfig: '<rootDir>/tsconfig.json' },
],
},
};
module.exports = config;
// jest.setup.ts
import '@testing-library/jest-dom';
// Mock IntersectionObserver
global.IntersectionObserver = class IntersectionObserver {
constructor() {}
observe() { return null; }
unobserve() { return null; }
disconnect() { return null; }
} as any;
// Mock ResizeObserver
global.ResizeObserver = class ResizeObserver {
constructor() {}
observe() { return null; }
unobserve() { return null; }
disconnect() { return null; }
} as any;
// Mock matchMedia
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
// tests/setup.ts
import { prisma } from '@/lib/prisma';
// Clean up after each test
afterEach(async () => {
jest.clearAllMocks();
});
// Close database connection after all tests
afterAll(async () => {
await prisma.$disconnect();
});
// __mocks__/fileMock.js
module.exports = 'test-file-stub';
// __mocks__/styleMock.js
module.exports = {};
Before outputting, verify:
testEnvironment (node vs jsdom)Prompt: "Create Jest config for a TypeScript Node.js API"
Output: Complete jest.config.js with ts-jest, coverage, path aliases.
Prompt: "Generate Jest configuration for React Testing Library"
Output: Complete jest.config.js with jsdom, RTL setup, CSS mocks.
Prompt: "Jest config for Next.js 14 with App Router"
Output: Complete jest.config.js using next/jest with proper setup.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience