Created
April 19, 2022 16:56
-
-
Save ivanoats/ce28c8e05fc2a85c2d8a41fcbb9feb39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Config } from '@jest/types'; | |
import nextJest from '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: Config.InitialOptions = { | |
collectCoverageFrom: [ | |
'**/*.{js,jsx,ts,tsx}', | |
'!**/*.d.ts', | |
'!**/node_modules/**', | |
], | |
coveragePathIgnorePatterns: ['/node_modules/'], | |
// extensionsToTreatAsEsm: ['.ts'], | |
globals: { | |
'ts-jest': { | |
useESM: true, | |
}, | |
}, | |
testMatch: ['tests/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'], | |
roots: ['<rootDir>/src', '<rootDir>/tests'], | |
preset: 'ts-jest', | |
transform: { | |
'^.+\\.(js|jsx|ts|tsx)$': [ | |
'ts-jest', | |
{ presets: ['next/babel', '@babel/preset-typescript'] }, | |
], | |
}, | |
transformIgnorePatterns: [ | |
'/node_modules/', | |
'^.+\\.module\\.(css|sass|scss)$', | |
], | |
testEnvironment: 'jsdom', | |
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'], | |
moduleDirectories: ['node_modules', 'src'], | |
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node', 'cjs'], | |
modulePaths: ['<rootDir>'], | |
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | |
moduleNameMapper: { | |
// Handle module aliases (this will be automatically configured for you soon) | |
'^@/components/(.*)$': '<rootDir>/components/$1', | |
'\\.(scss|sass|css)$': 'identity-obj-proxy', | |
'^(\\.{1,2}/.*)\\.js$': '$1', | |
'^@/pages/(.*)$': '<rootDir>/pages/$1', | |
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs', | |
}, | |
verbose: true, | |
}; | |
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async | |
export default createJestConfig(customJestConfig); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment