Ignore test coverage on more esoteric code paths

This commit is contained in:
Lovell Fuller 2019-07-14 21:52:29 +01:00
parent 38402d3185
commit 119d16cad3

View File

@ -8,7 +8,8 @@ const semver = require('semver');
const platform = require('./platform'); const platform = require('./platform');
const env = process.env; const env = process.env;
const minimumLibvipsVersion = env.npm_package_config_libvips || require('../package.json').config.libvips; const minimumLibvipsVersion = env.npm_package_config_libvips || /* istanbul ignore next */
require('../package.json').config.libvips;
const spawnSyncOptions = { const spawnSyncOptions = {
encoding: 'utf8', encoding: 'utf8',
@ -19,6 +20,7 @@ const mkdirSync = function (dirPath) {
try { try {
fs.mkdirSync(dirPath); fs.mkdirSync(dirPath);
} catch (err) { } catch (err) {
/* istanbul ignore if */
if (err.code !== 'EEXIST') { if (err.code !== 'EEXIST') {
throw err; throw err;
} }
@ -26,7 +28,8 @@ const mkdirSync = function (dirPath) {
}; };
const cachePath = function () { const cachePath = function () {
const npmCachePath = env.npm_config_cache || (env.APPDATA ? path.join(env.APPDATA, 'npm-cache') : path.join(os.homedir(), '.npm')); const npmCachePath = env.npm_config_cache || /* istanbul ignore next */
(env.APPDATA ? path.join(env.APPDATA, 'npm-cache') : path.join(os.homedir(), '.npm'));
mkdirSync(npmCachePath); mkdirSync(npmCachePath);
const libvipsCachePath = path.join(npmCachePath, '_libvips'); const libvipsCachePath = path.join(npmCachePath, '_libvips');
mkdirSync(libvipsCachePath); mkdirSync(libvipsCachePath);
@ -51,17 +54,21 @@ const hasVendoredLibvips = function () {
vendorVersionId = require(path.join(vendorPath, 'versions.json')).vips; vendorVersionId = require(path.join(vendorPath, 'versions.json')).vips;
vendorPlatformId = require(path.join(vendorPath, 'platform.json')); vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
} catch (err) {} } catch (err) {}
/* istanbul ignore if */
if (vendorVersionId && vendorVersionId !== minimumLibvipsVersion) { if (vendorVersionId && vendorVersionId !== minimumLibvipsVersion) {
throw new Error(`Found vendored libvips v${vendorVersionId} but require v${minimumLibvipsVersion}. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`); throw new Error(`Found vendored libvips v${vendorVersionId} but require v${minimumLibvipsVersion}. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
} }
/* istanbul ignore else */
if (vendorPlatformId) { if (vendorPlatformId) {
/* istanbul ignore else */
if (currentPlatformId === vendorPlatformId) { if (currentPlatformId === vendorPlatformId) {
return true; return true;
} else { } else {
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`); throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
} }
} else {
return false;
} }
return false;
}; };
const pkgConfigPath = function () { const pkgConfigPath = function () {
@ -81,7 +88,8 @@ const useGlobalLibvips = function () {
} }
const globalVipsVersion = globalLibvipsVersion(); const globalVipsVersion = globalLibvipsVersion();
return !!globalVipsVersion && semver.gte(globalVipsVersion, minimumLibvipsVersion); return !!globalVipsVersion && /* istanbul ignore next */
semver.gte(globalVipsVersion, minimumLibvipsVersion);
}; };
module.exports = { module.exports = {