pax_global_header00006660000000000000000000000064126663717710014532gustar00rootroot0000000000000052 comment=d0288a2b0b816094e76b7ac73331d04612afd79c grunt-contrib-nodeunit-1.0.0/000077500000000000000000000000001266637177100161505ustar00rootroot00000000000000grunt-contrib-nodeunit-1.0.0/.gitignore000066400000000000000000000000371266637177100201400ustar00rootroot00000000000000node_modules npm-debug.log tmp grunt-contrib-nodeunit-1.0.0/.jshintrc000066400000000000000000000003211266637177100177710ustar00rootroot00000000000000{ "boss": true, "curly": true, "eqeqeq": true, "eqnull": true, "immed": true, "latedef": true, "newcap": true, "noarg": true, "node": true, "sub": true, "undef": true, "unused": true } grunt-contrib-nodeunit-1.0.0/.travis.yml000066400000000000000000000001021266637177100202520ustar00rootroot00000000000000sudo: false language: node_js node_js: - '5' - '4' - '0.10' grunt-contrib-nodeunit-1.0.0/AUTHORS000066400000000000000000000004071266637177100172210ustar00rootroot00000000000000"Cowboy" Ben Alman (http://benalman.com) Tyler Kellen (http://goingslowly.com) Kyle Robinson Young (http://dontkry.com) Vlad Filippov (http://vladfilippov.com) Tim Wood (http://timwoodcreates.com) Nic Jansma (http://nicj.net) Matthew Beale (http://madhatted.com) grunt-contrib-nodeunit-1.0.0/CHANGELOG000066400000000000000000000023051266637177100173620ustar00rootroot00000000000000v1.0.0: date: 2016-03-04 changes: - Fixed unit test to run on Node v4.x and v5.x. - Point main to task and remove peerDep. - Doc updates. v0.4.1: date: 2014-06-21 changes: - Fixes Windows JUnit issue. - Check error.stack exists. v0.4.0: date: 2014-05-14 changes: - Bump nodeunit to v0.9.0 v0.3.0: date: 2014-01-26 changes: - Adds 'reporter' and 'reporterOutput' options. v0.2.2: date: 2013-10-19 changes: - Allow missing operators on error object. v0.2.1: date: 2013-09-24 changes: - Fix error display. 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. grunt-contrib-nodeunit-1.0.0/CONTRIBUTING.md000066400000000000000000000001771266637177100204060ustar00rootroot00000000000000Please see the [Contributing to grunt](http://gruntjs.com/contributing) guide for information on contributing to this project. grunt-contrib-nodeunit-1.0.0/Gruntfile.js000066400000000000000000000060461266637177100204530ustar00rootroot00000000000000/* * grunt-contrib-nodeunit * http://gruntjs.com/ * * Copyright (c) 2016 "Cowboy" Ben Alman, contributors * Licensed under the MIT license. */ 'use strict'; module.exports = function(grunt) { var path = require('path'); // Project configuration. grunt.initConfig({ jshint: { all: [ 'Gruntfile.js', 'tasks/*.js', '<%= nodeunit.tests %>' ], options: { jshintrc: '.jshintrc' } }, // Unit tests. nodeunit: { tests: ['test/*_test.js'] }, // clean tmp dir clean: { tests: ['tmp'] } }); // Actually load this plugin's task(s). grunt.loadTasks('tasks'); // These plugins provide necessary tasks. grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-internal'); // Whenever the "test" task is run, run some basic tests. grunt.registerTask('test', function(which) { var test = path.join(__dirname, 'test', 'fixtures', which + '.js'); if (grunt.file.exists(test)) { grunt.config('nodeunit.tests', test); } grunt.task.run('nodeunit'); }); // Tests nodeunit with tap reporter grunt.registerTask('test-tap', function(which) { var test = path.join('test', 'fixtures', which + '.js'); if (grunt.file.exists(test)) { grunt.config('nodeunit.tests', test); } grunt.config('nodeunit.options.reporter', 'tap'); grunt.task.run('clean'); grunt.task.run('nodeunit'); }); // Tests nodeunit with tap reporter and output saved to a file grunt.registerTask('test-tap-out', function(which) { var test = path.join('test', 'fixtures', which + '.js'); var tap = path.join('tmp', which + '.js.tap'); if (grunt.file.exists(test)) { grunt.config('nodeunit.tests', test); } grunt.config('nodeunit.options.reporter', 'tap'); grunt.config('nodeunit.options.reporterOutput', tap); grunt.task.run('clean'); grunt.task.run('nodeunit'); }); // Tests nodeunit with junit reporter grunt.registerTask('test-junit', function(which) { var test = path.join('test', 'fixtures', which + '.js'); var outDir = path.join('tmp', which + '.junit'); if (grunt.file.exists(test)) { grunt.config('nodeunit.tests', test); } grunt.config('nodeunit.options.reporter', 'junit'); grunt.config('nodeunit.options.reporterOptions', { output: outDir }); grunt.task.run('clean'); grunt.task.run('nodeunit'); }); // Tests nodeunit with minimal reporter grunt.registerTask('test-minimal', function(which) { var test = path.join('test', 'fixtures', which + '.js'); var out = path.join('tmp', which + '.js.out'); if (grunt.file.exists(test)) { grunt.config('nodeunit.tests', test); } grunt.config('nodeunit.options.reporter', 'minimal'); grunt.config('nodeunit.options.reporterOutput', out); grunt.task.run('clean'); grunt.task.run('nodeunit'); }); // By default, lint and run all tests. grunt.registerTask('default', ['jshint', 'nodeunit', 'build-contrib']); }; grunt-contrib-nodeunit-1.0.0/LICENSE-MIT000066400000000000000000000020641266637177100176060ustar00rootroot00000000000000Copyright (c) 2016 "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. grunt-contrib-nodeunit-1.0.0/README.md000066400000000000000000000120351266637177100174300ustar00rootroot00000000000000# grunt-contrib-nodeunit v1.0.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-nodeunit.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-nodeunit) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/8526qwiyaavbfbxh/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-contrib-nodeunit/branch/master) > Run Nodeunit unit tests ## Getting Started 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. ### Differences from Nodeunit Command Line There may be a few differences versus running `nodeunit` on the command line: #### Undone tests will cause problems Nodeunit's reporters (such as `default`) are in charge of tracking tests that do not complete. They often hook into `process.on('exit')`. Since `grunt` is handling the runtime, it does not exit, so the reporter's clean-up code that monitors undone tests does not fire. Additionally, the reporters do not expose the number of "Undone" tests in their completion callbacks. This can cause problems. For example, if an exception is thrown in an undone test, the exception might bubble up into the `grunt` runtime if it's still running. This would cause `grunt` to exit, while `nodeunit` command line would show the undone test. If you're getting strange `grunt` runtime errors or seeing `grunt` exit, check for "undone" tests. ### Settings #### options.reporter Type: `String` Default: `'grunt'` Specifies the reporter you want to use. For example, `default`, `verbose` or `tap`. #### options.reporterOutput Type: `Boolean` Default: `false` Specifies the file the `reporter`'s output should be saved to. For example, `tests.tap`. #### options.reporterOptions Type: `Object` Default: `{}` Specifies the options passed to the `reporter`. For example, the `junit` reporter requires the `output` option to be set: ```js grunt.initConfig({ nodeunit: { all: ['test/*_test.js'], options: { reporter: 'junit', reporterOptions: { output: 'outputdir' } } } }); ``` ### 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 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 grunt.initConfig({ nodeunit: { all: ['test/**/*_test.js'] } }); ``` #### Using Other Reporters To use a reporter other than the default one, you can specify the `reporter` and `reporterOutput` parameters. ```js grunt.initConfig({ nodeunit: { all: ['test/*_test.js'], options: { reporter: 'tap', reporterOutput: 'tests.tap', reporterOptions: { output: 'outputdir' } } } }); ``` ## Release History * 2016-03-04   v1.0.0   Fixed unit test to run on Node v4.x and v5.x. Point main to task and remove peerDep. Doc updates. * 2014-06-21   v0.4.1   Fixes Windows JUnit issue. Check error.stack exists. * 2014-05-14   v0.4.0   Bump nodeunit to v0.9.0 * 2014-01-26   v0.3.0   Adds 'reporter' and 'reporterOutput' options. * 2013-10-19   v0.2.2   Allow missing operators on error object. * 2013-09-24   v0.2.1   Fix error display. * 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 Fri Mar 04 2016 15:41:50.* grunt-contrib-nodeunit-1.0.0/appveyor.yml000066400000000000000000000007111266637177100205370ustar00rootroot00000000000000# AppVeyor file # http://www.appveyor.com/docs/appveyor-yml version: "{build}" clone_depth: 10 environment: matrix: - nodejs_version: "5" - nodejs_version: "4" - nodejs_version: "0.10" install: - ps: Install-Product node $env:nodejs_version - npm install build: off test_script: - node --version && npm --version - npm test matrix: fast_finish: true cache: - 'node_modules -> package.json' # local npm modules grunt-contrib-nodeunit-1.0.0/docs/000077500000000000000000000000001266637177100171005ustar00rootroot00000000000000grunt-contrib-nodeunit-1.0.0/docs/nodeunit-examples.md000066400000000000000000000014651266637177100230710ustar00rootroot00000000000000# 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 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 grunt.initConfig({ nodeunit: { all: ['test/**/*_test.js'] } }); ``` ## Using Other Reporters To use a reporter other than the default one, you can specify the `reporter` and `reporterOutput` parameters. ```js grunt.initConfig({ nodeunit: { all: ['test/*_test.js'], options: { reporter: 'tap', reporterOutput: 'tests.tap', reporterOptions: { output: 'outputdir' } } } }); ``` grunt-contrib-nodeunit-1.0.0/docs/nodeunit-options.md000066400000000000000000000012431266637177100227400ustar00rootroot00000000000000# Settings ## options.reporter Type: `String` Default: `'grunt'` Specifies the reporter you want to use. For example, `default`, `verbose` or `tap`. ## options.reporterOutput Type: `Boolean` Default: `false` Specifies the file the `reporter`'s output should be saved to. For example, `tests.tap`. ## options.reporterOptions Type: `Object` Default: `{}` Specifies the options passed to the `reporter`. For example, the `junit` reporter requires the `output` option to be set: ```js grunt.initConfig({ nodeunit: { all: ['test/*_test.js'], options: { reporter: 'junit', reporterOptions: { output: 'outputdir' } } } }); ``` grunt-contrib-nodeunit-1.0.0/docs/nodeunit-overview.md000066400000000000000000000024361266637177100231200ustar00rootroot00000000000000Task 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. # Differences from Nodeunit Command Line There may be a few differences versus running `nodeunit` on the command line: ## Undone tests will cause problems Nodeunit's reporters (such as `default`) are in charge of tracking tests that do not complete. They often hook into `process.on('exit')`. Since `grunt` is handling the runtime, it does not exit, so the reporter's clean-up code that monitors undone tests does not fire. Additionally, the reporters do not expose the number of "Undone" tests in their completion callbacks. This can cause problems. For example, if an exception is thrown in an undone test, the exception might bubble up into the `grunt` runtime if it's still running. This would cause `grunt` to exit, while `nodeunit` command line would show the undone test. If you're getting strange `grunt` runtime errors or seeing `grunt` exit, check for "undone" tests.grunt-contrib-nodeunit-1.0.0/package.json000066400000000000000000000014421266637177100204370ustar00rootroot00000000000000{ "name": "grunt-contrib-nodeunit", "description": "Run Nodeunit unit tests", "version": "1.0.0", "author": { "name": "Grunt Team", "url": "http://gruntjs.com/" }, "repository": "gruntjs/grunt-contrib-nodeunit", "license": "MIT", "engines": { "node": ">=0.10.0" }, "main": "tasks/nodeunit.js", "scripts": { "test": "grunt test && grunt jshint" }, "dependencies": { "nodeunit": "^0.9.0" }, "devDependencies": { "grunt": "^0.4.5", "grunt-cli": "^0.1.13", "grunt-contrib-clean": "^0.6.0", "grunt-contrib-internal": "^0.4.12", "grunt-contrib-jshint": "^0.11.0", "tap": "^0.7.0" }, "keywords": [ "gruntplugin", "nodeunit", "test", "runner" ], "files": [ "tasks" ], "appveyor_id": "8526qwiyaavbfbxh" } grunt-contrib-nodeunit-1.0.0/tasks/000077500000000000000000000000001266637177100172755ustar00rootroot00000000000000grunt-contrib-nodeunit-1.0.0/tasks/nodeunit.js000066400000000000000000000246101266637177100214630ustar00rootroot00000000000000/* * grunt-contrib-nodeunit * http://gruntjs.com/ * * Copyright (c) 2016 "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'); var fs = require('fs'); // External libs. var nodeunit = require('nodeunit'); function hook_stdout(callback) { var oldWrite = process.stdout.write; process.stdout.write = (function() { return function(string, encoding, fd) { //write.apply(process.stdout, arguments) callback(string, encoding, fd); }; })(process.stdout.write); return function() { process.stdout.write = oldWrite; }; } // ========================================================================== // BETTER ERROR DISPLAY // ========================================================================== // Much nicer error formatting than what comes with nodeunit. var betterErrors = function (assertion) { var e = assertion.error; if (!e || !('actual' in e) || !('expected' in e)) { 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, { depth: 10, colors: true }); var expected = util.inspect(e.expected, { depth: 10, colors: 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; } if (e.stack) { stack += '\n' + e.stack.split('\n').slice(1).join('\n'); } e.stack = stack; // 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; // 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() { var done = this.async(); // Merge task-specific and/or target-specific options with these defaults. var options = this.options({ reporterOutput: false, reporter: 'grunt', reporterOptions: {} }); // Ensure the default nodeunit options are set by reading in the nodeunit.json file. var nodeUnitDefaults = {}; // check for nodeunit under our package's node_modules directory first var nodeUnitDefaultsFile = path.join(__dirname, '..', 'node_modules', 'nodeunit', 'bin', 'nodeunit.json'); if (!fs.existsSync(nodeUnitDefaultsFile)) { // if both grunt-contrib-nodeunit and nodeunit are listed as dependencies for this project, they'd // be located at the same folder level. So check for that location next. nodeUnitDefaultsFile = path.join(__dirname, '..', '..', 'nodeunit', 'bin', 'nodeunit.json'); } if (fs.existsSync(nodeUnitDefaultsFile)) { nodeUnitDefaults = JSON.parse(fs.readFileSync(nodeUnitDefaultsFile, 'utf8')); } for (var defaultVal in nodeUnitDefaults) { if (typeof options.reporterOptions[defaultVal] === 'undefined') { options.reporterOptions[defaultVal] = nodeUnitDefaults[defaultVal]; } } if (!nodeunit.reporters[options.reporter]) { return done(new Error('Reporter ' + options.reporter + ' not found')); } var output = ''; if (options.reporterOutput) { // Hook into stdout to capture report var unhook = hook_stdout(function(string) { output += string; return ''; }); } // if reporterOutput has a directory destination make sure to create it. // See: https://github.com/caolan/nodeunit/issues/262 if (options.reporterOptions.output) { grunt.file.mkdir(path.normalize(options.reporterOptions.output)); } // Run test(s). nodeunit.reporters[options.reporter].run(this.filesSrc, options.reporterOptions, function(err) { // Write the output of the reporter if wanted if (options.reporterOutput) { // no longer hook stdout so we can grunt.log if (unhook) { unhook(); } // save all of the output we saw up to this point grunt.file.write(options.reporterOutput, output); grunt.log.ok('Report "' + options.reporterOutput + '" created.'); } done(err); }); }); }; grunt-contrib-nodeunit-1.0.0/test/000077500000000000000000000000001266637177100171275ustar00rootroot00000000000000grunt-contrib-nodeunit-1.0.0/test/fixtures/000077500000000000000000000000001266637177100210005ustar00rootroot00000000000000grunt-contrib-nodeunit-1.0.0/test/fixtures/fail.js000066400000000000000000000010041266637177100222440ustar00rootroot00000000000000'use strict'; exports.fail = { fail: function(test) { test.ok(undefined, 'this value should be truthy'); test.done(); }, failSupertestError: function(test) { var error = new Error('Something arbitrary'); // Must be long enough that the inspect calls try to // wrap the line for indentation. error.actual = { foo: 'bar', something: 'complex', more: 'more', even: 11335577992 }; error.expected = "No you didn't"; error.showDiff = true; throw(error); test.done(); }, }; grunt-contrib-nodeunit-1.0.0/test/nodeunit_test.js000066400000000000000000000101121266637177100223440ustar00rootroot00000000000000'use strict'; var grunt = require('grunt'); var path = require('path'); exports.nodeunit = { please_work: function(test) { test.expect(1); test.ok(true, 'this had better work.'); test.done(); }, fail: function(test) { test.expect(3); grunt.util.spawn({ grunt: true, args: ['test:fail', '--no-color'] }, function(err, result) { test.ok(result.stdout.indexOf('Operator:') !== -1, 'Operator should display for multiline.'); test.ok(result.stdout.indexOf('Message: this value should be truthy') !== -1, 'Message should have been displayed.'); test.ok(result.stdout.indexOf('Error: undefined == true') !== -1, 'Error should have been displayed.'); test.done(); }); }, tap_fail: function(test) { test.expect(6); grunt.util.spawn({ grunt: true, args: ['test-tap:fail', '--no-color'] }, function(err, result) { // stdout message test.ok(result.stdout.indexOf('# fail - fail') !== -1, 'First test should fail'); test.ok(result.stdout.indexOf('not ok 1 this value should be truthy') !== -1, 'First test failure notice'); test.ok(result.stdout.indexOf('# fail - failSupertestError') !== -1, 'Second test should fail'); test.ok(result.stdout.indexOf('not ok 2 Something arbitrary') !== -1, 'Second test failure message'); test.ok(result.stdout.indexOf('# tests 2') !== -1, 'Total test count'); test.ok(result.stdout.indexOf('# fail 2') !== -1, 'Total failure count'); test.done(); }); }, tap_out_fail: function(test) { test.expect(7); grunt.util.spawn({ grunt: true, args: ['test-tap-out:fail', '--no-color'] }, function(err, result) { // stdout message test.ok(result.stdout.indexOf('fail.js.tap" created') !== -1, 'File creation notice should be displayed.'); // verify parts of the fail.js.tap contents against ours var tapFile = path.join('tmp', 'fail.js.tap'); var tapContents = grunt.util.normalizelf(grunt.file.read(tapFile)); test.ok(tapContents.indexOf('# fail - fail') !== -1, 'First test should fail'); test.ok(tapContents.indexOf('not ok 1 this value should be truthy') !== -1, 'First test failure notice'); test.ok(tapContents.indexOf('# fail - failSupertestError') !== -1, 'Second test should fail'); test.ok(tapContents.indexOf('not ok 2 Something arbitrary') !== -1, 'Second test failure message'); test.ok(tapContents.indexOf('# tests 2') !== -1, 'Total test count'); test.ok(tapContents.indexOf('# fail 2') !== -1, 'Total failure count'); test.done(); }); }, junit: function(test) { test.expect(4); grunt.util.spawn({ grunt: true, args: ['test-junit:fail', '--no-color'] }, function() { // verify the junit directory exists var junitDir = path.join('tmp', 'fail.junit'); var junitFile = path.join(junitDir, 'fail.js.xml'); var junitContents = grunt.util.normalizelf(grunt.file.read(junitFile)); test.ok(junitContents.indexOf('