Skip to content

Commit

Permalink
55: Fix for no source available
Browse files Browse the repository at this point in the history
  • Loading branch information
vkadam committed Apr 9, 2016
1 parent b1af783 commit e48b8fd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/jsbeautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var path = require("path"),
grunt = require("grunt"),
_ = require("lodash"),
async = require("async"),
stringUtils = require("underscore.string"),
JsBeautifierTask = function(task) {
// Store reference to original task
Expand Down Expand Up @@ -162,7 +163,8 @@ JsBeautifierTask.prototype.run = function() {
return config;
}

var sourceFiles = this.task.files;
var sourceFiles = this.task.files,
done = this.task.async();
if (sourceFiles && sourceFiles.length > 0) {
if (!_.isEmpty(options.dest)) {
grunt.verbose.writeln("All beautified files will be stored under \"" + options.dest + "\" folder");
Expand All @@ -173,8 +175,7 @@ JsBeautifierTask.prototype.run = function() {

grunt.verbose.writeln("Using mode=\"" + options.mode + "\"...");
var actionHandler = "VERIFY_ONLY" === options.mode ? verifyActionHandler : verifyAndWriteActionHandler,
config = getConfig(),
done = this.task.async();
config = getConfig();

/** Add new line for js file unless specified as false */
addJsNewLine = config.js.end_with_newline !== false;
Expand All @@ -184,7 +185,7 @@ JsBeautifierTask.prototype.run = function() {
grunt.fail.fatal("Unable to update js-beautify version to " + options.jsBeautifyVersion + " due to \n" + error);
return done(error);
}
var q = grunt.util.async.queue(function(src, callback) {
var q = async.queue(function(src, callback) {
if (grunt.file.isDir(src)) {
callback();
return;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-jsbeautifier",
"description": "jsbeautifier.org for grunt",
"version": "0.2.11",
"version": "0.2.12-SNAPSHOT",
"homepage": "https://github.com/vkadam/grunt-jsbeautifier",
"author": {
"name": "Vishal Kadam",
Expand All @@ -22,6 +22,7 @@
"node": ">=0.8"
},
"dependencies": {
"async": "^2.0.0-rc.3",
"grunt": "^0.4.1",
"js-beautify": ">=1.4.2",
"lodash": ">=2.4.1",
Expand Down
25 changes: 25 additions & 0 deletions test/generic_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";
/*jshint -W079*/
var chai = require("chai"),
JsBeautifierTask = require("../lib/jsbeautifier"),
createMockTask = require("./mockTask");

chai.use(require('chai-fs'));
/*jshint -W030*/
describe("JsBeautifier: Generic test", function() {
var mockTask;

afterEach(function() {
mockTask = null;
});

it("Verify task response with empty source", function(done) {
var task;
mockTask = createMockTask({}, [], function() {
done();
});

task = new JsBeautifierTask(mockTask);
task.run();
});
});

0 comments on commit e48b8fd

Please sign in to comment.