Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 42 additions & 45 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,52 @@ const nextJest = require('next/jest');

// Tell Next.js where the app lives
const createJestConfig = nextJest({
dir: './',
dir: './',
});

/** @type {import('jest').Config} */
const customJestConfig = {
// Required for testing React components
testEnvironment: 'jest-environment-jsdom',

// Testing Library setup (matchers like toBeInTheDocument)
setupFilesAfterEnv: ['<rootDir>/tests/setup-jest.ts'],

// Support @/ path aliases (same as tsconfig.json)
moduleNameMapper: {
'^@/components/(.*)$': '<rootDir>/components/$1',
'^@/lib/(.*)$': '<rootDir>/lib/$1',
'^@/types/(.*)$': '<rootDir>/types/$1',
'^@/hooks/(.*)$': '<rootDir>/hooks/$1',
'^@/utils/(.*)$': '<rootDir>/utils/$1',
'^@/app/(.*)$': '<rootDir>/app/$1',
'^@/config/(.*)$': '<rootDir>/config/$1',
'^@/(.*)$': '<rootDir>/src/$1',
},

// Where Jest should look for tests
testMatch: [
'<rootDir>/tests/**/*.test.{ts,tsx}',
'<rootDir>/components/**/**tests**/**/*.test.{ts,tsx}',
],

// Ignore build + dependencies
testPathIgnorePatterns: [
'<rootDir>/.next/',
'<rootDir>/node_modules/',
],

// Ignore unrelated nested projects
modulePathIgnorePatterns: [
'<rootDir>/GroqTales/',
'<rootDir>/src/blockchain/alchemy/node_modules/',
],

// Coverage (optional but useful for PR reviewers)
collectCoverageFrom: [
'app/**/*.{ts,tsx}',
'components/**/*.{ts,tsx}',
'lib/**/*.{ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
],
// Required for testing React components
testEnvironment: 'jest-environment-jsdom',

// Testing Library setup (matchers like toBeInTheDocument)
setupFilesAfterEnv: ['<rootDir>/tests/setup-jest.ts'],

// Support @/ path aliases (same as tsconfig.json)
moduleNameMapper: {
'^@/components/(.*)$': '<rootDir>/components/$1',
'^@/lib/(.*)$': '<rootDir>/lib/$1',
'^@/types/(.*)$': '<rootDir>/types/$1',
'^@/hooks/(.*)$': '<rootDir>/hooks/$1',
'^@/utils/(.*)$': '<rootDir>/utils/$1',
'^@/app/(.*)$': '<rootDir>/app/$1',
'^@/config/(.*)$': '<rootDir>/config/$1',
'^@/(.*)$': '<rootDir>/src/$1',
},

// Where Jest should look for tests
testMatch: [
'<rootDir>/tests/**/*.test.{ts,tsx}',
'<rootDir>/components/**/__tests__/**/*.test.{ts,tsx}',
],

// Ignore build + dependencies
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],

// Ignore unrelated nested projects
modulePathIgnorePatterns: [
'<rootDir>/GroqTales/',
'<rootDir>/src/blockchain/alchemy/node_modules/',
],

// Coverage (optional but useful for PR reviewers)
collectCoverageFrom: [
'app/**/*.{ts,tsx}',
'components/**/*.{ts,tsx}',
'lib/**/*.{ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
],
};

// Export Next-aware Jest config
Expand Down
31 changes: 27 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,31 @@ const nextConfig = {
},
async rewrites() {
const envUrl = process.env.NEXT_PUBLIC_API_URL;
const apiUrl = (envUrl && envUrl.startsWith('http'))
? envUrl
: 'http://localhost:3001';
let apiUrl = 'http://localhost:3001';

if (envUrl) {
try {
const url = new URL(envUrl);
const allowedHosts = [
'localhost',
'groqtales.com',
'www.groqtales.com',
'api.groqtales.com',
'groqtales.vercel.app',
];

// Ensure we only allow specific hosts to prevent arbitrary redirects
if (allowedHosts.includes(url.hostname)) {
apiUrl = envUrl;
} else {
console.warn(
`NEXT_PUBLIC_API_URL host ${url.hostname} not in allowlist. Using default.`
);
}
} catch (e) {
console.warn('Invalid NEXT_PUBLIC_API_URL provided. Using default.');
}
}

return [
{
Expand Down Expand Up @@ -162,7 +184,8 @@ const nextConfig = {

// TypeScript configuration
typescript: {
ignoreBuildErrors: true,
// We want type errors to fail the build in CI
ignoreBuildErrors: false,
},

// ESLint configuration
Expand Down
Loading
Loading