Skip to content

Commit 4528d9a

Browse files
Bartek Wronaclaude
andcommitted
Fix test_locate_file_abspath_esm to use dynamic import for path module
The test was using require('path') which doesn't work in ESM mode. Since ESM output (.mjs) wraps the module in an async context, we can use top-level await with dynamic import. Changed from: require('path')['isAbsolute'](scriptDirectory) To: var nodePath = await import('node:path'); nodePath.isAbsolute(scriptDirectory) This properly tests the Node.js path.isAbsolute() function while being compatible with ESM module format. The CJS variant (test_locate_file_abspath) continues to use require() as appropriate for CommonJS. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3474523 commit 4528d9a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

test/test_other.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15081,9 +15081,11 @@ def test_locate_file_abspath(self, args):
1508115081
})
1508215082
def test_locate_file_abspath_esm(self, args):
1508315083
# Verify that `scriptDirectory` is an absolute path when `EXPORT_ES6`
15084+
# Use dynamic import for path module since ESM output supports top-level await
1508415085
create_file('pre.js', '''
15086+
var nodePath = await import('node:path');
1508515087
Module['locateFile'] = (fileName, scriptDirectory) => {
15086-
assert(require('path')['isAbsolute'](scriptDirectory), `scriptDirectory (${scriptDirectory}) should be an absolute path`);
15088+
assert(nodePath.isAbsolute(scriptDirectory), `scriptDirectory (${scriptDirectory}) should be an absolute path`);
1508715089
return scriptDirectory + fileName;
1508815090
};
1508915091
''')

0 commit comments

Comments
 (0)