Skip to content

Commit 54c5231

Browse files
Mrassimoclaude
andcommitted
fix: Enhance Jest configuration for CI compatibility and fix E2E test timeouts
- Enhanced CI environment detection with support for multiple CI platforms - Added explicit timeouts to E2E tests (15-45 seconds based on operation complexity) - Updated Jest configuration with CI-specific settings (single worker, longer timeouts) - Fixed missing timeouts in basic.test.ts that could cause CI failures - Improved test stability across different environments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent feb6242 commit 54c5231

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

jest.config.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
/** @type {import('jest').Config} */
2+
3+
// Enhanced CI detection for various environments
4+
function isCI() {
5+
return !!(
6+
process.env.CI || // Standard CI environment variable
7+
process.env.GITHUB_ACTIONS || // GitHub Actions
8+
process.env.GITLAB_CI || // GitLab CI
9+
process.env.CIRCLECI || // CircleCI
10+
process.env.TRAVIS || // Travis CI
11+
process.env.BUILDKITE || // Buildkite
12+
process.env.JENKINS_URL || // Jenkins
13+
process.env.TEAMCITY_VERSION || // TeamCity
14+
process.env.TF_BUILD || // Azure DevOps
15+
process.env.CODEBUILD_BUILD_ID || // AWS CodeBuild
16+
process.env.BUILD_ID || // Generic build ID
17+
process.env.NODE_ENV === 'test' // Test environment
18+
);
19+
}
20+
221
module.exports = {
322
preset: 'ts-jest',
423
testEnvironment: 'node',
@@ -31,18 +50,18 @@ module.exports = {
3150
statements: 65,
3251
},
3352
},
34-
// Fast test execution
35-
testTimeout: 5000,
36-
maxWorkers: '50%',
53+
// CI-friendly test execution - detect various CI environments
54+
testTimeout: isCI() ? 30000 : 10000, // Longer timeout for CI environments
55+
maxWorkers: isCI() ? 1 : '50%', // Single worker in CI to avoid resource conflicts
3756

3857
// Clean test environment
3958
clearMocks: true,
4059
restoreMocks: true,
4160
resetMocks: true,
4261

43-
// No hanging tests allowed
44-
forceExit: false,
45-
detectOpenHandles: false,
62+
// Better error detection and handling
63+
forceExit: isCI() ? true : false, // Force exit in CI to prevent hanging
64+
detectOpenHandles: true, // Enable to detect process leaks
4665

4766
// Coverage reporting
4867
coverageDirectory: 'coverage',
@@ -53,8 +72,8 @@ module.exports = {
5372
cache: true,
5473
cacheDirectory: '<rootDir>/.jest-cache',
5574

56-
// Error handling
57-
bail: 1, // Stop on first test failure for faster feedback
75+
// Error handling - show all failures in CI, bail locally for speed
76+
bail: isCI() ? false : 1,
5877

5978
// Custom matchers and setup
6079
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],

tests/e2e/basic.test.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,41 @@ Charlie,35,92`;
2828
});
2929

3030
it('should execute CLI help command', () => {
31-
const result = execSync(`node "${cliPath}" --help`, { encoding: 'utf8' });
31+
const result = execSync(`node "${cliPath}" --help`, {
32+
encoding: 'utf8',
33+
timeout: 15000, // 15 seconds timeout for CI compatibility
34+
maxBuffer: 1024 * 1024 // 1MB buffer
35+
});
3236
expect(result).toContain('Usage: datapilot');
3337
expect(result).toContain('Commands:');
3438
});
3539

3640
it('should execute CLI version command', () => {
37-
const result = execSync(`node "${cliPath}" --version`, { encoding: 'utf8' });
41+
const result = execSync(`node "${cliPath}" --version`, {
42+
encoding: 'utf8',
43+
timeout: 15000, // 15 seconds timeout for CI compatibility
44+
maxBuffer: 1024 * 1024 // 1MB buffer
45+
});
3846
expect(result).toContain('1.7.0');
3947
});
4048

4149
it('should analyze CSV file with overview command', () => {
42-
const result = execSync(`node "${cliPath}" overview "${testCsv}" -f json`, { encoding: 'utf8' });
50+
const result = execSync(`node "${cliPath}" overview "${testCsv}" -f json`, {
51+
encoding: 'utf8',
52+
timeout: 30000, // 30 seconds timeout for data processing
53+
maxBuffer: 1024 * 1024 // 1MB buffer
54+
});
4355
expect(result).toContain('Report written to:');
4456
expect(result).toContain('Selected parser: csv');
4557
expect(result).toContain('Detected format: csv');
4658
});
4759

4860
it('should run complete analysis with all command', () => {
49-
const result = execSync(`node "${cliPath}" all "${testCsv}"`, { encoding: 'utf8' });
61+
const result = execSync(`node "${cliPath}" all "${testCsv}"`, {
62+
encoding: 'utf8',
63+
timeout: 45000, // 45 seconds timeout for complete analysis
64+
maxBuffer: 2 * 1024 * 1024 // 2MB buffer for full analysis output
65+
});
5066
expect(result).toContain('Report written to:');
5167
expect(result).toContain('Sequential execution completed successfully');
5268
});

tests/setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ global.console = {
1414
error: originalConsole.error, // Keep errors for debugging
1515
};
1616

17-
// Global test timeout (should be fast)
18-
jest.setTimeout(5000);
17+
// Global test timeout - defer to jest.config.js for CI compatibility
18+
// jest.setTimeout is handled by jest.config.js based on environment
1919

2020
// Clean up after each test
2121
afterEach(() => {

0 commit comments

Comments
 (0)