Add Node.js and bun tests to release pipeline#115
Add Node.js and bun tests to release pipeline#115cb-srinaths wants to merge 10 commits intomasterfrom
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
PR Complexity Score: 3.4 - Simple
View Breakdown
- Lines Changed: 234
- Files Changed: 7
- Complexity Added: 18
- Raw Score: 52.68
Overview
This PR adds continuous integration and improves test and build tooling for the Chargebee library, including support for multiple Node versions and Bun. It refines test configuration with a dedicated tsconfig.test.json and new worker-bundle tests to verify ESM worker exports. It also adjusts Git ignore rules so ESM fixture scripts are tracked and slightly optimizes the release workflow.
Key Changes
- Introduces a
CIGitHub Actions workflow that runs install, build, and test across Node 20/22/24 and adds a separate job to build and test with Bun. - Enhances the release workflow by enabling npm cache for the Node setup step to speed up publishing.
- Updates
.gitignoreto keep.mjsfiles undertest/fixturesandtest/scriptsin version control while still ignoring other JS artifacts. - Adjusts the npm
testscript to use a dedicatedtsconfig.test.json, improving TypeScript/ts-node configuration isolation for tests. - Adds a worker-bundle test suite that verifies the built ESM worker bundle exports all expected webhook-related values and works correctly when loaded inside a Node worker thread (
type: 'module'). - Introduces
tsconfig.test.jsonto configure test compilation behavior and ts-node (including experimental resolver and CommonJS override for runtime).
Risks & Considerations
- The CI workflow assumes
npm ci,npm run build, andnpm testwork in all Node matrix versions and in the Bun environment; incompatibilities or missing Bun support could cause CI failures. - Worker-bundle tests depend on
esm/chargebee.esm.worker.jsbeing built; if build outputs change path or name, tests will need to be updated accordingly. - The use of
ts-nodewithexperimentalResolverand overridden module settings may mask or introduce module-resolution issues that differ from the production build configuration. - Ensuring that
.mjsfixtures are now tracked may surface previously unnoticed linting or tooling constraints on those files.
File-level change summary
| File | Change summary |
|---|---|
| .github/workflows/ci.yml | Adds a new CI workflow that runs install, build, and tests across Node 20/22/24 and under Bun. |
| .github/workflows/release.yml | Enables npm caching in the release workflow’s Node setup to speed up publish runs and fixes EOF newline. |
| .gitignore | Updates ignore rules to continue ignoring JS files while explicitly including .mjs files in test fixtures and scripts. |
| package.json | Updates the test script to use TS_NODE_PROJECT=./tsconfig.test.json for more controlled test TypeScript compilation. |
| test/fixtures/load-esm-worker-bundle.mjs | Adds an ESM worker-thread fixture that loads the built ESM worker bundle and checks for required webhook exports. |
| test/worker-bundle.test.ts | Adds mocha tests that validate the ESM worker bundle’s exports and its ability to run correctly inside a Node worker thread. |
| tsconfig.test.json | Introduces a dedicated TypeScript configuration for tests, including ts-node settings and module options. |
| const workerOptions: WorkerThreadOptions = { | ||
| workerData: { root: repoRoot }, | ||
| type: 'module', | ||
| }; | ||
| const worker = new Worker(fixture, workerOptions); | ||
| let settled = false; |
There was a problem hiding this comment.
Priority: 🟠 HIGH
Problem: The ESM worker thread is constructed with a filesystem path string while using type: 'module', instead of a file URL.
Why: In Node.js, when type: 'module' is used for Worker, the first argument must be a file URL (or URL object). Passing a plain filesystem path can cause the worker to fail to load the module, especially on Windows (where paths like C:\... are not valid URLs), leading to test failures that are platform-dependent.
How to Fix: Convert the fixture filesystem path to a file URL when creating the Worker, using the already-imported pathToFileURL helper.
| const workerOptions: WorkerThreadOptions = { | |
| workerData: { root: repoRoot }, | |
| type: 'module', | |
| }; | |
| const worker = new Worker(fixture, workerOptions); | |
| let settled = false; | |
| const workerOptions: WorkerThreadOptions = { | |
| workerData: { root: repoRoot }, | |
| type: 'module', | |
| }; | |
| const worker = new Worker(pathToFileURL(fixture), workerOptions); | |
| let settled = false; |
Test importing the esm worker and run tests on node 20/22/24 and Bun