From 2252645dd909091040e0cb27921e1fb039f0072a Mon Sep 17 00:00:00 2001 From: James Shore Date: Tue, 24 Sep 2013 16:51:21 -0700 Subject: [PATCH] Got nodeunit working with Grunt --- Gruntfile.js | 11 +- Jakefile.js | 1 - node_modules/grunt-contrib-nodeunit/.jshintrc | 13 + .../grunt-contrib-nodeunit/.npmignore | 3 + .../grunt-contrib-nodeunit/.travis.yml | 6 + node_modules/grunt-contrib-nodeunit/AUTHORS | 2 + node_modules/grunt-contrib-nodeunit/CHANGELOG | 26 ++ .../grunt-contrib-nodeunit/CONTRIBUTING.md | 1 + .../grunt-contrib-nodeunit/Gruntfile.js | 45 ++++ .../grunt-contrib-nodeunit/LICENSE-MIT | 22 ++ node_modules/grunt-contrib-nodeunit/README.md | 72 ++++++ .../docs/nodeunit-examples.md | 25 ++ .../docs/nodeunit-options.md | 0 .../docs/nodeunit-overview.md | 3 + .../grunt-contrib-nodeunit/package.json | 62 +++++ .../grunt-contrib-nodeunit/tasks/nodeunit.js | 224 ++++++++++++++++++ .../test/nodeunit_test.js | 11 + 17 files changed, 524 insertions(+), 3 deletions(-) create mode 100644 node_modules/grunt-contrib-nodeunit/.jshintrc create mode 100644 node_modules/grunt-contrib-nodeunit/.npmignore create mode 100644 node_modules/grunt-contrib-nodeunit/.travis.yml create mode 100644 node_modules/grunt-contrib-nodeunit/AUTHORS create mode 100644 node_modules/grunt-contrib-nodeunit/CHANGELOG create mode 100644 node_modules/grunt-contrib-nodeunit/CONTRIBUTING.md create mode 100644 node_modules/grunt-contrib-nodeunit/Gruntfile.js create mode 100644 node_modules/grunt-contrib-nodeunit/LICENSE-MIT create mode 100644 node_modules/grunt-contrib-nodeunit/README.md create mode 100644 node_modules/grunt-contrib-nodeunit/docs/nodeunit-examples.md create mode 100644 node_modules/grunt-contrib-nodeunit/docs/nodeunit-options.md create mode 100644 node_modules/grunt-contrib-nodeunit/docs/nodeunit-overview.md create mode 100644 node_modules/grunt-contrib-nodeunit/package.json create mode 100644 node_modules/grunt-contrib-nodeunit/tasks/nodeunit.js create mode 100644 node_modules/grunt-contrib-nodeunit/test/nodeunit_test.js diff --git a/Gruntfile.js b/Gruntfile.js index 7d17352..d8b69d0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -17,6 +17,10 @@ module.exports = function(grunt) { src: ["src/*.js", "src/server/**/*.js", "build/util/**/*.js", "Gruntfile.js"] } } + }, + + nodeunit: { + all: ["src/_*_test.js", "src/server/**/_*_test.js"] } @@ -38,12 +42,15 @@ module.exports = function(grunt) { // // Default task(s). // grunt.registerTask('default', ['uglify']); - grunt.loadNpmTasks("grunt-contrib-jshint"); - grunt.registerTask("default", "Default Description", ["jshint"], function() { + grunt.registerTask("default", "Lint and test", ["jshint", "nodeunit"], function() { console.log("\n\nOK"); }); + grunt.loadNpmTasks("grunt-contrib-jshint"); + grunt.loadNpmTasks("grunt-contrib-nodeunit"); + + function globalLintOptions() { return { bitwise: true, diff --git a/Jakefile.js b/Jakefile.js index 5b696e7..1c45207 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -51,7 +51,6 @@ var testFiles = new jake.FileList(); testFiles.include("src/_*_test.js"); testFiles.include("src/server/**/_*_test.js"); - testFiles.exclude("node_modules"); var tests = testFiles.toArray(); return tests; } diff --git a/node_modules/grunt-contrib-nodeunit/.jshintrc b/node_modules/grunt-contrib-nodeunit/.jshintrc new file mode 100644 index 0000000..f57a8ff --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/.jshintrc @@ -0,0 +1,13 @@ +{ + "curly": true, + "eqeqeq": true, + "immed": true, + "latedef": true, + "newcap": true, + "noarg": true, + "sub": true, + "undef": true, + "boss": true, + "eqnull": true, + "node": true +} diff --git a/node_modules/grunt-contrib-nodeunit/.npmignore b/node_modules/grunt-contrib-nodeunit/.npmignore new file mode 100644 index 0000000..b785247 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/.npmignore @@ -0,0 +1,3 @@ +node_modules +npm-debug.log +tmp diff --git a/node_modules/grunt-contrib-nodeunit/.travis.yml b/node_modules/grunt-contrib-nodeunit/.travis.yml new file mode 100644 index 0000000..5766191 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "0.8" + - "0.10" +before_script: + - npm install -g grunt-cli \ No newline at end of file diff --git a/node_modules/grunt-contrib-nodeunit/AUTHORS b/node_modules/grunt-contrib-nodeunit/AUTHORS new file mode 100644 index 0000000..6cf7a03 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/AUTHORS @@ -0,0 +1,2 @@ +"Cowboy" Ben Alman (http://benalman.com) +Tyler Kellen (http://goingslowly.com) diff --git a/node_modules/grunt-contrib-nodeunit/CHANGELOG b/node_modules/grunt-contrib-nodeunit/CHANGELOG new file mode 100644 index 0000000..844e7e2 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/CHANGELOG @@ -0,0 +1,26 @@ +v0.2.0: + date: 2013-05-23 + changes: + - Bump nodeunit to v0.8.0 +v0.1.2: + date: 2013-02-15 + changes: + - First official release for Grunt 0.4.0. +v0.1.2rc6: + date: 2013-01-18 + changes: + - Updating grunt/gruntplugin dependencies to rc6. + - Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions. +v0.1.2rc5: + date: 2013-01-09 + changes: + - Updating to work with grunt v0.4.0rc5. + - Switching to this.filesSrc api. +v0.1.1: + date: 2012-11-13 + changes: + - Switch to this.file api internally. +v0.1.0: + date: 2012-11-04 + changes: + - Work in progress, not yet officially released. diff --git a/node_modules/grunt-contrib-nodeunit/CONTRIBUTING.md b/node_modules/grunt-contrib-nodeunit/CONTRIBUTING.md new file mode 100644 index 0000000..5d08cc3 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/CONTRIBUTING.md @@ -0,0 +1 @@ +Please see the [Contributing to grunt](http://gruntjs.com/contributing) guide for information on contributing to this project. diff --git a/node_modules/grunt-contrib-nodeunit/Gruntfile.js b/node_modules/grunt-contrib-nodeunit/Gruntfile.js new file mode 100644 index 0000000..cbe98f6 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/Gruntfile.js @@ -0,0 +1,45 @@ +/* + * grunt-contrib-nodeunit + * http://gruntjs.com/ + * + * Copyright (c) 2013 "Cowboy" Ben Alman, contributors + * Licensed under the MIT license. + */ + +'use strict'; + +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + jshint: { + all: [ + 'Gruntfile.js', + 'tasks/*.js' + ], + options: { + jshintrc: '.jshintrc' + } + }, + + // Unit tests. + nodeunit: { + tests: ['test/*_test.js'] + } + + }); + + // Actually load this plugin's task(s). + grunt.loadTasks('tasks'); + + // These plugins provide necessary tasks. + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-internal'); + + // Whenever the "test" task is run, run some basic tests. + grunt.registerTask('test', ['nodeunit']); + + // By default, lint and run all tests. + grunt.registerTask('default', ['jshint', 'nodeunit', 'build-contrib']); + +}; diff --git a/node_modules/grunt-contrib-nodeunit/LICENSE-MIT b/node_modules/grunt-contrib-nodeunit/LICENSE-MIT new file mode 100644 index 0000000..8368849 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/LICENSE-MIT @@ -0,0 +1,22 @@ +Copyright (c) 2013 "Cowboy" Ben Alman, contributors + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/grunt-contrib-nodeunit/README.md b/node_modules/grunt-contrib-nodeunit/README.md new file mode 100644 index 0000000..57521ba --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/README.md @@ -0,0 +1,72 @@ +# grunt-contrib-nodeunit [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-nodeunit.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-nodeunit) + +> Run Nodeunit unit tests. + + + +## Getting Started +This plugin requires Grunt `~0.4.0` + +If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: + +```shell +npm install grunt-contrib-nodeunit --save-dev +``` + +Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: + +```js +grunt.loadNpmTasks('grunt-contrib-nodeunit'); +``` + + + + +## Nodeunit task +_Run this task with the `grunt nodeunit` command._ + +Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide. + +This plugin provides server-side JavaScript unit testing via [nodeunit](https://github.com/caolan/nodeunit/). If you're looking to test JavaScript that uses `window` or the DOM, please use the [grunt-contrib-qunit plugin](https://github.com/gruntjs/grunt-contrib-qunit)`qunit` task. + + +### Usage examples + +#### Wildcards + +In this example, `grunt nodeunit:all` or `grunt nodeunit` will test all files ending with `_test.js` in the `test` directory. + +```js +// Project configuration. +grunt.initConfig({ + nodeunit: { + all: ['test/*_test.js'] + } +}); +``` + +With a slight modification, `grunt nodeunit:all` will test files matching the same pattern in the `test` directory _and all subdirectories_. + +```js +// Project configuration. +grunt.initConfig({ + nodeunit: { + all: ['test/**/*_test.js'] + } +}); +``` + +## Release History + + * 2013-05-23   v0.2.0   Bump nodeunit to v0.8.0 + * 2013-02-15   v0.1.2   First official release for Grunt 0.4.0. + * 2013-01-18   v0.1.2rc6   Updating grunt/gruntplugin dependencies to rc6. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions. + * 2013-01-09   v0.1.2rc5   Updating to work with grunt v0.4.0rc5. Switching to this.filesSrc api. + * 2012-11-13   v0.1.1   Switch to this.file api internally. + * 2012-11-04   v0.1.0   Work in progress, not yet officially released. + +--- + +Task submitted by ["Cowboy" Ben Alman](http://benalman.com) + +*This file was generated on Thu May 23 2013 11:27:24.* diff --git a/node_modules/grunt-contrib-nodeunit/docs/nodeunit-examples.md b/node_modules/grunt-contrib-nodeunit/docs/nodeunit-examples.md new file mode 100644 index 0000000..b5db4fe --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/docs/nodeunit-examples.md @@ -0,0 +1,25 @@ +# Usage examples + +## Wildcards + +In this example, `grunt nodeunit:all` or `grunt nodeunit` will test all files ending with `_test.js` in the `test` directory. + +```js +// Project configuration. +grunt.initConfig({ + nodeunit: { + all: ['test/*_test.js'] + } +}); +``` + +With a slight modification, `grunt nodeunit:all` will test files matching the same pattern in the `test` directory _and all subdirectories_. + +```js +// Project configuration. +grunt.initConfig({ + nodeunit: { + all: ['test/**/*_test.js'] + } +}); +``` \ No newline at end of file diff --git a/node_modules/grunt-contrib-nodeunit/docs/nodeunit-options.md b/node_modules/grunt-contrib-nodeunit/docs/nodeunit-options.md new file mode 100644 index 0000000..e69de29 diff --git a/node_modules/grunt-contrib-nodeunit/docs/nodeunit-overview.md b/node_modules/grunt-contrib-nodeunit/docs/nodeunit-overview.md new file mode 100644 index 0000000..8311026 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/docs/nodeunit-overview.md @@ -0,0 +1,3 @@ +Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide. + +This plugin provides server-side JavaScript unit testing via [nodeunit](https://github.com/caolan/nodeunit/). If you're looking to test JavaScript that uses `window` or the DOM, please use the [grunt-contrib-qunit plugin](https://github.com/gruntjs/grunt-contrib-qunit)`qunit` task. diff --git a/node_modules/grunt-contrib-nodeunit/package.json b/node_modules/grunt-contrib-nodeunit/package.json new file mode 100644 index 0000000..fd541f7 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/package.json @@ -0,0 +1,62 @@ +{ + "name": "grunt-contrib-nodeunit", + "description": "Run Nodeunit unit tests.", + "version": "0.2.0", + "homepage": "https://github.com/gruntjs/grunt-contrib-nodeunit", + "author": { + "name": "Grunt Team", + "url": "http://gruntjs.com/" + }, + "repository": { + "type": "git", + "url": "git://github.com/gruntjs/grunt-contrib-nodeunit.git" + }, + "bugs": { + "url": "https://github.com/gruntjs/grunt-contrib-nodeunit/issues" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/gruntjs/grunt-contrib-nodeunit/blob/master/LICENSE-MIT" + } + ], + "main": "Gruntfile.js", + "engines": { + "node": ">= 0.8.0" + }, + "scripts": { + "test": "grunt test" + }, + "dependencies": { + "nodeunit": "~0.8.0" + }, + "devDependencies": { + "grunt-contrib-jshint": "~0.5.4", + "grunt-contrib-internal": "~0.4.5", + "grunt": "~0.4.0" + }, + "peerDependencies": { + "grunt": "~0.4.0" + }, + "keywords": [ + "gruntplugin" + ], + "contributors": [ + { + "name": "\"Cowboy\" Ben Alman", + "url": "http://benalman.com" + }, + { + "name": "Tyler Kellen", + "url": "http://goingslowly.com" + } + ], + "readme": "# grunt-contrib-nodeunit [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-nodeunit.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-nodeunit)\n\n> Run Nodeunit unit tests.\n\n\n\n## Getting Started\nThis plugin requires Grunt `~0.4.0`\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-contrib-nodeunit --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-contrib-nodeunit');\n```\n\n\n\n\n## Nodeunit task\n_Run this task with the `grunt nodeunit` command._\n\nTask targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide.\n\nThis plugin provides server-side JavaScript unit testing via [nodeunit](https://github.com/caolan/nodeunit/). If you're looking to test JavaScript that uses `window` or the DOM, please use the [grunt-contrib-qunit plugin](https://github.com/gruntjs/grunt-contrib-qunit)`qunit` task.\n\n\n### Usage examples\n\n#### Wildcards\n\nIn this example, `grunt nodeunit:all` or `grunt nodeunit` will test all files ending with `_test.js` in the `test` directory.\n\n```js\n// Project configuration.\ngrunt.initConfig({\n nodeunit: {\n all: ['test/*_test.js']\n }\n});\n```\n\nWith a slight modification, `grunt nodeunit:all` will test files matching the same pattern in the `test` directory _and all subdirectories_.\n\n```js\n// Project configuration.\ngrunt.initConfig({\n nodeunit: {\n all: ['test/**/*_test.js']\n }\n});\n```\n\n## Release History\n\n * 2013-05-23   v0.2.0   Bump nodeunit to v0.8.0\n * 2013-02-15   v0.1.2   First official release for Grunt 0.4.0.\n * 2013-01-18   v0.1.2rc6   Updating grunt/gruntplugin dependencies to rc6. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions.\n * 2013-01-09   v0.1.2rc5   Updating to work with grunt v0.4.0rc5. Switching to this.filesSrc api.\n * 2012-11-13   v0.1.1   Switch to this.file api internally.\n * 2012-11-04   v0.1.0   Work in progress, not yet officially released.\n\n---\n\nTask submitted by [\"Cowboy\" Ben Alman](http://benalman.com)\n\n*This file was generated on Thu May 23 2013 11:27:24.*\n", + "readmeFilename": "README.md", + "_id": "grunt-contrib-nodeunit@0.2.0", + "dist": { + "shasum": "3f94c8390513963b4460c9bf150d68b49edbd9ca" + }, + "_from": "grunt-contrib-nodeunit@", + "_resolved": "https://registry.npmjs.org/grunt-contrib-nodeunit/-/grunt-contrib-nodeunit-0.2.0.tgz" +} diff --git a/node_modules/grunt-contrib-nodeunit/tasks/nodeunit.js b/node_modules/grunt-contrib-nodeunit/tasks/nodeunit.js new file mode 100644 index 0000000..627b9b0 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/tasks/nodeunit.js @@ -0,0 +1,224 @@ +/* + * grunt-contrib-nodeunit + * http://gruntjs.com/ + * + * Copyright (c) 2013 "Cowboy" Ben Alman, contributors + * Licensed under the MIT license. + */ + +'use strict'; + +module.exports = function(grunt) { + + // Nodejs libs. + var path = require('path'); + var util = require('util'); + + // External libs. + var nodeunit = require('nodeunit'); + + // ========================================================================== + // BETTER ERROR DISPLAY + // ========================================================================== + + // Much nicer error formatting than what comes with nodeunit. + var betterErrors = function (assertion) { + var e = assertion.error; + if (!e || !e.actual || !e.expected) { return assertion; } + + // Temporarily override the global "inspect" property because logging + // the entire global object is just silly. + var globalInspect = global.inspect; + global.inspect = function() { return '[object global]'; }; + + e._message = e.message; + + // Pretty-formatted objects. + var actual = util.inspect(e.actual, false, 10, true); + var expected = util.inspect(e.expected, false, 10, true); + + var indent = function(str) { + return str.split('\n').map(function(s) { return ' ' + s; }).join('\n'); + }; + + var stack; + var multiline = (actual + expected).indexOf('\n') !== -1; + if (multiline) { + stack = [ + 'Actual:', indent(actual), + 'Operator:', indent(e.operator), + 'Expected:', indent(expected), + ].join('\n'); + } else { + stack = e.name + ': ' + actual + ' ' + e.operator + ' ' + expected; + } + + e.stack = stack + '\n' + e.stack.split('\n').slice(1).join('\n'); + + // Restore the global "inspect" property. + global.inspect = globalInspect; + return assertion; + }; + + // Reformat stack trace to remove nodeunit scripts, fix indentation, etc. + var cleanStack = function(error) { + error._stack = error.stack; + // Show a full stack trace? + var fullStack = grunt.option('verbose') || grunt.option('stack'); + // Reformat stack trace output. + error.stack = error.stack.split('\n').map(function(line) { + if (line[0] === ' ') { + // Remove nodeunit script srcs from non-verbose stack trace. + if (!fullStack && line.indexOf(path.join('node_modules', 'nodeunit') + path.sep) !== -1) { + return ''; + } + // Remove leading spaces. + line = line.replace(/^ {4}(?=at)/, ''); + // Remove cwd. + line = line.replace('(' + process.cwd() + path.sep, '('); + } else { + line = line.replace(/Assertion(Error)/, '$1'); + } + return line + '\n'; + }).join(''); + + return error; + }; + + // ========================================================================== + // CUSTOM NODEUNIT REPORTER + // ========================================================================== + + // Keep track of the last-started module. + var currentModule; + // Keep track of the last-started test(s). + var unfinished = {}; + + // If Nodeunit explodes because a test was missing test.done(), handle it. + process.on('exit', function() { + var len = Object.keys(unfinished).length; + // If there are unfinished tests, tell the user why Nodeunit killed grunt. + if (len > 0) { + grunt.log.muted = false; + grunt.verbose.error().or.writeln('F'.red); + grunt.log.error('Incomplete tests/setups/teardowns:'); + Object.keys(unfinished).forEach(grunt.log.error, grunt.log); + grunt.fatal('A test was missing test.done(), so nodeunit exploded. Sorry!', + Math.min(99, 90 + len)); + } + }); + + // Keep track of failed assertions for pretty-printing. + var failedAssertions = []; + function logFailedAssertions() { + var assertion, stack; + // Print each assertion error + stack. + while (assertion = failedAssertions.shift()) { + betterErrors(assertion); + cleanStack(assertion.error); + grunt.verbose.or.error(assertion.testName); + if (assertion.error.name === 'AssertionError' && assertion.message) { + grunt.log.error('Message: ' + assertion.message.magenta); + } + grunt.log.error(assertion.error.stack).writeln(); + } + } + + // Define our own Nodeunit reporter. + nodeunit.reporters.grunt = { + info: 'Grunt reporter', + run: function(files, options, callback) { + var opts = { + // No idea. + testspec: undefined, + // Executed when the first test in a file is run. If no tests exist in + // the file, this doesn't execute. + moduleStart: function(name) { + // Keep track of this so that moduleDone output can be suppressed in + // cases where a test file contains no tests. + currentModule = name; + grunt.verbose.subhead('Testing ' + name).or.write('Testing ' + name); + }, + // Executed after a file is done being processed. This executes whether + // tests exist in the file or not. + moduleDone: function(name) { + // Abort if no tests actually ran. + if (name !== currentModule) { return; } + // Print assertion errors here, if verbose mode is disabled. + if (!grunt.option('verbose')) { + if (failedAssertions.length > 0) { + grunt.log.writeln(); + logFailedAssertions(); + } else { + grunt.log.ok(); + } + } + }, + // Executed before each test is run. + testStart: function(name) { + // Keep track of the current test, in case test.done() was omitted + // and Nodeunit explodes. + unfinished[name] = name; + grunt.verbose.write(name + '...'); + // Mute output, in cases where a function being tested logs through + // grunt (for testing grunt internals). + grunt.log.muted = true; + }, + // Executed after each test and all its assertions are run. + testDone: function(name, assertions) { + delete unfinished[name]; + // Un-mute output. + grunt.log.muted = false; + // Log errors if necessary, otherwise success. + if (assertions.failures()) { + assertions.forEach(function(ass) { + if (ass.failed()) { + ass.testName = name; + failedAssertions.push(ass); + } + }); + if (grunt.option('verbose')) { + grunt.log.error(); + logFailedAssertions(); + } else { + grunt.log.write('F'.red); + } + } else { + grunt.verbose.ok().or.write('.'); + } + }, + // Executed when everything is all done. + done: function (assertions) { + if (assertions.failures()) { + grunt.warn(assertions.failures() + '/' + assertions.length + + ' assertions failed (' + assertions.duration + 'ms)'); + } else if (assertions.length === 0) { + grunt.warn('0/0 assertions ran (' + assertions.duration + 'ms)'); + } else { + grunt.verbose.writeln(); + grunt.log.ok(assertions.length + ' assertions passed (' + + assertions.duration + 'ms)'); + } + // Tell the task manager we're all done. + callback(); // callback(assertions.failures() === 0); + } + }; + + // Nodeunit needs absolute paths. + var paths = files.map(function(filepath) { + return path.resolve(filepath); + }); + nodeunit.runFiles(paths, opts); + } + }; + + // ========================================================================== + // TASKS + // ========================================================================== + + grunt.registerMultiTask('nodeunit', 'Run Nodeunit unit tests.', function() { + // Run test(s). + nodeunit.reporters.grunt.run(this.filesSrc, {}, this.async()); + }); + +}; diff --git a/node_modules/grunt-contrib-nodeunit/test/nodeunit_test.js b/node_modules/grunt-contrib-nodeunit/test/nodeunit_test.js new file mode 100644 index 0000000..b175d66 --- /dev/null +++ b/node_modules/grunt-contrib-nodeunit/test/nodeunit_test.js @@ -0,0 +1,11 @@ +'use strict'; + +var grunt = require('grunt'); + +exports.nodeunit = { + please_work: function(test) { + test.expect(1); + test.ok(true, 'this had better work.'); + test.done(); + } +};