build: enhance test configuration and TypeScript handling
- Update Jest config to use ts-jest for better TypeScript support - Add TSX test file pattern support for React components - Improve Babel config with proper TypeScript preset settings - Enable better import.meta transformation for Jest compatibility
This commit is contained in:
@@ -1,31 +1,43 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
presets: [
|
presets: [
|
||||||
['@babel/preset-env', {
|
[
|
||||||
targets: {
|
'@babel/preset-env',
|
||||||
node: 'current'
|
{
|
||||||
}
|
targets: {
|
||||||
}],
|
node: 'current',
|
||||||
'@babel/preset-typescript'
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'@babel/preset-typescript',
|
||||||
|
{
|
||||||
|
isTSX: true,
|
||||||
|
allExtensions: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
// Transform import.meta for Jest compatibility
|
// Transform import.meta for Jest compatibility
|
||||||
function() {
|
function () {
|
||||||
return {
|
return {
|
||||||
visitor: {
|
visitor: {
|
||||||
MetaProperty(path) {
|
MetaProperty(path) {
|
||||||
if (path.node.meta.name === 'import' && path.node.property.name === 'meta') {
|
if (
|
||||||
|
path.node.meta.name === 'import' &&
|
||||||
|
path.node.property.name === 'meta'
|
||||||
|
) {
|
||||||
path.replaceWithSourceString('({ env: process.env })');
|
path.replaceWithSourceString('({ env: process.env })');
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
env: {
|
env: {
|
||||||
test: {
|
test: {
|
||||||
plugins: [
|
plugins: [
|
||||||
// Additional test-specific plugins can go here
|
// Additional test-specific plugins can go here
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"<rootDir>/types/**/__tests__/**/*.test.ts",
|
"<rootDir>/types/**/__tests__/**/*.test.ts",
|
||||||
"<rootDir>/components/**/__tests__/**/*.test.tsx",
|
"<rootDir>/components/**/__tests__/**/*.test.tsx",
|
||||||
"<rootDir>/tests/**/*.test.ts",
|
"<rootDir>/tests/**/*.test.ts",
|
||||||
|
"<rootDir>/tests/**/*.test.tsx",
|
||||||
"<rootDir>/tests/**/*.test.js"
|
"<rootDir>/tests/**/*.test.js"
|
||||||
],
|
],
|
||||||
"collectCoverageFrom": [
|
"collectCoverageFrom": [
|
||||||
@@ -25,7 +26,14 @@
|
|||||||
"^node-fetch$": "<rootDir>/tests/__mocks__/node-fetch.js"
|
"^node-fetch$": "<rootDir>/tests/__mocks__/node-fetch.js"
|
||||||
},
|
},
|
||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.tsx?$": "babel-jest",
|
"^.+\\.tsx?$": [
|
||||||
|
"ts-jest",
|
||||||
|
{
|
||||||
|
"tsconfig": "tsconfig.json",
|
||||||
|
"babelConfig": "babel.config.cjs",
|
||||||
|
"diagnostics": false
|
||||||
|
}
|
||||||
|
],
|
||||||
"^.+\\.jsx?$": "babel-jest"
|
"^.+\\.jsx?$": "babel-jest"
|
||||||
},
|
},
|
||||||
"transformIgnorePatterns": ["node_modules/(?!(@jest/transform|uuid|node-fetch)/)"],
|
"transformIgnorePatterns": ["node_modules/(?!(@jest/transform|uuid|node-fetch)/)"],
|
||||||
|
|||||||
Reference in New Issue
Block a user