Skip to content

Commit

Permalink
Update: Add a better error message if a non-Vinyl is received by .des…
Browse files Browse the repository at this point in the history
…t/.symlink (closes #281)
  • Loading branch information
phated committed Nov 30, 2017
1 parent b8318dd commit fdc6fe5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/dest/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var path = require('path');

var fs = require('graceful-fs');
var Vinyl = require('vinyl');
var through = require('through2');

function prepareWrite(folderResolver, optResolver) {
Expand All @@ -11,6 +12,10 @@ function prepareWrite(folderResolver, optResolver) {
}

function normalize(file, enc, cb) {
if (!Vinyl.isVinyl(file)) {
return cb(new Error('Received a non-Vinyl object in `dest()`'));
}

var outFolderPath = folderResolver.resolve('outFolder', file);
if (!outFolderPath) {
return cb(new Error('Invalid output folder'));
Expand Down
5 changes: 5 additions & 0 deletions lib/symlink/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var path = require('path');

var fs = require('graceful-fs');
var Vinyl = require('vinyl');
var through = require('through2');

function prepareSymlink(folderResolver, optResolver) {
Expand All @@ -11,6 +12,10 @@ function prepareSymlink(folderResolver, optResolver) {
}

function normalize(file, enc, cb) {
if (!Vinyl.isVinyl(file)) {
return cb(new Error('Received a non-Vinyl object in `symlink()`'));
}

var cwd = path.resolve(optResolver.resolve('cwd', file));

var outFolderPath = folderResolver.resolve('outFolder', file);
Expand Down
30 changes: 30 additions & 0 deletions test/dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,36 @@ describe('.dest()', function() {
], done);
});

it('errors when a non-Vinyl object is emitted', function(done) {
var file = {};

function assert(err) {
expect(err).toExist();
expect(err.message).toEqual('Received a non-Vinyl object in `dest()`');
done();
}

pipe([
from.obj([file]),
vfs.dest(outputBase),
], assert);
});

it('errors when a buffer-mode stream is piped to it', function(done) {
var file = new Buffer('test');

function assert(err) {
expect(err).toExist();
expect(err.message).toEqual('Received a non-Vinyl object in `dest()`');
done();
}

pipe([
from([file]),
vfs.dest(outputBase),
], assert);
});

it('errors if we cannot mkdirp', function(done) {
var mkdirSpy = expect.spyOn(fs, 'mkdir').andCall(mockError);

Expand Down
30 changes: 30 additions & 0 deletions test/symlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,36 @@ describe('symlink stream', function() {
]);
});

it('errors when a non-Vinyl object is emitted', function(done) {
var file = {};

function assert(err) {
expect(err).toExist();
expect(err.message).toEqual('Received a non-Vinyl object in `symlink()`');
done();
}

pipe([
from.obj([file]),
vfs.symlink(outputBase),
], assert);
});

it('errors when a buffer-mode stream is piped to it', function(done) {
var file = new Buffer('test');

function assert(err) {
expect(err).toExist();
expect(err.message).toEqual('Received a non-Vinyl object in `symlink()`');
done();
}

pipe([
from([file]),
vfs.symlink(outputBase),
], assert);
});

it('does not get clogged by highWaterMark', function(done) {
var expectedCount = 17;
var highwatermarkFiles = [];
Expand Down

0 comments on commit fdc6fe5

Please sign in to comment.