1'use strict' 2var fs = require('fs') 3var test = require('tap').test 4var requireInject = require('require-inject') 5var semver = require('semver') 6 7var globalProcess = global.process 8 9function loadIsFsAccessAvailable (newProcess, newFs) { 10 global.process = Object.assign({}, global.process, newProcess) 11 var mocks = {fs: Object.assign({}, fs, newFs)} 12 var isFsAccessAvailable = requireInject('../../lib/install/is-fs-access-available.js', mocks) 13 global.process = globalProcess 14 return isFsAccessAvailable 15} 16 17var fsWithAccess = {access: function () {}} 18var fsWithoutAccess = {access: undefined} 19 20if (semver.lt(process.version, '0.12.0')) { 21 test('skipping', function (t) { 22 t.pass('skipping all tests on < 0.12.0 due to process not being injectable') 23 t.end() 24 }) 25} else { 26 test('mac + !fs.access', function (t) { 27 var isFsAccessAvailable = loadIsFsAccessAvailable({platform: 'darwin'}, fsWithoutAccess) 28 t.is(isFsAccessAvailable, false, 'not available') 29 t.end() 30 }) 31 32 test('mac + fs.access', function (t) { 33 var isFsAccessAvailable = loadIsFsAccessAvailable({platform: 'darwin'}, fsWithAccess) 34 t.is(isFsAccessAvailable, true, 'available') 35 t.end() 36 }) 37 38 test('windows + !fs.access', function (t) { 39 var isFsAccessAvailable = loadIsFsAccessAvailable({platform: 'win32'}, fsWithoutAccess) 40 t.is(isFsAccessAvailable, false, 'not available') 41 t.end() 42 }) 43 44 test('windows + fs.access + node 0.12.7', function (t) { 45 var isFsAccessAvailable = loadIsFsAccessAvailable({platform: 'win32', version: '0.12.7'}, fsWithAccess) 46 t.is(isFsAccessAvailable, false, 'not available') 47 t.end() 48 }) 49 50 test('windows + fs.access + node 2.4.0', function (t) { 51 var isFsAccessAvailable = loadIsFsAccessAvailable({platform: 'win32', version: '2.4.0'}, fsWithAccess) 52 t.is(isFsAccessAvailable, true, 'available') 53 t.end() 54 }) 55} 56