/
path-exists.test.js
40 lines (33 loc) · 1006 Bytes
/
path-exists.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict'
/* eslint-env mocha */
const fs = require('../..')
const path = require('path')
const os = require('os')
const assert = require('assert')
describe('pathExists()', () => {
let TEST_DIR
beforeEach(done => {
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'path-exists')
fs.emptyDir(TEST_DIR, done)
})
afterEach(done => fs.remove(TEST_DIR, done))
it('should return false if file does not exist', () => {
return fs.pathExists(path.join(TEST_DIR, 'somefile'))
.then(exists => assert(!exists))
})
it('should return true if file does exist', () => {
const file = path.join(TEST_DIR, 'exists')
fs.ensureFileSync(file)
return fs.pathExists(file)
.then(exists => assert(exists))
})
it('should pass an empty error parameter to the callback', done => {
const file = path.join(TEST_DIR, 'exists')
fs.ensureFileSync(file)
fs.pathExists(file, (err, exists) => {
assert.ifError(err)
assert(exists)
done()
})
})
})