Files

63 lines
2.7 KiB
JavaScript

const path = require('path')
const fs = require('fs')
// Set environment variables before modules are loaded
if (!process.env.NEXT_PUBLIC_APP_VERSION || !process.env.NEXT_PUBLIC_APP_HOMEPAGE) {
const packageJsonPath = path.join(__dirname, 'package.json')
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
process.env.NEXT_PUBLIC_APP_VERSION = process.env.NEXT_PUBLIC_APP_VERSION || packageJson.version
process.env.NEXT_PUBLIC_APP_HOMEPAGE = process.env.NEXT_PUBLIC_APP_HOMEPAGE || packageJson.homepage
}
const nextJest = require('next/jest')
const createJestConfig = nextJest({
// Absolute path so this resolves correctly even when invoked from a different cwd (e.g. knip running from the repo root)
dir: __dirname,
})
// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
'^@/(.*)$': '<rootDir>/src/$1',
'^react-dom$': '<rootDir>/../../node_modules/react-dom',
'^react-dom/client$': '<rootDir>/../../node_modules/react-dom/client',
'^.+\\.(svg)$': '<rootDir>/mocks/svg.js',
'^.+/markdown/terms/terms\\.md$': '<rootDir>/mocks/terms.md.js',
isows: '<rootDir>/node_modules/isows/_cjs/index.js',
'^@safe-global/utils/(.*)$': '<rootDir>/../../packages/utils/src/$1',
'^@safe-global/store/(.*)$': '<rootDir>/../../packages/store/src/$1',
},
// https://github.com/mswjs/jest-fixed-jsdom
// without this environment it is basically impossible to run tests with msw
testEnvironment: 'jest-fixed-jsdom',
testEnvironmentOptions: {
url: 'http://localhost/balances?safe=rin:0xb3b83bf204C458B461de9B0CD2739DB152b4fa5A',
// https://github.com/mswjs/msw/issues/1786#issuecomment-2426900455
// without this line 4 tests related to firefox fail
customExportConditions: ['node'],
},
coveragePathIgnorePatterns: ['/node_modules/', '/src/tests/', '/src/types/contracts/'],
coverageThreshold: {
global: {
branches: 56,
functions: 62,
lines: 78,
statements: 76,
},
},
// Exclude storybook snapshot tests and Playwright e2e specs from main test run - they have their own CI workflows
testPathIgnorePatterns: ['/node_modules/', '/.next/', '/e2e/', '\\.stories\\.test\\.tsx$'],
}
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = async () => ({
...(await createJestConfig(customJestConfig)()),
transformIgnorePatterns: [
'node_modules/(?!(uint8arrays|multiformats|@web3-onboard/common|@walletconnect/(.*)/uint8arrays|@storybook|storybook)/)',
],
})