Skip to content

Commit

Permalink
Add test for loadNpmTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Jan 30, 2016
1 parent 0b35e64 commit 1f9bddd
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"grunt-jscs": "~2.3.0",
"semver": "2.1.0",
"shelljs": "~0.5.3",
"temporary": "~0.0.4"
"temporary": "~0.0.4",
"through2": "~2.0.0"
},
"files": [
"lib"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/fixtures/load-npm-tasks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"name": "load-npm-tasks",
"devDependencies": {
"grunt-foo-plugin": "1.0.0"
}
}
51 changes: 51 additions & 0 deletions test/gruntfile/load-npm-tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* grunt
* http://gruntjs.com/
*
* Copyright (c) 2016 "Cowboy" Ben Alman
* Licensed under the MIT license.
* https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
*/

'use strict';

var Log = require('grunt-legacy-log').Log;
var assert = require('assert');
var through = require('through2');

module.exports = function(grunt) {
grunt.file.setBase('../fixtures/load-npm-tasks');

// Create a custom log to assert output
var stdout = [];
var oldlog = grunt.log;
var stream = through(function(data, enc, next) {
stdout.push(data.toString());
next(null, data);
});
stream.pipe(process.stdout);
var log = new Log({
grunt: grunt,
outStream: stream,
});
grunt.log = log;

// Load a npm task
grunt.loadNpmTasks('grunt-foo-plugin');

// Run them
grunt.registerTask('default', ['foo', 'done']);

// Assert they loaded and ran correctly
grunt.registerTask('done', function() {
grunt.log = oldlog;
stdout = stdout.join('\n');
try {
assert.ok(stdout.indexOf('foo has ran.') !== -1, 'oh-four task should have ran.');
} catch (err) {
grunt.log.subhead(err.message);
grunt.log.error('Expected ' + err.expected + ' but actually: ' + err.actual);
throw err;
}
});
};

0 comments on commit 1f9bddd

Please sign in to comment.