From f2110decc163d12e82199e4d7433d9091bf2400b Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Sun, 10 Nov 2013 14:54:03 -0500 Subject: [PATCH 1/4] Use @options (not @data) per Grunt guidelines To get target > task > default option merging out of the box, you have to use `options` when configuring; as opposed to putting the settings directly on the target. Then, within the task, use `this.options([defaults])`. --- tasks/spec.coffee | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tasks/spec.coffee b/tasks/spec.coffee index 0d87dad..a9dbb8d 100644 --- a/tasks/spec.coffee +++ b/tasks/spec.coffee @@ -10,6 +10,15 @@ module.exports = (grunt) -> grunt.registerMultiTask "spec", "run unit specs with Jasmine", (target) -> done = @async() + options = @options + helpers: "spec/helpers/**/*.{js,coffee}" + specs: "spec/**/*.{js,coffee}" + minijasminenode: + onComplete: (runner, log) -> + done(runner.results().failedCount == 0) + + options.minijasminenode.specs = grunt.file.expand(options.helpers).concat(grunt.file.expand(options.specs)) + jasmine = require("minijasminenode") #duck-punch the heck out of global jasmine: global.context = global.describe @@ -19,12 +28,7 @@ module.exports = (grunt) -> require("jasmine-before-all") require("jasmine-stealth") - defaultConfig = - specs: grunt.file.expand(@data.helpers || "spec/helpers/**/*.{js,coffee}").concat(grunt.file.expand(@data.specs || "spec/**/*.{js,coffee}")) - onComplete: (runner, log) -> - done(runner.results().failedCount == 0) - - jasmine.executeSpecs(_({}).extend(defaultConfig, @data.minijasminenode)) + jasmine.executeSpecs options.minijasminenode # because this is a multi-task, it's necessary to have a default task defined grunt.config("spec", default: {}) unless grunt.config("spec")? From 390a655b3af05406ebc1b6eaad88955a859bc5c6 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Sun, 10 Nov 2013 14:57:31 -0500 Subject: [PATCH 2/4] de-dupe the specs array No longer be at the mercy of how minijasminenode handles duplicate files in `specs` option. --- tasks/spec.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tasks/spec.coffee b/tasks/spec.coffee index a9dbb8d..79a32b5 100644 --- a/tasks/spec.coffee +++ b/tasks/spec.coffee @@ -17,7 +17,10 @@ module.exports = (grunt) -> onComplete: (runner, log) -> done(runner.results().failedCount == 0) - options.minijasminenode.specs = grunt.file.expand(options.helpers).concat(grunt.file.expand(options.specs)) + options.minijasminenode.specs = grunt.file.expand( + grunt.file.expand(options.helpers) + .concat(grunt.file.expand(options.specs)) + ) jasmine = require("minijasminenode") #duck-punch the heck out of global jasmine: From de734a45decaba314c6ee652640442dfce0e237a Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Sun, 10 Nov 2013 15:06:02 -0500 Subject: [PATCH 3/4] Update documentation and example with proper usage --- README.md | 20 +++++++++++++------- example/Gruntfile.js | 6 ++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ef47525..d50fc17 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,16 @@ Check out [the included example project](https://github.com/testdouble/grunt-jas No configuration is necessary if the defaults work for you. A simple config might be as small as this, however: -``` +```javascript grunt.loadNpmTasks("grunt-jasmine-bundle") grunt.initConfig({ spec: { unit: { - minijasminenode: { - showColors: true + options: { + minijasminenode: { + showColors: true + } } } } @@ -52,12 +54,16 @@ grunt.initConfig({ } }, unit: { - helpers: ["shared/helpers/**/*.{js,coffee}", "test/helpers/**/*.{js,coffee}"], - specs: "test/**/*.{js,coffee}" + options: { + helpers: ["shared/helpers/**/*.{js,coffee}", "test/helpers/**/*.{js,coffee}"], + specs: "test/**/*.{js,coffee}" + } }, e2e: { - helpers: ["shared/helpers/**/*.{js,coffee}", "e2e/helpers/**/*.{js,coffee}"], - specs: "e2e/**/*.{js,coffee}" + options: { + helpers: ["shared/helpers/**/*.{js,coffee}", "e2e/helpers/**/*.{js,coffee}"], + specs: "e2e/**/*.{js,coffee}" + } } } }); diff --git a/example/Gruntfile.js b/example/Gruntfile.js index ec6862f..3d2a231 100644 --- a/example/Gruntfile.js +++ b/example/Gruntfile.js @@ -5,8 +5,10 @@ module.exports = function(grunt) { grunt.initConfig({ spec: { unit: { - minijasminenode: { - showColors: true + options: { + minijasminenode: { + showColors: true + } } } } From bf61d1af51dafd466c5a7cdca16bf2553e650ec6 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Sun, 10 Nov 2013 21:20:04 -0500 Subject: [PATCH 4/4] Support the deprecated config format as well. (And log a message) --- tasks/spec.coffee | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tasks/spec.coffee b/tasks/spec.coffee index 79a32b5..6e10fbf 100644 --- a/tasks/spec.coffee +++ b/tasks/spec.coffee @@ -4,9 +4,16 @@ # helpers - "spec/helpers/**/*.{js,coffee}" - a glob (or array of globs) to your spec helpers # specs - "spec/**/*.{js,coffee}" - a glob (or array of globs) to your specs # minijasminenode - {} - an object to set or override any options to minijasmine node. See options here: https://github.com/juliemr/minijasminenode#usage + module.exports = (grunt) -> _ = grunt.util._ + extractDeprecatedOptions = (data) -> + _(data).chain() + .pick('specs', 'helpers', 'minijasminenode') + .each((value,option) -> grunt.log.writeln "Specifying '#{option}' directly on a target is deprecated. Please use `options.#{option}` instead." ) + .value() + grunt.registerMultiTask "spec", "run unit specs with Jasmine", (target) -> done = @async() @@ -17,6 +24,8 @@ module.exports = (grunt) -> onComplete: (runner, log) -> done(runner.results().failedCount == 0) + _(options).extend extractDeprecatedOptions(@data) + options.minijasminenode.specs = grunt.file.expand( grunt.file.expand(options.helpers) .concat(grunt.file.expand(options.specs)) @@ -35,4 +44,3 @@ module.exports = (grunt) -> # because this is a multi-task, it's necessary to have a default task defined grunt.config("spec", default: {}) unless grunt.config("spec")? -