Skip to content

Commit ba2d10f

Browse files
committed
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>
1 parent e7904d4 commit ba2d10f

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
const fixtureBuildDir = path.join(
1012
__dirname,
1113
'fixture_library',
1214
'build',
1315
common.buildType,
1416
);
15-
const libraryPath = 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+
const libraryPath = path.join(fixtureBuildDir, `ffi_test_library.${suffix}`);
2118

2219
function ensureFixtureLibrary() {
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(typeof ffi.types, 'object');
155155
});
156156

157+
test('ffi.suffix matches the current platform', () => {
158+
const ffi = require('node:ffi');
159+
const expected = 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
const ffi = require('node:ffi');
159167
const expected = {

0 commit comments

Comments
 (0)