Add test environment configuration and update Jest setup

- Created `.env.test.example` with test environment variables
- Updated `jest.config.cjs` to simplify configuration and improve test setup
- Added `jest.setup.ts` to load and configure test environment variables
- Updated test files to use dynamic test environment configuration
- Enhanced README.md with additional configuration details for testing
This commit is contained in:
jango-blockchained
2025-01-30 09:56:19 +01:00
parent b3fa5f729e
commit 3115c41e87
5 changed files with 362 additions and 42 deletions

View File

@@ -1,9 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest/presets/default-esm',
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
extensionsToTreatAsEsm: ['.ts', '.tsx'],
setupFiles: ['./jest.setup.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
'#(.*)': '<rootDir>/node_modules/$1',
@@ -13,20 +12,15 @@ module.exports = {
'#supports-color': '<rootDir>/node_modules/supports-color/index.js'
},
transform: {
'^.+\\.(ts|tsx|js|jsx)$': [
'ts-jest',
{
useESM: true,
tsconfig: 'tsconfig.json'
},
],
'^.+\\.tsx?$': ['ts-jest', {
useESM: true,
}],
},
transformIgnorePatterns: [
'node_modules/(?!(@digital-alchemy|chalk|#ansi-styles|#supports-color)/)'
],
resolver: '<rootDir>/jest-resolver.cjs',
testMatch: ['**/__tests__/**/*.test.ts'],
setupFilesAfterEnv: ['<rootDir>/jest.setup.cjs'],
globals: {
'ts-jest': {
useESM: true,
@@ -36,9 +30,9 @@ module.exports = {
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'clover', 'html'],
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.{ts,tsx}',
'!src/**/*.test.ts',
'!src/types/**/*',
'!src/polyfills.ts'
],
@@ -49,5 +43,6 @@ module.exports = {
lines: 80,
statements: 80
}
}
},
verbose: true
};