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: https://github.com/nodejs/node/pull/64840
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Aviv Keller <me@aviv.sh>
This commit is contained in:
Seongeun Lee authored and Antoine du Hamel committed 2026-08-05 11:15:05 +02:00
1 parent 70cd5df810
commit b9e596f8e5
2 files changed
+11 -6

No files matched your search

+3 -6
View File
@@ -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)) {
+8
View File
@@ -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 = {