Skip to content

Commit

Permalink
use path-exists module as fs.exists is being deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 2, 2015
1 parent b15779d commit 8b4789f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"devDependencies": {
"fs-extra": "^0.12.0",
"mocha": "*"
"mocha": "*",
"path-exists": "^1.0.0"
}
}
45 changes: 23 additions & 22 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var assert = require('assert');
var fs = require('fs-extra');
var pathExists = require('path-exists');
var del = require('./');

beforeEach(function () {
Expand All @@ -26,50 +27,50 @@ afterEach(function () {
it('should delete files - async', function (cb) {
del(['*.tmp', '!1*'], function (err) {
assert(!err, err);
assert(fs.existsSync('1.tmp'));
assert(!fs.existsSync('2.tmp'));
assert(!fs.existsSync('3.tmp'));
assert(!fs.existsSync('4.tmp'));
assert(fs.existsSync('.dot.tmp'));
assert(pathExists.sync('1.tmp'));
assert(!pathExists.sync('2.tmp'));
assert(!pathExists.sync('3.tmp'));
assert(!pathExists.sync('4.tmp'));
assert(pathExists.sync('.dot.tmp'));
cb();
});
});

it('should delete files - sync', function () {
del.sync(['*.tmp', '!1*']);
assert(fs.existsSync('1.tmp'));
assert(!fs.existsSync('2.tmp'));
assert(!fs.existsSync('3.tmp'));
assert(!fs.existsSync('4.tmp'));
assert(fs.existsSync('.dot.tmp'));
assert(pathExists.sync('1.tmp'));
assert(!pathExists.sync('2.tmp'));
assert(!pathExists.sync('3.tmp'));
assert(!pathExists.sync('4.tmp'));
assert(pathExists.sync('.dot.tmp'));
});

it('should take account of options - async', function (cb) {
del(['*.tmp', '!1*'], {dot: true}, function (err) {
assert(!err, err);
assert(fs.existsSync('1.tmp'));
assert(!fs.existsSync('2.tmp'));
assert(!fs.existsSync('3.tmp'));
assert(!fs.existsSync('4.tmp'));
assert(!fs.existsSync('.dot.tmp'));
assert(pathExists.sync('1.tmp'));
assert(!pathExists.sync('2.tmp'));
assert(!pathExists.sync('3.tmp'));
assert(!pathExists.sync('4.tmp'));
assert(!pathExists.sync('.dot.tmp'));
cb();
});
});

it('should take account of options - sync', function () {
del.sync(['*.tmp', '!1*'], {dot: true});
assert(fs.existsSync('1.tmp'));
assert(!fs.existsSync('2.tmp'));
assert(!fs.existsSync('3.tmp'));
assert(!fs.existsSync('4.tmp'));
assert(!fs.existsSync('.dot.tmp'));
assert(pathExists.sync('1.tmp'));
assert(!pathExists.sync('2.tmp'));
assert(!pathExists.sync('3.tmp'));
assert(!pathExists.sync('4.tmp'));
assert(!pathExists.sync('.dot.tmp'));
});

it('cwd option - sync', function () {
var f = 'tmp/tmp.txt';
fs.ensureFileSync(f);
del.sync('tmp.txt', {cwd: 'tmp'});
assert(!fs.existsSync(f));
assert(!pathExists.sync(f));
fs.remove(f);
});

Expand All @@ -79,7 +80,7 @@ it('cwd option - async', function (cb) {

del('tmp.txt', {cwd: 'tmp'}, function (err) {
assert(!err, err);
assert(!fs.existsSync(f));
assert(!pathExists.sync(f));
fs.remove(f);
cb();
});
Expand Down

0 comments on commit 8b4789f

Please sign in to comment.