44 * SPDX-License-Identifier: BSD-3-Clause
55 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
7+ /* eslint-env jest */
78
89import 'raf/polyfill' // fix requestAnimationFrame issue with polyfill
910import fetch from 'jest-fetch-mock'
1011import 'regenerator-runtime/runtime'
1112
1213// Mock Fetch
1314global . fetch = fetch
15+
16+ /**
17+ * Jest setup to handle Node.js built-in modules with 'node:' prefix.
18+ *
19+ * Problem: The AWS SDK (which uses parse5 internally) tries to import Node.js built-ins
20+ * using the 'node:' prefix (e.g., require('node:stream')), but Jest cannot resolve
21+ * these imports and throws "ENOENT: no such file or directory, open 'node:stream'".
22+ *
23+ * Solution: Mock the 'node:' prefixed imports to point to the standard Node.js modules.
24+ * This allows Jest to properly resolve these imports during testing.
25+ *
26+ * Related issue: https://github.com/inikulin/parse5/issues/1260
27+ */
28+ jest . mock ( 'node:stream' , ( ) => require ( 'stream' ) )
29+ jest . mock ( 'node:util' , ( ) => require ( 'util' ) )
30+ jest . mock ( 'node:path' , ( ) => require ( 'path' ) )
31+ jest . mock ( 'node:fs' , ( ) => require ( 'fs' ) )
32+ jest . mock ( 'node:fs/promises' , ( ) => require ( 'fs/promises' ) )
33+ jest . mock ( 'node:buffer' , ( ) => require ( 'buffer' ) )
34+ jest . mock ( 'node:events' , ( ) => require ( 'events' ) )
35+ jest . mock ( 'node:http' , ( ) => require ( 'http' ) )
36+ jest . mock ( 'node:https' , ( ) => require ( 'https' ) )
37+ jest . mock ( 'node:crypto' , ( ) => require ( 'crypto' ) )
38+ jest . mock ( 'node:os' , ( ) => require ( 'os' ) )
39+ jest . mock ( 'node:url' , ( ) => require ( 'url' ) )
40+ jest . mock ( 'node:zlib' , ( ) => require ( 'zlib' ) )
0 commit comments