From 90783c3b3a9f686085e2e18710d9da0ee8985d9d Mon Sep 17 00:00:00 2001 From: Dylan Greene Date: Sat, 17 Aug 2013 23:57:02 -0400 Subject: [PATCH] 0.2.8 * Fixed bug caused Grunt-Notify to not work in 32-bit windows. * Fixed bug that prevented Snarl from working if the task ended quickly from an error. * Removed defaults for how many notifications and how long notifications say on the screen for Snarl. * Replaced Nodeunit tests with Mocha tests. --- Gruntfile.js | 50 +++++++++++++++++---------- README.md | 5 +++ package.json | 9 ++--- tasks/lib/hooks/notify-jshint.js | 2 ++ tasks/lib/platforms/hey-snarl.js | 40 +++++++++++----------- tasks/lib/util/spawn.js | 17 ++++----- tasks/notify.js | 3 +- test/notify.test.js | 34 ++++++++++++++++++ test/notify_test.js | 59 -------------------------------- 9 files changed, 106 insertions(+), 113 deletions(-) create mode 100644 test/notify.test.js delete mode 100644 test/notify_test.js diff --git a/Gruntfile.js b/Gruntfile.js index fea4051..a44eec8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,27 +10,44 @@ module.exports = function(grunt) { - // Project configuration. + grunt.initConfig({ + cafemocha: { + notify: { + src: 'test/**/*.test.js', + options: { + timeout: 10000, + ui: 'bdd', + reporter: 'spec', + require: [ + 'chai' + ] + } + } + }, jshint: { all: [ 'Gruntfile.js', 'tasks/**/*.js', - '<%= nodeunit.tests %>' + 'tests/**/*' ], fixtures: [ 'test/fixtures/*.js' ], options: { jshintrc: '.jshintrc', - force: false + force: true } }, watch: { test: { - files: ['**/*.js'], - tasks: ['nodeunit', 'notify'], + files: [ + 'Gruntfile.js', + 'tasks/**/*.js', + 'test/**/*.js' + ], + tasks: ['cafemocha'], options: { nospawn: true } @@ -38,13 +55,13 @@ module.exports = function(grunt) { }, // Configuration to be run (and then tested). - notify: { - custom_options: { - options: { - title: 'Notify Title', - message: 'This is a "Notify Message" test!' - } - }, +notify: { + custom_options: { + options: { + title: 'Notify Title', + message: 'This is a "Notify Message" test!' + } + }, just_message: { options: { message: 'Just Message' @@ -68,11 +85,6 @@ module.exports = function(grunt) { message: 'Line 1\nLine 2\nLine3\nLine 4\nLine 5.' } } - }, - - // Unit tests. - nodeunit: { - tests: ['test/*_test.js'] } }); @@ -82,12 +94,12 @@ module.exports = function(grunt) { // These plugins provide necessary tasks. grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-nodeunit'); + grunt.loadNpmTasks('grunt-cafe-mocha'); grunt.loadNpmTasks('grunt-contrib-watch'); // Whenever the "test" task is run, first clean the "tmp" dir, then run this // plugin's task(s), then test the result. - grunt.registerTask('test', ['notify', 'nodeunit']); + grunt.registerTask('test', ['notify', 'cafemocha']); // By default, lint and run all tests. grunt.registerTask('default', ['jshint', 'test']); diff --git a/README.md b/README.md index 4eca3f9..0e694b4 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,11 @@ I've changed the default icon which is owned by Apple to the Grunt logo. This project was created for and is used by the free game I co-created for Node Knockout called [Doodle or Die](http://doodleOrDie.com). Please give it a try, we think you will enjoy it! ## Release History +* 17 August 2013 - 0.2.8 + * Fixed bug caused Grunt-Notify to not work in 32-bit windows. + * Fixed bug that prevented Snarl from working if the task ended quickly from an error. + * Removed defaults for how many notifications and how long notifications say on the screen for Snarl. + * Replaced Nodeunit tests with Mocha tests. * 29 July 2013 - 0.2.7 * Fixed bug that could prevent Growl from working. * 26 July 2013 - 0.2.5 diff --git a/package.json b/package.json index 16cb3f3..1efc923 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-notify", "description": "Automatic desktop notifications for Grunt errors and warnings using Growl for OS X or Windows, Mountain Lion Notification Center, and Notify-Send.", - "version": "0.2.7", + "version": "0.2.8", "homepage": "https://github.com/dylang/grunt-notify", "author": { "name": "Dylan Greene", @@ -29,8 +29,9 @@ }, "devDependencies": { "grunt-contrib-jshint": "~0.6.2", - "grunt-contrib-nodeunit": "~0.2.0", - "grunt-contrib-watch": "~0.5.1" + "grunt-contrib-watch": "~0.5.1", + "grunt-cafe-mocha": "~0.1.8", + "chai": "~1.7.2" }, "peerDependencies": { "grunt": "~0.4.1" @@ -50,6 +51,6 @@ "dependencies": { "stack-parser": "~0.0.1", "which": "~1.0.5", - "semver": "~1.1.4" + "semver": "~2.1.0" } } diff --git a/tasks/lib/hooks/notify-jshint.js b/tasks/lib/hooks/notify-jshint.js index 9c5a38b..5346e15 100644 --- a/tasks/lib/hooks/notify-jshint.js +++ b/tasks/lib/hooks/notify-jshint.js @@ -77,6 +77,8 @@ module.exports = function(grunt, options) { message.trim() ].join('\n') }); + + console.log('========', message.trim()); lineNumber = false; reason = false; } diff --git a/tasks/lib/platforms/hey-snarl.js b/tasks/lib/platforms/hey-snarl.js index 2cfce93..7cbee5d 100644 --- a/tasks/lib/platforms/hey-snarl.js +++ b/tasks/lib/platforms/hey-snarl.js @@ -17,14 +17,14 @@ var cmd = 'heysnarl.exe'; var IS_WINDOWS = os.type() === 'Windows_NT'; var DEFAULT_IMAGE = path.resolve(__dirname + '../../../../images/grunt-logo.png'); -var DEFAULT_TIMEOUT = 2; -var DEFAULT_PRIORITY = 0; function findInstall() { var INSTALL_DIR = path.join('full phat', 'Snarl', 'tools'); - var full_path = path.join(process.env.ProgramFiles, INSTALL_DIR, cmd); - var full_path_x86 = path.join(process.env['ProgramFiles(x86)'], INSTALL_DIR, cmd); + var PROGRAM_FILES = process.env.ProgramFiles || ''; + var PROGRAM_FILES_X86 = process.env['ProgramFiles(x86)'] || ''; + var full_path = path.join(PROGRAM_FILES, INSTALL_DIR, cmd); + var full_path_x86 = path.join(PROGRAM_FILES_X86, INSTALL_DIR, cmd); return cmd = findApp(cmd) || findApp(full_path) || @@ -35,24 +35,24 @@ function isSupported() { return IS_WINDOWS && findInstall(); } -module.exports = isSupported() && function(options, cb) { +function escape(str) { + return str.replace(/&/g, '&&').substr(0, 60); +} - var params = url.format({ - pathname: 'notify', - query: { - title: options.title, - text: options.message, - icon: options.image || DEFAULT_IMAGE, - timeout: options.timeout || DEFAULT_TIMEOUT, - priority: options.priority || DEFAULT_PRIORITY +function notify(options, cb) { + var params = + 'notify?' + + 'title=' + escape(options.title) + '&' + + 'text=' + escape(options.message) + '&' + + 'icon=' + (options.image || DEFAULT_IMAGE); + + spawn(cmd, [params], function(err, result, code){ + if (typeof cb === 'function') { + cb(); } }); +} - // don't want the windows version of newline - params = params.replace(/\%0A/g, '\n'); - - spawn(cmd, [params], function(err){ - // heysnarl seems to sends err even when it doesn't need to - cb(); - }); +module.exports = isSupported() && function(options, cb) { + notify(options, cb); //, function(){ }; diff --git a/tasks/lib/util/spawn.js b/tasks/lib/util/spawn.js index e67a1e4..a05a206 100644 --- a/tasks/lib/util/spawn.js +++ b/tasks/lib/util/spawn.js @@ -1,23 +1,20 @@ 'use strict'; var grunt = require('grunt'); +var spawn = require('child_process').spawn; module.exports = function(cmd, args, cb){ var options = { - detached: true + detached: true, + stdio: [ 'ignore','ignore', 'ignore' ] }; - grunt.util.spawn({ - cmd: cmd, - args: args, - options: options - }, function(err, result, code){ - if (cb) { - cb(err); - } - }); + var child = spawn(cmd, args, options); + child.on('close', function (code) { + cb(code); + }); }; diff --git a/tasks/notify.js b/tasks/notify.js index c0a51fb..8f386e4 100644 --- a/tasks/notify.js +++ b/tasks/notify.js @@ -20,8 +20,9 @@ module.exports = function gruntTask(grunt) { grunt.registerMultiTask('notify', 'Show an arbitrary notification whenever you need.', function() { var options = this.options(defaults); + var done = this.async(); if (options.message) { - notify(options); + notify(options, done); } grunt.log.debug('Notify options:', options); }); diff --git a/test/notify.test.js b/test/notify.test.js new file mode 100644 index 0000000..970f2f7 --- /dev/null +++ b/test/notify.test.js @@ -0,0 +1,34 @@ +'use strict'; +var expect = require('chai').expect; + +var grunt = require('grunt'); +var notify = require('../tasks/lib/notify'); + + +describe('grunt-notify', function () { + describe('sanity checks', function () { + it('notify', function (done) { + notify({ title: 'title', message: 'message' }, function(err){ + if (err) throw err; + //expect(err).to.be.empty; + done(); + }); + }); + + it('weird chars', function (done) { + notify({ title: 'weird chars', message: 'bang! "quotes" [brackets] &and&' }, function(err){ + if (err) throw err; + //expect(err).to.be.; + done(); + }); + }); + + it('notify', function (done) { + notify({ title: 'title' }, function(err){ + expect(err).to.equal('Message is required'); + done(); + }); + }); + + }); +}); diff --git a/test/notify_test.js b/test/notify_test.js deleted file mode 100644 index f47e27c..0000000 --- a/test/notify_test.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var grunt = require('grunt'); -var notify = require('../tasks/lib/notify'); - -/* - ======== A Handy Little Nodeunit Reference ======== - https://github.com/caolan/nodeunit - - Test methods: - test.expect(numAssertions) - test.done() - Test assertions: - test.ok(value, [message]) - test.equal(actual, expected, [message]) - test.notEqual(actual, expected, [message]) - test.deepEqual(actual, expected, [message]) - test.notDeepEqual(actual, expected, [message]) - test.strictEqual(actual, expected, [message]) - test.notStrictEqual(actual, expected, [message]) - test.throws(block, [error], [message]) - test.doesNotThrow(block, [error], [message]) - test.ifError(value) -*/ - -exports.notify = { - setUp: function(done) { - // setup here if necessary - done(); - }, - - notify: function(test) { - test.expect(1); - - notify({ title: 'title', message: 'message' }, function(err){ - test.equal(err, null, 'should not have any errors.'); - test.done(); - }); - - }, - - wierdChars: function(test) { - test.expect(1); - - notify({ title: 'weird chars', message: 'bang! "quotes" [brackets] &and&' }, function(err){ - test.equal(err, null, 'should not have any errors.'); - test.done(); - }); - }, - - noMessage: function(test) { - test.expect(1); - - notify({ title: 'title' }, function(err){ - test.equal(err, 'Message is required', 'should error when no message.'); - test.done(); - }); - } -};