Skip to content

Commit 2545889

Browse files
committed
Add some docs to better understand this pattern
1 parent ac18a77 commit 2545889

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

packages/mrt-utilities/test/helpers/express4-alias.cjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
/*
2+
* Copyright (c) 2025, Salesforce, Inc.
3+
* SPDX-License-Identifier: Apache-2
4+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
17
const Module = require('module');
28

9+
/**
10+
* Monkey-patch Node's module resolution for tests.
11+
* - Redirect `express` to the `express4` alias.
12+
* - Preserve subpath imports like `express/static` by mapping to `express4/...`.
13+
*/
314
const originalResolveFilename = Module._resolveFilename;
415

16+
/**
17+
* Ensure Mocha runs the same test suite against Express 4 by mapping the
18+
* module IDs at resolution time. This avoids touching production imports.
19+
*/
520
Module._resolveFilename = function (request, parent, isMain, options) {
621
if (request === 'express') {
722
return originalResolveFilename.call(this, 'express4', parent, isMain, options);

0 commit comments

Comments
 (0)