Skip to content

Commit a7717aa

Browse files
Bartek Wronavogel76
authored 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.
1 parent 0a83a98 commit a7717aa

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
@@ -15166,9 +15166,11 @@ def test_locate_file_abspath(self, args):
1516615166
})
1516715167
def test_locate_file_abspath_esm(self, args):
1516815168
# Verify that `scriptDirectory` is an absolute path when `EXPORT_ES6`
15169+
# Use dynamic import for path module since ESM output supports top-level await
1516915170
create_file('pre.js', '''
15171+
var nodePath = await import('node:path');
1517015172
Module['locateFile'] = (fileName, scriptDirectory) => {
15171-
assert(require('path')['isAbsolute'](scriptDirectory), `scriptDirectory (${scriptDirectory}) should be an absolute path`);
15173+
assert(nodePath.isAbsolute(scriptDirectory), `scriptDirectory (${scriptDirectory}) should be an absolute path`);
1517215174
return scriptDirectory + fileName;
1517315175
};
1517415176
''')

0 commit comments

Comments
 (0)