next-jest-boost
A CLI tool to automatically setup Jest + Testing Library for Next.js projects, supporting JavaScript and TypeScript, and npm, yarn, pnpm package managers.
A CLI tool to automatically setup Jest + Testing Library for Next.js projects, supporting JavaScript and TypeScript, and npm, yarn, pnpm package managers.
- Detects Next.js projects
- Detects TypeScript usage
- Detects package manager (npm, yarn, pnpm)
- Installs required dependencies
- Generates
jest.config.js
,jest.setup.ts/js
, andbabel.config.js
- Provides friendly CLI logs
After installing with:
npm install -D next-jest-boost
or
npx next-jest-boost
npm install -g next-jest-boost
or
yarn global add next-jest-boost
or
pnpm add -g next-jest-boost
npx next-jest-boost
✅ Detect the project type (JavaScript or TypeScript)
✅ Install all required packages:
jest, @testing-library/react, @testing-library/jest-dom, jest-environment-jsdom, etc.
✅ Create necessary files:
jest.config.js
jest.setup.js or jest.setup.ts
babel.config.js (if needed)
jest.config.js
const nextJest = require('next/jest');
const createJestConfig = nextJest({ dir: './' });
const customJestConfig = {
testEnvironment: 'jest-environment-jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'], // or .js depending on the project
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
};
module.exports = createJestConfig(customJestConfig);
jest.setup.ts or jest.setup.js
import 'jest-environment-jsdom';
import '@testing-library/jest-dom';
babel.config.js
module.exports = {
presets: ['next/babel'],
};
You can now write your tests like this:
Example.test.tsx
import { render, screen } from '@testing-library/react';
import Home from '../pages/index';
describe('Home', () => {
it('renders the heading', () => {
render(<Home />);
expect(screen.getByRole('heading', { name: /welcome/i })).toBeInTheDocument();
});
});
Pull requests are welcome! To contribute:
git clone https://github.com/costa-everton/next-jest-boost.git
cd next-jest-boost
yarn install
yarn link
Now the next-jest-boost command will be available locally for testing.
- Node.js >= 12
- Next.js project
MIT © Everton Costa