File
Blob: src/workerd/api/node/tests/process-getbuiltin-newmodreg-test.js
| 1 | // Copyright (c) 2026 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | import { strictEqual } from 'node:assert'; |
| 5 | |
| 6 | export const getBuiltinModulePublicBuiltins = { |
| 7 | test() { |
| 8 | // process.getBuiltinModule must be able to resolve known public built-ins. |
| 9 | strictEqual(typeof process.getBuiltinModule('node:process'), 'object'); |
| 10 | strictEqual(typeof process.getBuiltinModule('node:buffer'), 'object'); |
| 11 | strictEqual(typeof process.getBuiltinModule('node:assert'), 'object'); |
| 12 | }, |
| 13 | }; |
| 14 | |
| 15 | export const getBuiltinModuleNonExistent = { |
| 16 | test() { |
| 17 | // Non-existent modules return undefined. |
| 18 | strictEqual(process.getBuiltinModule('node:nonexistent'), undefined); |
| 19 | strictEqual(process.getBuiltinModule('non-existent'), undefined); |
| 20 | }, |
| 21 | }; |
| 22 | |
| 23 | export const getBuiltinModuleInternalNotExposed = { |
| 24 | test() { |
| 25 | // Internal modules must not be accessible via getBuiltinModule. |
| 26 | // These are BUILTIN_ONLY modules that should only be importable |
| 27 | // by other built-in modules, never by user code. |
| 28 | strictEqual(process.getBuiltinModule('node-internal:process'), undefined); |
| 29 | strictEqual( |
| 30 | process.getBuiltinModule('node-internal:public_process'), |
| 31 | undefined |
| 32 | ); |
| 33 | strictEqual( |
| 34 | process.getBuiltinModule('node-internal:legacy_process'), |
| 35 | undefined |
| 36 | ); |
| 37 | strictEqual( |
| 38 | process.getBuiltinModule('node-internal:internal_timers_global_override'), |
| 39 | undefined |
| 40 | ); |
| 41 | strictEqual(process.getBuiltinModule('cloudflare-internal:env'), undefined); |
| 42 | strictEqual( |
| 43 | process.getBuiltinModule('cloudflare-internal:filesystem'), |
| 44 | undefined |
| 45 | ); |
| 46 | }, |
| 47 | }; |