Skip to content

Commit 1efd494

Browse files
author
Bartek Wrona
committed
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 d612f3f commit 1efd494

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
@@ -15123,9 +15123,11 @@ def test_locate_file_abspath(self, args):
1512315123
})
1512415124
def test_locate_file_abspath_esm(self, args):
1512515125
# Verify that `scriptDirectory` is an absolute path when `EXPORT_ES6`
15126+
# Use dynamic import for path module since ESM output supports top-level await
1512615127
create_file('pre.js', '''
15128+
var nodePath = await import('node:path');
1512715129
Module['locateFile'] = (fileName, scriptDirectory) => {
15128-
assert(require('path')['isAbsolute'](scriptDirectory), `scriptDirectory (${scriptDirectory}) should be an absolute path`);
15130+
assert(nodePath.isAbsolute(scriptDirectory), `scriptDirectory (${scriptDirectory}) should be an absolute path`);
1512915131
return scriptDirectory + fileName;
1513015132
};
1513115133
''')

0 commit comments

Comments
 (0)