forked from sindresorhus/path-type
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 6 and add 100% code coverage (sindresorhus#3)
- Loading branch information
1 parent
a83cd9d
commit efe7650
Showing
7 changed files
with
96 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
yarn.lock | ||
.nyc_output | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); |