Page MenuHomePhabricator

[keyserver] Add conditional handling for import.meta in tests and update Babel configuration
ClosedPublic

Authored by varun on Jun 30 2023, 9:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Dec 29, 5:59 AM
Unknown Object (File)
Sun, Dec 29, 5:59 AM
Unknown Object (File)
Sun, Dec 29, 5:58 AM
Unknown Object (File)
Sun, Dec 29, 5:56 AM
Unknown Object (File)
Fri, Dec 13, 9:55 AM
Unknown Object (File)
Nov 23 2024, 4:54 PM
Unknown Object (File)
Nov 23 2024, 2:28 PM
Unknown Object (File)
Nov 23 2024, 2:28 PM
Subscribers

Details

Summary

The file index.js was modified to conditionally handle the require function, based on whether the code is running in a testing environment or not. This is because Jest, our testing framework, does not fully support ES modules or import.meta as of our current setup. Therefore, for the testing environment, we fall back to the traditional Node.js require function to load our modules.

In the non-testing environment, we rely on import.meta.url and dynamic imports using the createRequire function. This approach is more flexible and aligns with the future-proof ES module standard.

In addition, I've updated the babel.config.cjs file to include the babel-plugin-transform-import-meta plugin. This plugin replaces the import.meta object with { url: __filename } only in the Jest testing environment. The Babel configuration allows Jest to understand import.meta.url in our code by transpiling it to something Jest knows (__filename).

Test Plan

No Jest errors in the following diff, the rust-node-addon APIs work as expected

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable