Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update logging to be less verbose #454

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions tasks/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,25 @@ module.exports = function(grunt) {

// When task runner has started
taskrun.on('start', function() {
Object.keys(changedFiles).forEach(function(filepath) {
var changed = Object.keys(changedFiles);
var changedHow = {};
changed.forEach(function(filepath) {
var how = changedFiles[filepath];
// Log which file has changed, and how.
grunt.log.ok('File "' + filepath + '" ' + changedFiles[filepath] + '.');
grunt.verbose.writeln('File "' + filepath + '" ' + how + '.');
if (typeof changedHow[how] === 'undefined') {
changedHow[how] = 0;
}
changedHow[how]++;
});
Object.keys(changedHow).forEach(function(how) {
if (changedHow[how] > 0) {
grunt.log.ok(
changedHow[how] + ' ' +
grunt.util.pluralize(changedHow[how], 'file/files') +
' ' + how + '.'
);
}
});
// Reset changedFiles
changedFiles = Object.create(null);
Expand Down
19 changes: 17 additions & 2 deletions test/tasks/patterns_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ exports.patterns = {
cleanUp();
done();
},
negate: function(test) {
negateVerbose: function(test) {
test.expect(2);
var cwd = path.resolve(fixtures, 'patterns');
var assertWatch = helper.assertTask('watch', {cwd: cwd});
var assertWatch = helper.assertTask('watch', {cwd: cwd, verbose: true});
assertWatch(function() {
grunt.file.write(path.join(cwd, 'lib', 'sub', 'dontedit.js'), 'var dontedit = true;');
setTimeout(function() {
Expand All @@ -41,4 +41,19 @@ exports.patterns = {
test.done();
});
},
negate: function(test) {
test.expect(1);
var cwd = path.resolve(fixtures, 'patterns');
var assertWatch = helper.assertTask('watch', {cwd: cwd});
assertWatch(function() {
grunt.file.write(path.join(cwd, 'lib', 'sub', 'dontedit.js'), 'var dontedit = true;');
setTimeout(function() {
grunt.file.write(path.join(cwd, 'lib', 'edit.js'), 'var edit = true;');
}, 3000);
}, function(result) {
test.ok(result.indexOf('1 file changed.') !== -1,
'Watch should have been triggered when edit.js was edited.');
test.done();
});
},
};
2 changes: 1 addition & 1 deletion test/tasks/watch_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ exports.watch = {
grunt.file.write(path.join(cwd, 'lib', 'one.js'), write);
}, function(result) {
helper.verboseLog(result);
test.ok(result.indexOf('File "lib' + path.sep + 'one.js" changed') !== -1,
test.ok(result.indexOf('1 file changed.') !== -1,
'Watch should have fired when oneTarget/lib/one.js has changed.');
test.ok(result.indexOf('I do absolutely nothing.') !== -1, 'echo task should have fired.');
test.done();
Expand Down