Skip to content

Commit

Permalink
Breaking: Avoid error in write when sourceMap property did not exist …
Browse files Browse the repository at this point in the history
…on file (closes #5)
  • Loading branch information
phated committed Jun 17, 2017
1 parent d74d061 commit ad18dc9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ function write(file, destPath, options, callback) {
return callback(new Error(PLUGIN_NAME + '-write: Not a vinyl file'));
}

// Throw an error if the file doesn't have a sourcemap
if (!file.sourceMap) {
return callback(new Error(PLUGIN_NAME + '-write: No sourcemap found'));
if (file.isStream()) {
return callback(new Error(PLUGIN_NAME + '-write: Streaming not supported'));
}

if (file.isNull() || !file.sourceMap) {
return callback(null, file);
}

// TODO: don't mutate - needs test too
Expand Down
24 changes: 11 additions & 13 deletions test/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ function makeSourceMap() {
};
}

function makeFile(addSourcemap) {
if (addSourcemap === undefined) {
addSourcemap = true;
}
function makeFile() {
var file = new File({
cwd: __dirname,
base: path.join(__dirname, 'assets'),
path: path.join(__dirname, 'assets', 'helloworld.js'),
contents: new Buffer(sourceContent)
contents: new Buffer(sourceContent),
sourceMap: makeSourceMap(),
});
if (addSourcemap === true) {
file.sourceMap = makeSourceMap();
}
return file;
}

Expand Down Expand Up @@ -83,11 +78,14 @@ describe('write', function() {
});
});

it('should return an error when no sourcemap is found on the file', function(done) {
var file = makeFile(false);
sourcemaps.write(file, function(err) {
expect(err instanceof Error && err.message === 'vinyl-sourcemap-write: No sourcemap found').toExist();
done();
it('calls back with the untouched file if sourceMap property does not exist', function(done) {
var file = makeFile();
delete file.sourceMap;
sourcemaps.write(file, function(err, outFile) {
expect(err).toNotExist();
expect(file).toExist();
expect(outFile).toEqual(file);
done(err);
});
});

Expand Down

0 comments on commit ad18dc9

Please sign in to comment.