Skip to content

Conversation

@alisman
Copy link
Contributor

@alisman alisman commented Oct 28, 2025

Migrate E2E tests from Java to JavaScript/TypeScript (Mocha)

Summary

This PR migrates all E2E tests from Java to JavaScript/TypeScript using Mocha, Chai, and Axios. The new test suite provides better developer experience with faster test execution and clearer test patterns.

Changes

New JavaScript/TypeScript E2E Tests

  • ✅ Created src/e2e/js/ directory with complete test infrastructure
  • ✅ Migrated 3 test suites to TypeScript/Mocha (11 total tests):
    • AlterationEnrichmentController (7 tests)
    • ColumnStoreMutationController (3 tests)
    • ColumnStoreStudyController (1 test)
  • ✅ All tests passing against cgds_public_2025_06_24 database

Test Infrastructure

  • Framework: Mocha + Chai for assertions
  • Language: TypeScript with strict type checking
  • HTTP Client: Axios for API requests
  • Data Processing: Lodash for all array/object operations
  • Test Organization: Each test suite in its own directory with co-located test data

Key Features

  • ✨ TypeScript types derived from official Swagger API documentation
  • ✨ Inline test logic with comprehensive comments (no hidden helper methods)
  • ✨ Lodash used consistently for all data transformations
  • ✨ Stack trace inspection for automatic test data discovery
  • ✨ Clear test structure with descriptive assertions

Removed

  • 🗑️ Deleted entire src/e2e/java/ directory and all Java E2E tests
  • 🗑️ Removed Java E2E test references from documentation
  • 🗑️ Removed e2e-test Maven profile

Documentation

  • 📝 Updated README.md with JavaScript E2E test instructions
  • 📝 Created CLAUDE.md with comprehensive test writing guidelines
  • 📝 Updated environment variable documentation
  • 📝 Clarified test layer tools and purpose

Testing

All 11 tests verified passing:

cd src/e2e/js
CBIOPORTAL_URL=http://localhost:8082 npm test

Results: ✅ 11 passing (15s)

Prerequisites for Running Tests

  • Node.js v18 or higher
  • Running cBioPortal instance with cgds_public_2025_06_24 database
  • Server accessible at http://localhost:8080 (or set CBIOPORTAL_URL)

Example Test Structure

describe('AlterationEnrichmentController E2E Tests', () => {
  it('should handle combination comparison session', async () => {
    // Load test data containing 104 samples across two studies
    const testData = await TestUtils.loadTestData('all_alterations.json');

    // Call the enrichment endpoint to get gene statistics
    const enrichments = await TestUtils.callEnrichmentEndpoint(testData);

    // Find the TP53 gene enrichment from the results using Lodash
    const tp53Enrichment = _.find(enrichments, { hugoGeneSymbol: 'TP53' });
    expect(tp53Enrichment, 'TP53 should be present').to.not.be.undefined;

    // Calculate total profiled samples by summing profiledCount
    const totalProfiled = _.sumBy(tp53Enrichment!.counts, 'profiledCount');
    expect(totalProfiled).to.equal(103, 'TP53 should have 103 profiled samples');
  });
});

Benefits

  1. Faster Execution: JavaScript tests run in ~15s vs Java Spring Boot context startup
  2. Better DX: TypeScript provides excellent IDE support and type safety
  3. Clear Test Logic: All data processing visible inline with comments
  4. Easier Maintenance: Co-located test data and clear patterns
  5. Modern Tooling: Leverages Node.js ecosystem (npm, TypeScript, Mocha)

Migration Notes

All Java E2E test functionality has been preserved:

  • ✅ AlterationEnrichmentController: All 7 test scenarios migrated
  • ✅ ColumnStoreMutationController: All 3 projection tests migrated
  • ✅ ColumnStoreStudyController: Study fetch test migrated
  • ❌ HealthCheckE2ETest: Not migrated (simple health check, can be added if needed)

Related Documentation

  • Test writing guide: src/e2e/js/CLAUDE.md
  • Running tests: See README.md "JavaScript/TypeScript E2E Tests" section

Branch: alisman:js-e2ecbioportal:master

alisman and others added 6 commits October 28, 2025 14:45
Converted Java E2E tests to JavaScript/TypeScript using Mocha test framework. The new test suite provides equivalent coverage to the original Java tests while allowing for easier JavaScript-based test development.

Key features:
- 7 comprehensive test cases covering alteration enrichment scenarios
- TypeScript for type safety and better IDE support
- Mocha + Chai for test framework and assertions
- Configurable server URL via environment variable
- Test utilities matching original Java helper methods
- All tests passing against local cBioPortal instance

Test coverage includes:
- Multi-study comparison (WES and IMPACT)
- CNA-only profile filtering
- Missense mutation filtering
- Multi-panel sample handling
- Alteration type filtering
- Patient vs Sample enrichment types

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Refactor test utilities to work with parsed JSON objects

Updated TestUtils to handle JSON objects directly instead of strings:
- loadTestData() now parses and returns JSON objects instead of raw strings
- callEnrichmentEndpoint() accepts objects instead of strings (axios handles serialization)
- Removed redundant JSON.parse() and JSON.stringify() calls throughout tests
- Fixed shallow copy bug by using deep clones where needed and reordering test execution

