@kodeme-io/next-core-testing
Version:
Testing utilities and helpers for next-core applications
90 lines (75 loc) • 2.11 kB
JavaScript
/**
* Base Jest Configuration for next-core Applications
*
* All demo apps should extend this configuration for consistency
*
* @example
* In your app's jest.config.js:
* ```js
* const baseConfig = require('@kodeme-io/next-core-testing/jest-config')
*
* module.exports = {
* ...baseConfig,
* // Your app-specific overrides here
* }
* ```
*/
const nextJest = require('next/jest')
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})
// Add any custom config to be passed to Jest
const customJestConfig = {
// Setup files to run before tests
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// Test environment
testEnvironment: 'jest-environment-jsdom',
// Module path aliases (adjust these to match your tsconfig.json)
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^@next-core/(.*)$': '<rootDir>/../../packages/$1/src',
},
// Coverage configuration
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'!src/**/*.d.ts',
'!src/**/*.stories.{js,jsx,ts,tsx}',
'!src/**/__tests__/**',
],
// Test match patterns
testMatch: [
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
],
// Transform configuration
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['@swc/jest', {
jsc: {
transform: {
react: {
runtime: 'automatic',
},
},
},
}],
},
// Module file extensions
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
// Ignore patterns
testPathIgnorePatterns: [
'<rootDir>/.next/',
'<rootDir>/node_modules/',
],
// Transform ignore patterns
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
// Roots
roots: ['<rootDir>/src'],
// Verbose output
verbose: true,
}
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)