npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dbarrett24/jest-config

v1.0.2

Published

Shared Jest configuration for React/Next.js applications

Readme

@dbarrett24/jest-config

Shared Jest configuration for React/Next.js applications in the monorepo.

Features

  • Fast test execution with @swc/jest (20-30x faster than babel-jest)
  • Automatic JSX runtime (no React imports needed)
  • jsdom environment for React component testing
  • Coverage thresholds (90% for apps)
  • Path alias support (@/* mapped to src/*)
  • Asset mocking (CSS, images)

Usage

In Your Package

  1. Install the config:

    {
      "devDependencies": {
        "@dbarrett24/jest-config": "workspace:*",
        "jest": "^29.7.0"
      }
    }
  2. Create jest.config.js:

    module.exports = require('@dbarrett24/jest-config');
  3. Create test setup file at testing/setupTests.ts:

    import '@testing-library/jest-dom';
  4. Add test scripts to package.json:

    {
      "scripts": {
        "test": "jest",
        "test:watch": "jest --watch",
        "test:coverage": "jest --coverage"
      }
    }

Extending the Configuration

If you need to customize the config:

const baseConfig = require('@dbarrett24/jest-config');

module.exports = {
    ...baseConfig,
    displayName: 'my-app',
    // Add your overrides here
    testPathIgnorePatterns: [
        ...baseConfig.testPathIgnorePatterns,
        '/custom-folder/',
    ],
};

Configuration Details

Test Environment

  • Environment: jsdom (for React/DOM testing)
  • Setup: Loads testing/setupTests.ts after environment setup

Coverage Thresholds

  • Statements: 90%
  • Branches: 90%
  • Functions: 90%
  • Lines: 90%

Path Aliases

  • @/*<rootDir>/src/*

Asset Mocking

  • CSS files → testing/__mocks__/styleMock.js
  • Images → testing/__mocks__/fileMock.js

File Transform

Uses @swc/jest with automatic JSX runtime:

transform: {
    '^.+\\.(t|j)sx?$': [
        '@swc/jest',
        {
            jsc: {
                transform: {
                    react: {
                        runtime: 'automatic', // No React imports needed!
                    },
                },
            },
        },
    ],
}

Library Configuration

For component libraries, use @dbarrett24/jest-config-library instead. It extends this config with:

  • Higher coverage thresholds (95%)
  • Additional ignore patterns for Storybook
  • Library-specific display name

Testing Patterns

Component Tests

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MyComponent } from './MyComponent';

describe('MyComponent', () => {
    it('renders correctly', () => {
        render(<MyComponent title="Hello" />);
        expect(screen.getByText('Hello')).toBeVisible();
    });

    it('handles click events', async () => {
        const handleClick = jest.fn();
        render(<MyComponent onClick={handleClick} />);
        
        await userEvent.click(screen.getByRole('button'));
        expect(handleClick).toHaveBeenCalledTimes(1);
    });
});

No React Imports Needed

Thanks to @swc/jest with automatic JSX runtime:

// ✅ CORRECT - No React import
import { render } from '@testing-library/react';
import { Button } from './Button';

// ❌ WRONG - Don't import React
import React from 'react';

Troubleshooting

"React is not defined" error

If you see this error, your @swc/jest transform is not configured correctly. Ensure your jest.config.js includes the react.runtime: 'automatic' setting.

Coverage thresholds not enforced

Make sure you're running jest --coverage to enable coverage checks.

Path aliases not working

Verify your tsconfig.json has matching path mappings:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

Performance

@swc/jest vs babel-jest:

  • ✅ 20-30x faster test execution
  • ✅ No Babel dependencies required
  • ✅ Rust-based transpilation
  • ✅ Native TypeScript & JSX support

Related Packages

  • @dbarrett24/jest-config-library - For component libraries (95% coverage)
  • @dbarrett24/testing-utils - Shared test utilities and mocks
  • @dbarrett24/typescript-config - TypeScript configurations

Migration from babel-jest

If migrating from an older setup with babel-jest:

  1. Remove Babel dependencies:

    pnpm remove babel-jest @babel/preset-env @babel/preset-react @babel/preset-typescript
  2. Install @swc packages (already in this config):

    pnpm install
  3. Remove React imports from component files:

    // Before
    import React from 'react';
       
    // After
    // (remove the import)
  4. Run tests to verify:

    pnpm test

License

MIT