This change makes the code more idiomatic and eliminates unnecessary string conversions.

All 7 tests passing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Refactor tests to use lodash with inline logic and improved comments

Removed abstraction layers and made test logic transparent:
- Removed helper methods (findGeneEnrichment, getTotalProfiledSamples, getTotalAlteredSamples)
- Inlined all response processing logic directly in test bodies
- Replaced native JS array methods with lodash equivalents:
  - _.find() for finding genes by symbol
  - _.sumBy() for calculating totals
  - _.cloneDeep() for deep cloning objects
  - _.filter(), _.forEach(), _.every(), _.some() for array operations
  - _.endsWith() for string matching
- Added comprehensive inline comments explaining each step
- All assertions now clearly show what data is being processed

Benefits:
- Test logic is explicit and visible in each test
- Comments explain the "why" behind each calculation
- Easier to understand and debug test failures
- Consistent use of lodash throughout

All 7 tests passing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Add comprehensive test writing guide

Created WRITING_TESTS.md to document testing patterns and best practices:
- Core principles: transparency, lodash usage, thorough commenting
- Detailed lodash method examples (find, sumBy, filter, every, some, etc.)
- Step-by-step guide for writing test logic
- Four common reusable patterns with code examples
- Best practices with good/bad comparisons
- Three complete example tests
- Debugging tips

The guide provides clear instructions for writing maintainable, well-commented
E2E tests that follow the established patterns in the codebase.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Reorganize tests and update types from Swagger documentation

Major changes:
- Reorganized test structure: each spec now lives in its own directory with test data
- Updated TypeScript types to match official cBioPortal Swagger API documentation
- Renamed AlterationCount to CountSummary (correct Swagger name)
- Made 'name' field required in CountSummary (per Swagger spec)
- Removed qValue field (not in Swagger spec)
- Updated loadTestData() to automatically find test data in same directory as test
- Uses stack trace inspection to determine caller location
- Replaced WRITING_TESTS.md with CLAUDE.md for AI-assisted development

Type derivation:
- All types now sourced from https://www.cbioportal.org/api/v3/api-docs/internal
- Added comprehensive JSDoc comments with source attribution
- Documented which fields are required vs optional
- Added instructions in CLAUDE.md for deriving types from Swagger docs

Directory structure changes:
- test/AlterationEnrichmentController/
  ├── AlterationEnrichmentController.spec.ts
  ├── all_alterations.json
  ├── multi_panel.json
  ├── patient.json
  └── sample.json

All tests passing with updated structure and types.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

fesafdsafdsa
…ontroller

Migrate two Java E2E test suites to TypeScript/Mocha:
- ColumnStoreMutationControllerE2ETest.java → test/ColumnStoreMutationController/
- ColumnStoreStudyControllerE2ETest.java → test/ColumnStoreStudyController/

Key changes:
- Add MutationDTO, Gene, AlleleSpecificCopyNumber types and ProjectionType enum
- Add mutation fetch tests for ID, SUMMARY, and DETAILED projections
- Add study fetch test with DETAILED projection
- Fix CancerStudyMetadataDTO.cancerType → typeOfCancer to match API response
- All 11 E2E tests passing (7 AlterationEnrichment + 3 Mutation + 1 Study)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add comprehensive section describing the JavaScript/TypeScript E2E tests:
- Prerequisites: Node.js, running cBioPortal with cgds_public_2025_06_24 database
- Installation and running instructions with npm commands
- Environment variable configuration (CBIOPORTAL_URL)
- Test structure and conventions
- Reference to CLAUDE.md for detailed test writing guidelines

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Remove Java E2E tests reference from directory structure
- Simplify JavaScript E2E tests description to focus on API testing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Delete src/e2e/java/ directory and all Java E2E test files:
- AbstractE2ETest.java
- AlterationEnrichmentControllerE2ETest.java
- ColumnStoreMutationControllerE2ETest.java
- ColumnStoreStudyControllerE2ETest.java
- HealthCheckE2ETest.java
- All associated test data JSON files

Update README.md to remove Java E2E test references:
- Update E2E test layer to use Mocha, Chai, Axios instead of Spring Boot tools
- Remove ClickHouse E2E environment variable references
- Remove e2e-test Maven profile from documentation
- Update environment variables table to only reference Integration tests

All E2E tests are now exclusively JavaScript/TypeScript based in src/e2e/js/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add "(test api requests)" to section heading for clarity
- Remove watch mode command (not commonly used)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@alisman alisman requested a review from haynescd October 28, 2025 19:31
@alisman alisman added the test label Oct 28, 2025
alisman and others added 3 commits October 28, 2025 15:58
- Update run-tests.sh to check if cBioPortal is responding before running tests
- Fail with clear error message if server is not accessible
- Update npm test script to use run-tests.sh
- Change default URL from 8080 to 8082 to match actual server
- Pass through spec patterns to mocha for flexible test execution
- Update README with corrected test commands

Benefits:
- Tests fail fast with helpful message if server is not running
- Saves time by not running tests against non-responsive server
- Clear instructions on how to fix the issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Use --no-warnings flag to suppress MODULE_TYPELESS_PACKAGE_JSON warning
for cleaner test output

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant