Skip to content

Commit

Permalink
check src and dest args, closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
yocontra authored and phated committed Nov 27, 2017
1 parent 1f332c5 commit 6c48690
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/dest/index.js
Expand Up @@ -7,6 +7,8 @@ var writeContents = require('./writeContents');
var defaultMode = 0777 & (~process.umask());

module.exports = function(outFolder, opt) {
if (typeof outFolder !== 'string') throw new Error('Invalid output folder');

if (!opt) opt = {};
if (!opt.cwd) opt.cwd = process.cwd();
if (typeof opt.mode === 'string') opt.mode = parseInt(opt.mode, 8);
Expand Down
9 changes: 9 additions & 0 deletions lib/src/index.js
Expand Up @@ -5,7 +5,16 @@ var File = require('vinyl');
var getContents = require('./getContents');
var getStats = require('./getStats');

var validateGlob = function(glob) {
var isArr = Array.isArray(glob);
if (typeof glob !== 'string' && !isArr) return false;
if (isArr && isArr.length === 0) return false;
return true;
};

module.exports = function(glob, opt) {
if (!validateGlob(glob)) throw new Error('Invalid glob pattern');

if (!opt) opt = {};
if (typeof opt.read !== 'boolean') opt.read = true;
if (typeof opt.buffer !== 'boolean') opt.buffer = true;
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,15 +1,15 @@
{
"name": "vinyl-fs",
"description": "Vinyl adapter for the file system",
"version": "0.1.1",
"version": "0.1.2",
"homepage": "http://github.com/wearefractal/vinyl-fs",
"repository": "git://github.com/wearefractal/vinyl-fs.git",
"author": "Fractal <contact@wearefractal.com> (http://wearefractal.com/)",
"main": "./index.js",
"dependencies": {
"vinyl": "^0.2.0",
"glob-stream": "^3.1.5",
"glob-watcher": "^0.0.3",
"glob-watcher": "^0.0.4",
"mkdirp": "^0.3.5",
"graceful-fs": "^2.0.1",
"map-stream": "^0.1.0"
Expand Down
11 changes: 11 additions & 0 deletions test/dest.js
Expand Up @@ -30,6 +30,17 @@ describe('dest stream', function() {
beforeEach(wipeOut);
afterEach(wipeOut);

it('should explode on invalid folder', function(done) {
var stream;
try {
stream = gulp.dest();
} catch (err) {
should.exist(err);
should.not.exist(stream);
done();
}
});

it('should pass through writes with cwd', function(done) {
var inputPath = path.join(__dirname, "./fixtures/test.coffee");

Expand Down
33 changes: 33 additions & 0 deletions test/src.js
Expand Up @@ -19,6 +19,39 @@ var dataWrap = function(fn) {

describe('source stream', function() {

it('should explode on invalid glob (empty)', function(done) {
var stream;
try {
stream = gulp.src();
} catch (err) {
should.exist(err);
should.not.exist(stream);
done();
}
});

it('should explode on invalid glob (number)', function(done) {
var stream;
try {
stream = gulp.src(123);
} catch (err) {
should.exist(err);
should.not.exist(stream);
done();
}
});

it('should explode on invalid glob (empty array)', function(done) {
var stream;
try {
stream = gulp.src([]);
} catch (err) {
should.exist(err);
should.not.exist(stream);
done();
}
});

it('should pass through writes', function(done) {
var expectedPath = path.join(__dirname, "./fixtures/test.coffee");
var expectedContent = fs.readFileSync(expectedPath);
Expand Down

0 comments on commit 6c48690

Please sign in to comment.