From 88db1794d23826204a2ca4ba2dd505d72b9a0abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Cruz?= Date: Sun, 17 Feb 2013 11:09:50 +0000 Subject: [PATCH] Better grunt test labels. --- test/grunt.js | 912 +++++++++++++++++++++++++------------------------- 1 file changed, 457 insertions(+), 455 deletions(-) diff --git a/test/grunt.js b/test/grunt.js index 5b47694..19bb01d 100644 --- a/test/grunt.js +++ b/test/grunt.js @@ -11,584 +11,586 @@ var expect = require('expect.js'), module.exports = function (automaton) { var target = __dirname + '/tmp/grunt/'; - describe('Grunt Runner', function () { - var runner; + describe('Grunt', function () { + describe('Runner', function () { + var runner; - before(function () { - runner = new Runner(); - }); + before(function () { + runner = new Runner(); + }); - beforeEach(function () { - fs.mkdirSync(target, '0777'); - }); + beforeEach(function () { + fs.mkdirSync(target, '0777'); + }); - it('should run grunt tasks (multi task)', function (done) { - var opts = {}, - stack = []; + it('should run grunt tasks (multi task)', function (done) { + var opts = {}, + stack = []; - opts[target] = __dirname + '/helpers/assets/file2'; + opts[target] = __dirname + '/helpers/assets/file2'; - runner.run('copy', { - files: opts - }, null).on('end', function (err) { - if (err) { - throw err; - } + runner.run('copy', { + files: opts + }, null).on('end', function (err) { + if (err) { + throw err; + } - stack.push(1); - expect(isDir(target)).to.be(true); - expect(isFile(target + 'file2')).to.be(true); - }); + stack.push(1); + expect(isDir(target)).to.be(true); + expect(isFile(target + 'file2')).to.be(true); + }); - opts = {}; - opts[target] = __dirname + '/helpers/assets/file1.json'; - runner.run('copy', { - files: opts - }, null).on('end', function (err) { - if (err) { - throw err; - } - - stack.push(2); - expect(isDir(target)).to.be(true); - expect(isFile(target + 'file1.json')).to.be(true); - expect(stack).to.eql([1, 2]); - - done(); - }); - }); + opts = {}; + opts[target] = __dirname + '/helpers/assets/file1.json'; + runner.run('copy', { + files: opts + }, null).on('end', function (err) { + if (err) { + throw err; + } - it('should run grunt task (not multi task)', function (done) { - runner.run('dummy-single', { - file: target + 'dummy' - }, { - tasks: [__dirname + '/helpers/tasks'] - }).on('end', function (err) { - if (err) { - throw err; - } - - expect(isDir(target)).to.be(true); - expect(isFile(target + 'dummy')).to.be(true); - }); + stack.push(2); + expect(isDir(target)).to.be(true); + expect(isFile(target + 'file1.json')).to.be(true); + expect(stack).to.eql([1, 2]); - runner.run('dummy-single', { - file: target + 'dummy2' - }, { - tasks: [__dirname + '/helpers/tasks'] - }).on('end', function (err) { - if (err) { - throw err; - } - - expect(isDir(target)).to.be(true); - expect(isFile(target + 'dummy2')).to.be(true); - done(); + done(); + }); }); - }); - it('should emit "start", "data", and "end" events', function (done) { - var opts = {}, - stack = [], - stack2 = [], - emitter; + it('should run grunt task (not multi task)', function (done) { + runner.run('dummy-single', { + file: target + 'dummy' + }, { + tasks: [__dirname + '/helpers/tasks'] + }).on('end', function (err) { + if (err) { + throw err; + } - opts[target] = __dirname + '/helpers/assets/file2'; + expect(isDir(target)).to.be(true); + expect(isFile(target + 'dummy')).to.be(true); + }); - emitter = runner.run('copy', { - files: opts - }, null).on('end', function (err) { - if (err) { - throw err; - } + runner.run('dummy-single', { + file: target + 'dummy2' + }, { + tasks: [__dirname + '/helpers/tasks'] + }).on('end', function (err) { + if (err) { + throw err; + } - expect(stack[0]).to.equal('start'); - expect(stack[1]).to.equal('data'); + expect(isDir(target)).to.be(true); + expect(isFile(target + 'dummy2')).to.be(true); + done(); + }); }); - emitter - .on('start', function () { stack.push('start'); }) - .on('data', function () { stack.push('data'); }); + it('should emit "start", "data", and "end" events', function (done) { + var opts = {}, + stack = [], + stack2 = [], + emitter; - opts = {}; - opts[target] = __dirname + '/helpers/assets/filethatwillneverexist'; + opts[target] = __dirname + '/helpers/assets/file2'; - emitter = runner.run('not_loaded_task', { - files: opts - }, null).on('end', function (err) { - expect(err).to.be.an(Error); - expect(stack2[0]).to.equal('start'); - - done(); - }); + emitter = runner.run('copy', { + files: opts + }, null).on('end', function (err) { + if (err) { + throw err; + } - emitter - .on('start', function () { stack2.push('start'); }) - .on('data', function () { stack2.push('data'); }); - }); + expect(stack[0]).to.equal('start'); + expect(stack[1]).to.equal('data'); + }); - it('should emit "error" event', function (done) { - var runner = new Runner(), - error; + emitter + .on('start', function () { stack.push('start'); }) + .on('data', function () { stack.push('data'); }); - fs.renameSync(__dirname + '/../node_modules/grunt', __dirname + '/../node_modules/grunt_'); + opts = {}; + opts[target] = __dirname + '/helpers/assets/filethatwillneverexist'; - // when grunt is not found, an error is emitted - runner.run('bleh', {}, null) - .on('error', function (err) { - error = err.message; - }) - .on('end', function (err) { - fs.renameSync(__dirname + '/../node_modules/grunt_', __dirname + '/../node_modules/grunt'); + emitter = runner.run('not_loaded_task', { + files: opts + }, null).on('end', function (err) { + expect(err).to.be.an(Error); + expect(stack2[0]).to.equal('start'); - expect(err).to.be.an(Error); - expect(error).to.be.a('string'); - expect(error).to.contain('find grunt'); + done(); + }); - done(); + emitter + .on('start', function () { stack2.push('start'); }) + .on('data', function () { stack2.push('data'); }); }); - }); - it('should emit "end" with error if task failed', function (done) { - runner.run('copy', { - files: { - 'wtv': 'filethatwillneverexist' - } - }, null).on('end', function (err) { - expect(err).to.be.an(Error); - expect(err.message).to.contain('grunt'); + it('should emit "error" event', function (done) { + var runner = new Runner(), + error; - done(); - }); - }); + fs.renameSync(__dirname + '/../node_modules/grunt', __dirname + '/../node_modules/grunt_'); - it('should pass the grunt config (and not inherit from others)', function (done) { - runner.run('copy', { - files: { - 'wtv': 'filethatwillneverexist' - } - }, { force: true }).on('end', function (err) { - if (err) { - throw err; - } - }); + // when grunt is not found, an error is emitted + runner.run('bleh', {}, null) + .on('error', function (err) { + error = err.message; + }) + .on('end', function (err) { + fs.renameSync(__dirname + '/../node_modules/grunt_', __dirname + '/../node_modules/grunt'); - runner.run('copy', { - files: { - 'wtv': 'filethatwillneverexist' - } - }, null).on('end', function (err) { - expect(err).to.be.an(Error); - expect(err.message).to.contain('grunt'); + expect(err).to.be.an(Error); + expect(error).to.be.a('string'); + expect(error).to.contain('find grunt'); - done(); + done(); + }); }); - }); - it('should kill the worker', function (done) { - this.timeout(5000); - - var opts = {}; - opts[target] = __dirname + '/helpers/assets/file2'; + it('should emit "end" with error if task failed', function (done) { + runner.run('copy', { + files: { + 'wtv': 'filethatwillneverexist' + } + }, null).on('end', function (err) { + expect(err).to.be.an(Error); + expect(err.message).to.contain('grunt'); - runner.run('copy', { - files: opts - }, null).on('end', function () { - throw new Error('Should have killed!'); + done(); + }); }); - runner.kill(); - setTimeout(function () { - opts = {}; - opts[target] = __dirname + '/helpers/assets/file1.json'; - + it('should pass the grunt config (and not inherit from others)', function (done) { runner.run('copy', { - files: opts - }, null).on('end', function (err) { + files: { + 'wtv': 'filethatwillneverexist' + } + }, { force: true }).on('end', function (err) { if (err) { throw err; } + }); - expect(isDir(target)).to.be(true); - expect(isFile(target + 'file1.json')).to.be(true); + runner.run('copy', { + files: { + 'wtv': 'filethatwillneverexist' + } + }, null).on('end', function (err) { + expect(err).to.be.an(Error); + expect(err.message).to.contain('grunt'); done(); }); - }, 4000); + }); + + it('should kill the worker', function (done) { + this.timeout(5000); + + var opts = {}; + opts[target] = __dirname + '/helpers/assets/file2'; + + runner.run('copy', { + files: opts + }, null).on('end', function () { + throw new Error('Should have killed!'); + }); + + runner.kill(); + setTimeout(function () { + opts = {}; + opts[target] = __dirname + '/helpers/assets/file1.json'; + + runner.run('copy', { + files: opts + }, null).on('end', function (err) { + if (err) { + throw err; + } + + expect(isDir(target)).to.be(true); + expect(isFile(target + 'file1.json')).to.be(true); + + done(); + }); + }, 4000); + }); }); - }); - describe('Grunt integration', function () { - it('should respect task order', function (done) { - var opts = {}, - opts2 = {}, - stack = []; - - opts[target] = __dirname + '/helpers/assets/file2'; - opts2[target] = __dirname + '/helpers/assets/file1.json'; - - automaton.run({ - tasks: [ - { - task: 'callback', - options: { - callback: function () { - stack.push(1); + describe('Integration', function () { + it('should respect task order', function (done) { + var opts = {}, + opts2 = {}, + stack = []; + + opts[target] = __dirname + '/helpers/assets/file2'; + opts2[target] = __dirname + '/helpers/assets/file1.json'; + + automaton.run({ + tasks: [ + { + task: 'callback', + options: { + callback: function () { + stack.push(1); + } } - } - }, - { - task: 'copy', - grunt: true, - options: { - files: opts - } - }, - { - task: 'copy', - grunt: true, - options: { - files: opts2 - } - }, - { - task: 'callback', - options: { - callback: function () { - stack.push(2); + }, + { + task: 'copy', + grunt: true, + options: { + files: opts + } + }, + { + task: 'copy', + grunt: true, + options: { + files: opts2 + } + }, + { + task: 'callback', + options: { + callback: function () { + stack.push(2); + } } } + ] + }, null, function (err) { + if (err) { + throw err; } - ] - }, null, function (err) { - if (err) { - throw err; - } - - expect(stack).to.eql([1, 2]); - expect(isDir(target)).to.be(true); - expect(isFile(target + 'file2')).to.be(true); - expect(isFile(target + 'file1.json')).to.be(true); - - done(); + + expect(stack).to.eql([1, 2]); + expect(isDir(target)).to.be(true); + expect(isFile(target + 'file2')).to.be(true); + expect(isFile(target + 'file1.json')).to.be(true); + + done(); + }); }); - }); - it('should log indented output', function (done) { - var opts = {}, - log = ''; + it('should log indented output', function (done) { + var opts = {}, + log = ''; - opts[target] = __dirname + '/helpers/assets/file2'; + opts[target] = __dirname + '/helpers/assets/file2'; - automaton.run({ - tasks: [ - { - task: 'copy', - grunt: true, - options: { - files: opts + automaton.run({ + tasks: [ + { + task: 'copy', + grunt: true, + options: { + files: opts + } } + ] + }, null, function (err) { + var x, + lines; + + if (err) { + throw err; } - ] - }, null, function (err) { - var x, - lines; - - if (err) { - throw err; - } - - lines = removeColors(log).split('\n'); - for (x = 1; x < lines.length; ++x) { - if (lines[x] && lines[x].charAt(0) !== ' ') { - throw new Error('Indentation not respected.'); + + lines = removeColors(log).split('\n'); + for (x = 1; x < lines.length; ++x) { + if (lines[x] && lines[x].charAt(0) !== ' ') { + throw new Error('Indentation not respected.'); + } } - } - done(); - }) - .on('data', function (data) { log += data; }); - }); + done(); + }) + .on('data', function (data) { log += data; }); + }); - it('should pass grunt config', function (done) { - var opts = {}; + it('should pass grunt config', function (done) { + var opts = {}; - opts[target] = __dirname + '/helpers/assets/filethatwillneverexist'; + opts[target] = __dirname + '/helpers/assets/filethatwillneverexist'; - automaton.run({ - tasks: [ - { - task: 'copy', - grunt: { - force: true - }, - options: { - files: opts + automaton.run({ + tasks: [ + { + task: 'copy', + grunt: { + force: true + }, + options: { + files: opts + } } + ] + }, null, function (err) { + // the file does not exist but we use force: true, + // so grunt should not complain about it + if (err) { + throw err; } - ] - }, null, function (err) { - // the file does not exist but we use force: true, - // so grunt should not complain about it - if (err) { - throw err; - } - - done(); + + done(); + }); }); - }); - it('should not inherit previous grunt config', function (done) { - var opts = {}; + it('should not inherit previous grunt config', function (done) { + var opts = {}; - opts[target] = __dirname + '/helpers/assets/filethatwillneverexist'; + opts[target] = __dirname + '/helpers/assets/filethatwillneverexist'; - automaton.run({ - tasks: [ - { - task: 'copy', - grunt: { - force: true + automaton.run({ + tasks: [ + { + task: 'copy', + grunt: { + force: true + }, + options: { + files: opts + } }, - options: { - files: opts - } - }, - { - task: 'copy', - grunt: true, - options: { - files: opts + { + task: 'copy', + grunt: true, + options: { + files: opts + } } - } - ] - }, null, function (err) { - expect(err).to.be.an(Error); - expect(err.message).to.contain('grunt'); + ] + }, null, function (err) { + expect(err).to.be.an(Error); + expect(err.message).to.contain('grunt'); - done(); + done(); + }); }); - }); - it('should integrate well with options replacement', function (done) { - var opts = {}; + it('should integrate well with options replacement', function (done) { + var opts = {}; - opts[target] = __dirname + '/helpers/assets/{{file}}'; + opts[target] = __dirname + '/helpers/assets/{{file}}'; - automaton.run({ - tasks: [ - { - task: 'copy', - grunt: true, - options: { - files: opts + automaton.run({ + tasks: [ + { + task: 'copy', + grunt: true, + options: { + files: opts + } } + ] + }, { file: 'file2' }, function (err) { + if (err) { + throw err; } - ] - }, { file: 'file2' }, function (err) { - if (err) { - throw err; - } - expect(isDir(target)).to.be(true); - expect(isFile(target + 'file2')).to.be(true); + expect(isDir(target)).to.be(true); + expect(isFile(target + 'file2')).to.be(true); - done(); + done(); + }); }); - }); - it('should integrate well with fatal', function (done) { - var opts = {}; + it('should integrate well with fatal', function (done) { + var opts = {}; - opts[target] = __dirname + '/helpers/assets/filethatwillneverexist'; + opts[target] = __dirname + '/helpers/assets/filethatwillneverexist'; - automaton.run({ - tasks: [ - { - task: 'copy', - grunt: true, - fatal: false, - options: { - files: opts - } - } - ] - }, null, function (err) { - // the file does not exist but we pass fatal: false - // so autoamton should not complain about it - if (err) { - throw err; - } - - // test without fatal automaton.run({ tasks: [ { task: 'copy', grunt: true, + fatal: false, options: { files: opts } } ] }, null, function (err) { - expect(err).to.be.an(Error); - done(); + // the file does not exist but we pass fatal: false + // so autoamton should not complain about it + if (err) { + throw err; + } + + // test without fatal + automaton.run({ + tasks: [ + { + task: 'copy', + grunt: true, + options: { + files: opts + } + } + ] + }, null, function (err) { + expect(err).to.be.an(Error); + done(); + }); }); }); - }); - it('should integrate well with mute', function (done) { - var opts = {}, - log = ''; + it('should integrate well with mute', function (done) { + var opts = {}, + log = ''; - opts[target] = __dirname + '/helpers/assets/file2'; + opts[target] = __dirname + '/helpers/assets/file2'; - automaton.run({ - tasks: [ - { - task: 'copy', - grunt: true, - mute: true, - options: { - files: opts + automaton.run({ + tasks: [ + { + task: 'copy', + grunt: true, + mute: true, + options: { + files: opts + } } - } - ] - }, null, function (err) { - var lines; + ] + }, null, function (err) { + var lines; - if (err) { - throw err; - } + if (err) { + throw err; + } - lines = removeColors(log).split('\n'); - expect(lines.length <= 2).to.equal(true); + lines = removeColors(log).split('\n'); + expect(lines.length <= 2).to.equal(true); - done(); - }) - .on('data', function (data) { log += data; }); - }); + done(); + }) + .on('data', function (data) { log += data; }); + }); - it('should integrate well with on', function (done) { - var opts = {}; + it('should integrate well with on', function (done) { + var opts = {}; - opts[target] = __dirname + '/helpers/assets/file2}'; + opts[target] = __dirname + '/helpers/assets/file2}'; - automaton.run({ - tasks: [ - { - task: 'copy', - grunt: true, - on: false, - options: { - files: opts + automaton.run({ + tasks: [ + { + task: 'copy', + grunt: true, + on: false, + options: { + files: opts + } } + ] + }, null, function (err) { + if (err) { + throw err; } - ] - }, null, function (err) { - if (err) { - throw err; - } - - expect(isDir(target)).to.be(false); - done(); + + expect(isDir(target)).to.be(false); + done(); + }); }); - }); - it('should load tasks specified in the grunt config', function (done) { - var log = ''; + it('should load tasks specified in the grunt config', function (done) { + var log = ''; - automaton.run({ - tasks: [ - { - task: 'dummy', - grunt: { - tasks: __dirname + '/helpers/tasks' + automaton.run({ + tasks: [ + { + task: 'dummy', + grunt: { + tasks: __dirname + '/helpers/tasks' + } } + ] + }, null, function (err) { + if (err) { + throw err; } - ] - }, null, function (err) { - if (err) { - throw err; - } - - expect(log).to.contain('dummy'); - done(); - }) - .on('data', function (data) { log += data; }); - }); - it('should autoload npm tasks and tasks located in tasks/', function (done) { - var log = '', - dummyTask = process.cwd() + '/tasks/grunt-dummy.js'; + expect(log).to.contain('dummy'); + done(); + }) + .on('data', function (data) { log += data; }); + }); - // the autoload npm tasks is not necessary to test because the tests above ensure it (copy task) - // so this test must only assert the autoload of tasks/ + it('should autoload npm tasks and tasks located in tasks/', function (done) { + var log = '', + dummyTask = process.cwd() + '/tasks/grunt-dummy.js'; - // copy the dummy grunt task to tasks/ - fs.writeFileSync(dummyTask, fs.readFileSync(__dirname + '/helpers/tasks/grunt-dummy.js')); + // the autoload npm tasks is not necessary to test because the tests above ensure it (copy task) + // so this test must only assert the autoload of tasks/ - automaton.run({ - tasks: [ - { - task: 'dummy', - grunt: true - } - ] - }, null, function (err) { - fs.unlinkSync(dummyTask); - - if (err) { - throw err; - } - - expect(log).to.contain('dummy'); - done(); - }) - .on('data', function (data) { log += data; }); - }); + // copy the dummy grunt task to tasks/ + fs.writeFileSync(dummyTask, fs.readFileSync(__dirname + '/helpers/tasks/grunt-dummy.js')); - it('should error when task is not loaded', function (done) { - var log = ''; + automaton.run({ + tasks: [ + { + task: 'dummy', + grunt: true + } + ] + }, null, function (err) { + fs.unlinkSync(dummyTask); - automaton.run({ - tasks: [ - { - task: 'taskthatwillneverexist', - grunt: true + if (err) { + throw err; } - ] - }, null, function (err) { - expect(err).to.be.an(Error); - expect(err.message).to.contain('not loaded'); - - done(); - }) - .on('data', function (data) { log += data; }); - }); - it('should error when grunt is not loaded', function (done) { - var log = ''; + expect(log).to.contain('dummy'); + done(); + }) + .on('data', function (data) { log += data; }); + }); - fs.renameSync(__dirname + '/../node_modules/grunt', __dirname + '/../node_modules/grunt_'); + it('should error when task is not loaded', function (done) { + var log = ''; - automaton.run({ - tasks: [ - { - task: 'taskthatwillneverexist', - grunt: true - } - ] - }, null, function (err) { - fs.renameSync(__dirname + '/../node_modules/grunt_', __dirname + '/../node_modules/grunt'); + automaton.run({ + tasks: [ + { + task: 'taskthatwillneverexist', + grunt: true + } + ] + }, null, function (err) { + expect(err).to.be.an(Error); + expect(err.message).to.contain('not loaded'); + + done(); + }) + .on('data', function (data) { log += data; }); + }); + + it('should error when grunt is not loaded', function (done) { + var log = ''; + + fs.renameSync(__dirname + '/../node_modules/grunt', __dirname + '/../node_modules/grunt_'); + + automaton.run({ + tasks: [ + { + task: 'taskthatwillneverexist', + grunt: true + } + ] + }, null, function (err) { + fs.renameSync(__dirname + '/../node_modules/grunt_', __dirname + '/../node_modules/grunt'); - expect(err).to.be.an(Error); - expect(log).to.contain('find grunt'); + expect(err).to.be.an(Error); + expect(log).to.contain('find grunt'); - done(); - }) - .on('data', function (data) { log += data; }); + done(); + }) + .on('data', function (data) { log += data; }); + }); }); }); }; \ No newline at end of file