Tests: improve yarn locator coverage

This commit is contained in:
Lovell Fuller 2023-12-11 21:14:40 +00:00
parent 6e02f9288e
commit 95ba045a69
2 changed files with 17 additions and 7 deletions

View File

@ -106,7 +106,6 @@ const yarnLocator = () => {
const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`]).version; const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`]).version;
return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10); return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10);
} catch {} } catch {}
/* istanbul ignore next */
return ''; return '';
}; };

View File

@ -145,11 +145,22 @@ describe('libvips binaries', function () {
}); });
}); });
it('yarn locator hash', () => { describe('yarn locator hash', () => {
const locatorHash = libvips.yarnLocator(); it('known platform', () => {
if (locatorHash.length) { process.env.npm_config_platform = 'linux';
assert.strict(locatorHash.length, 10); process.env.npm_config_arch = 's390x';
assert.strict(/[a-f0-9]{10}/.test(locatorHash)); 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;
});
}); });
}); });