From ba2d10fb30802e06decc61114533ec6cadf6eb27 Mon Sep 17 00:00:00 2001 From: leah-1ee Date: Thu, 30 Jul 2026 17:06:58 +0900 Subject: [PATCH] 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 --- test/ffi/ffi-test-common.js | 9 +++------ test/ffi/test-ffi-module.js | 8 ++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/ffi/ffi-test-common.js b/test/ffi/ffi-test-common.js index 86e56de8ec21..fa54ca2cfd34 100644 --- a/test/ffi/ffi-test-common.js +++ b/test/ffi/ffi-test-common.js @@ -6,18 +6,15 @@ const path = require('node:path'); common.skipIfFFIMissing(); +const { suffix } = require('node:ffi'); + const fixtureBuildDir = path.join( __dirname, 'fixture_library', 'build', common.buildType, ); -const libraryPath = path.join( - fixtureBuildDir, - process.platform === 'win32' ? 'ffi_test_library.dll' : - process.platform === 'darwin' ? 'ffi_test_library.dylib' : - 'ffi_test_library.so', -); +const libraryPath = path.join(fixtureBuildDir, `ffi_test_library.${suffix}`); function ensureFixtureLibrary() { if (!fs.existsSync(libraryPath)) { diff --git a/test/ffi/test-ffi-module.js b/test/ffi/test-ffi-module.js index ecbd6f1c6a98..7fe265972a74 100644 --- a/test/ffi/test-ffi-module.js +++ b/test/ffi/test-ffi-module.js @@ -154,6 +154,14 @@ test('ffi exports expected API surface', () => { assert.strictEqual(typeof ffi.types, 'object'); }); +test('ffi.suffix matches the current platform', () => { + const ffi = require('node:ffi'); + const expected = process.platform === 'win32' ? 'dll' : + process.platform === 'darwin' ? 'dylib' : 'so'; + + assert.strictEqual(ffi.suffix, expected); +}); + test('ffi.types exports canonical type constants', () => { const ffi = require('node:ffi'); const expected = {