Skip to content

Commit b9e596f

Browse files
leah-1eeaduh95
authored andcommitted
test: reuse ffi.suffix instead of reimplementing it
ffi-test-common.js duplicated the platform branch already exposed as ffi.suffix, risking drift if lib/ffi.js changes. Reuse it, and require it after skipIfFFIMissing() so a build without FFI skips instead of throwing. Also assert ffi.suffix resolves to the correct value per platform, since test-ffi-module.js only checked that the key exists. Signed-off-by: leah-1ee <dltjddms1028@gmail.com> PR-URL: #64840 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent 70cd5df commit b9e596f

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎test/ffi/ffi-test-common.js‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@ const path = require('node:path');
66

77
common.skipIfFFIMissing();
88

9+
const{ suffix }=require('node:ffi');
10+
911
constfixtureBuildDir=path.join(
1012
__dirname,
1113
'fixture_library',
1214
'build',
1315
common.buildType,
1416
);
15-
constlibraryPath=path.join(
16-
fixtureBuildDir,
17-
process.platform==='win32' ? 'ffi_test_library.dll' :
18-
process.platform==='darwin' ? 'ffi_test_library.dylib' :
19-
'ffi_test_library.so',
20-
);
17+
constlibraryPath=path.join(fixtureBuildDir,`ffi_test_library.${suffix}`);
2118

2219
functionensureFixtureLibrary(){
2320
if(!fs.existsSync(libraryPath)){

‎test/ffi/test-ffi-module.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ test('ffi exports expected API surface', () => {
154154
assert.strictEqual(typeofffi.types,'object');
155155
});
156156

157+
test('ffi.suffix matches the current platform',()=>{
158+
constffi=require('node:ffi');
159+
constexpected=process.platform==='win32' ? 'dll' :
160+
process.platform==='darwin' ? 'dylib' : 'so';
161+
162+
assert.strictEqual(ffi.suffix,expected);
163+
});
164+
157165
test('ffi.types exports canonical type constants',()=>{
158166
constffi=require('node:ffi');
159167
constexpected={

0 commit comments

Comments
 (0)