Skip to content

Commit

Permalink
Require Node.js 6 and add 100% code coverage (sindresorhus#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyfarrell authored and sindresorhus committed Feb 21, 2019
1 parent a83cd9d commit efe7650
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
yarn.lock
.nyc_output
coverage
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
os:
- osx
- linux
- windows
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ function type(fn, fn2, fp) {

return pify(fs[fn])(fp)
.then(stats => stats[fn2]())
.catch(err => {
if (err.code === 'ENOENT') {
.catch(error => {
if (error.code === 'ENOENT') {
return false;
}

throw err;
throw error;
});
}

Expand All @@ -25,12 +25,12 @@ function typeSync(fn, fn2, fp) {

try {
return fs[fn](fp)[fn2]();
} catch (err) {
if (err.code === 'ENOENT') {
} catch (error) {
if (error.code === 'ENOENT') {
return false;
}

throw err;
throw error;
}
}

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
"test": "xo && nyc ava"
},
"files": [
"index.js"
Expand All @@ -36,10 +36,11 @@
"filesystem"
],
"dependencies": {
"pify": "^3.0.0"
"pify": "^4.0.1"
},
"devDependencies": {
"ava": "*",
"nyc": "^13.3.0",
"xo": "*"
}
}
34 changes: 0 additions & 34 deletions test.js

This file was deleted.

30 changes: 30 additions & 0 deletions test/eacces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fs from 'fs';
import test from 'ava';
import m from '..';

function fakeError(fp) {
const error = new Error(`EACCES: permission denied, stat '${fp}'`);
error.code = 'EACCES';
return error;
}

Object.defineProperties(fs, {
stat: {
value(fp, cb) {
cb(fakeError(fp));
}
},
statSync: {
value(fp) {
throw fakeError(fp);
}
}
});

test('throws on EACCES error - async', async t => {
await t.throwsAsync(m.file('/root/private'));
});

test('throws on EACCES error - sync', t => {
t.throws(() => m.fileSync('/root/private'));
});
49 changes: 49 additions & 0 deletions test/nominal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import test from 'ava';
import m from '..';

test('.file()', async t => {
t.true(await m.file('package.json'));
await t.throwsAsync(m.file(false));
});

test('.dir()', async t => {
t.true(await m.dir('.'));
await t.throwsAsync(m.dir(false));
});

if (process.platform !== 'win32') {
test('.symlink()', async t => {
t.true(await m.symlink('symlink'));
await t.throwsAsync(m.symlink(false));
});
}

test('.fileSync()', t => {
t.true(m.fileSync('package.json'));
});

test('.dirSync()', t => {
t.true(m.dirSync('.'));
});

if (process.platform !== 'win32') {
test('.symlinkSync()', t => {
t.true(m.symlinkSync('symlink'));
});
}

test('return false if path doesn\'t exist - async', async t => {
t.false(await m.file('unicorn'));
});

test('return false if path doesn\'t exist - sync', t => {
t.false(m.fileSync('unicorn'));
});

test('throws invalid argument - async', async t => {
await t.throwsAsync(m.file(false));
});

test('throws on invalid argument - sync', t => {
t.throws(() => m.fileSync(false));
});

0 comments on commit efe7650

Please sign in to comment.