mirror of
https://github.com/luxfi/safe-wallet.git
synced 2026-10-30 15:19:21 +00:00
Add global coverage thresholds to jest.config.cjs to prevent test coverage from regressing. Thresholds are set slightly below current levels (branches: 56%, functions: 62%, lines: 78%, statements: 76%) so they can be ratcheted up over time. Co-authored-by: Hanzo Dev <[email protected]>
63 lines
2.6 KiB
JavaScript
63 lines
2.6 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({
|
|
// 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 = {
|
|
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 from main test run - they have their own CI workflow
|
|
testPathIgnorePatterns: ['/node_modules/', '/.next/', '\\.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)/)',
|
|
],
|
|
})
|