From 95ba045a694be4b3a892b0eae4a1b01baf87df2d Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 11 Dec 2023 21:14:40 +0000 Subject: [PATCH] Tests: improve yarn locator coverage --- lib/libvips.js | 1 - test/unit/libvips.js | 23 +++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/libvips.js b/lib/libvips.js index 6376e217..a76c9b46 100644 --- a/lib/libvips.js +++ b/lib/libvips.js @@ -106,7 +106,6 @@ const yarnLocator = () => { const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`]).version; return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10); } catch {} - /* istanbul ignore next */ return ''; }; diff --git a/test/unit/libvips.js b/test/unit/libvips.js index d18af852..dee38d17 100644 --- a/test/unit/libvips.js +++ b/test/unit/libvips.js @@ -145,11 +145,22 @@ describe('libvips binaries', function () { }); }); - it('yarn locator hash', () => { - const locatorHash = libvips.yarnLocator(); - if (locatorHash.length) { - assert.strict(locatorHash.length, 10); - assert.strict(/[a-f0-9]{10}/.test(locatorHash)); - } + describe('yarn locator hash', () => { + it('known platform', () => { + process.env.npm_config_platform = 'linux'; + process.env.npm_config_arch = 's390x'; + const locatorHash = libvips.yarnLocator(); + assert.strictEqual(locatorHash, '86cc8ee6e4'); + delete process.env.npm_config_platform; + delete process.env.npm_config_arch; + }); + it('unknown platform', () => { + process.env.npm_config_platform = 'unknown-platform'; + process.env.npm_config_arch = 'unknown-arch'; + const locatorHash = libvips.yarnLocator(); + assert.strictEqual(locatorHash, ''); + delete process.env.npm_config_platform; + delete process.env.npm_config_arch; + }); }); });