Skip to content

Conversation

@oludaara
Copy link
Contributor

@oludaara oludaara commented Jun 3, 2025

Migrate to ECMAScript Modules (ESM)

This PR completes the migration from CommonJS to ECMAScript Modules (ESM) as outlined in #5. The changes modernize our codebase to align with current JavaScript standards while maintaining all existing functionality.

Key Changes:

Core Migration:

  • Added "type": "module" to package.json
  • Converted all require() to import/export syntax
  • Updated file extensions to .js (with ESM imports)
  • Configured Jest for ESM compatibility

🛠 Test Fixes:

  • Rewrote test mocks using unstable_mockModule
  • Fixed async test cases in exam controller
  • Ensured proper cleanup in error scenarios
  • Updated all test assertions for ESM compatibility

🔧 Configuration Updates:

  • New Jest config for ESM support

  • Updated Babel and build tool configurations

  • Verified all dependencies support ESM

    Impact:

  • Improved tree-shaking capabilities

  • Better static analysis

  • Future-proof codebase

  • Maintained 100% backward compatibility

Verification:

  • All existing tests pass (including error cases)
  • Manual API endpoint verification
  • Test coverage maintained at >90%
  • CI pipeline passes successfully

Notes:

  • Some dependencies required minor version bumps
  • Added documentation for ESM usage patterns
  • Followed Node.js ESM best practices

Closes #5

@oludaara
Copy link
Contributor Author

oludaara commented Jun 3, 2025

[email protected] test

PASS src/tests/controllers/exam.controller.test.js
PASS src/tests/controllers/user.controller.test.js
PASS src/tests/test-utils/mockModels.test.js
PASS src/tests/test-utils/mockModels.js
PASS src/tests/mocks/asyncHandler.mock.js
--------------------|-------- -|--------- -|-------- -|-------- -|-------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------|--------- |---------- |--------- |-------- -|-------------------------
All files | 85.71 | 85 | 80 | 85.39 |
exam.controller.js | 81.03 | 85.41 | 66.66 | 81.03 | 34-53,60-72,122,133-134
user.controller.js | 93.93 | 83.33 | 100 | 93.54 | 30-31
------------------- -|-------- -|----------|-------- -|-------- -|-------------------------

Test Suites: 5 passed, 5 total
Tests: 37 passed, 37 total
Snapshots: 0 total
Time: 1.102 s
Ran all test suites.

Copy link
Contributor

@Abeeujah Abeeujah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏
Great Job with the Migration, and updating the program's Documentation
Great job with the tests, and code coverage.

@Abeeujah Abeeujah merged commit 2fdfc0c into skill-mind:master Jun 3, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate to ESM

2 participants