Streamlining ESHOPMAN Development: Addressing Unwanted Test File Bundling

Streamlining ESHOPMAN Development: Addressing Unwanted Test File Bundling

In the fast-paced world of headless commerce and custom storefront development with ESHOPMAN, maintaining a clean and efficient development environment is crucial. Our community frequently shares insights and solutions to common challenges, and a recent discussion highlighted an important issue concerning test file inclusion in development builds.

The Challenge: Test Files Appearing in Development Builds

A developer within the ESHOPMAN community reported an unexpected behavior: when running the local development server (often initiated via a dev script), content intended solely for testing environments was being bundled into the development build. This led to runtime errors, specifically messages like Do not import `@jest/globals` outside of the Jest test environment, which are typically encountered when test-specific libraries are loaded in a non-test context.

This issue primarily affects developers working on custom ESHOPMAN services, storefront components for HubSpot CMS, or other Node.js/TypeScript-based extensions. The inclusion of test files not only bloats the development build but also introduces instability and confusion, making local debugging and feature development more challenging.

Understanding the Impact on ESHOPMAN Projects

For ESHOPMAN developers leveraging Node.js and TypeScript to build robust backend services or integrate with the Admin API and Store API, a streamlined development workflow is paramount. Unexpected errors during the dev process can halt progress and require time-consuming troubleshooting. The problem stems from the build process inadvertently including directories typically reserved for unit or integration tests, such as those found under src/**/__tests__.

Consider a typical package.json script setup for an ESHOPMAN project:

{
  "name": "my-eshopman-storefront",
  "version": "0.0.1",
  "scripts": {
    "build": "eshopman build",
    "start": "eshopman start",
    "dev": "eshopman develop",
    "test:unit": "TEST_TYPE=unit NODE_OPTI jest --silent --runInBand --forceExit"
  },
  "devDependencies": {
    "@jest/globals": "30.0.5",
    "@swc/jest": "^0.2.36",
    "jest": "^29.7.0",
    "typescript": "^5.6.2"
  },
  "engines": {
    "node": ">=20"
  }
}

As seen above, tools like jest and @jest/globals are clearly designated as devDependencies. Their presence in a live development bundle indicates an incorrect configuration or oversight in the build tooling, which should typically exclude such files by default when not explicitly running test scripts.

The ESHOPMAN Team's Solution

We're pleased to report that the ESHOPMAN core development team has been made aware of this behavior and has already implemented a fix. This issue was identified as a duplicate of another reported concern, and the necessary changes to prevent test files from being bundled in development builds have been merged into the ESHOPMAN platform codebase.

This resolution means that in an upcoming ESHOPMAN platform release, developers will no longer encounter these unexpected errors during their local dev cycles. The platform will correctly differentiate between development and testing contexts, ensuring that only relevant code is bundled for efficient and error-free local development.

Best Practices for ESHOPMAN Developers

This community insight underscores the importance of:

  • Keeping your ESHOPMAN installation updated: Regular updates ensure you benefit from the latest features, performance improvements, and critical bug fixes like this one.
  • Leveraging the ESHOPMAN community: Sharing issues and solutions helps everyone build better, more stable headless commerce experiences on HubSpot CMS.
  • Maintaining clean project structures: While the platform addresses this specific bug, adhering to best practices for separating test code from application code remains vital.

The ESHOPMAN team is committed to providing a robust and developer-friendly platform for building powerful headless commerce solutions integrated with HubSpot. Stay tuned for the next platform release to experience these improvements firsthand!

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools