This document outlines the detailed steps required to update the remaining legacy packages (mocha, chai, and jsdom) to their absolute latest versions. These upgrades require significant architectural shifts, specifically migrating the project to ECMAScript Modules (ESM) and rewriting the JSDOM network mocking layer.
Make an initial, non-invasive switch to ESM semantics required by latest test tooling.
- Update
package.json: add"type": "module"(done) - Update
tsconfig.json:- Set
"module": "NodeNext"and"moduleResolution": "NodeNext".
- Set
- Update
.mocharc.yamltest loader:- Replace
ts-node/registerwithloader: ts-node/esm(or addnode-options: ["--loader=ts-node/esm"]).
- Replace
Notes: this phase is intentionally compact — it prepares Node/TS to resolve ESM imports. The codebase refactor (Phase 2) still follows and is more invasive.
ESM has stricter rules for file paths and global variables compared to CommonJS.
- Update Import Extensions in
src/andtest/- All relative imports must include the
.jsextension, even inside TypeScript files. - Example:
import { Component } from './component';must becomeimport { Component } from './component.js'; - Example:
import { noop } from '../../src/index';must becomeimport { noop } from '../../src/index.js';
- All relative imports must include the
- Refactor Build Scripts (
.build/*.js)- Convert
.build/clean.jsand.build/minify.jsto useimport/exportinstead ofrequire(). - If
__dirnameor__filenameare used, replace them with:import { fileURLToPath } from 'url'; import { dirname } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename);
- Convert
Once the ESM infrastructure is in place, the packages can be safely upgraded.
- Upgrade Test Framework
- Run:
npm install mocha@latest @types/mocha@latest chai@latest @types/chai@latest --save-dev
- Run:
- Upgrade JSDOM
- Run:
npm install jsdom@latest @types/jsdom@latest undici --save-dev
- Run:
JSDOM v23+ removed the ResourceLoader class in favor of the newer undici HTTP client.
- Refactor
test/core/children/crossWindow/childComponent.spec.ts- Remove the
CustomResourceLoaderclass. - Import
MockAgentandsetGlobalDispatcherfromundici. - Set up a mock agent to intercept requests previously handled by
CustomResourceLoader:import { MockAgent, setGlobalDispatcher } from 'undici'; const mockAgent = new MockAgent(); mockAgent.disableNetConnect(); setGlobalDispatcher(mockAgent); const mockPool = mockAgent.get('http://localhost:8080'); // Mock successful requests mockPool.intercept({ path: '/' }).reply(200, ''); // Mock error requests mockPool.intercept({ path: '/iframe-error.html' }).replyWithError(new Error('Some network error'));
- Pass the agent or rely on the global dispatcher when initializing
new JSDOM(). Note thatundiciis now baked into how JSDOM handlesrunScripts: 'dangerously'.
- Remove the
- Run Linter
- Run
npm run lintand fix any new rules or path resolution issues.
- Run
- Run Build
- Run
npm run buildto ensure the TypeScript compiler successfully outputs the ESM bundles.
- Run
- Run Tests
- Run
npm testand verify all 212 tests continue to pass in the new environment.
- Run
- SemVer Major Bump
- Because moving from CommonJS to ESM is a breaking change for anyone consuming the
@validide/u-front-endspackage, theversioninpackage.jsonMUST be bumped to the next major version (e.g.,1.0.0).
- Because moving from CommonJS to ESM is a breaking change for anyone consuming the