From cfafece1ff63a78495a6443220da9e574b91b759 Mon Sep 17 00:00:00 2001 From: Mickael Daniel Date: Sun, 16 Sep 2012 23:09:40 +0200 Subject: [PATCH] test - add tests for bower task --- cli/test/helpers/index.js | 6 +-- cli/test/test-bower.js | 96 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 cli/test/test-bower.js diff --git a/cli/test/helpers/index.js b/cli/test/helpers/index.js index 49744e8d..523ef329 100644 --- a/cli/test/helpers/index.js +++ b/cli/test/helpers/index.js @@ -48,11 +48,7 @@ helpers.run = function run(cmds, opts) { // Returns a function suitable to use with mocha's before/after hooks. helpers.directory = function directory(dir) { return function directory(done) { - var cwd = process.cwd(), - dirname = path.basename(cwd); - - if(dirname === dir) return done(); - + process.chdir(path.join(__dirname, '../..')); rimraf(dir, function(err) { if(err) return done(err); mkdirp(dir, function(err) { diff --git a/cli/test/test-bower.js b/cli/test/test-bower.js new file mode 100644 index 00000000..94dc5447 --- /dev/null +++ b/cli/test/test-bower.js @@ -0,0 +1,96 @@ +/*globals describe, it, before, after, beforeEach, afterEach */ +var fs = require('fs'), + path = require('path'), + grunt = require('grunt'), + assert = require('assert'), + helpers = require('./helpers'), + bower = require('bower').commands; + +// bower components to test out +var components = ['jquery', 'backbone']; +// var components = ['jquery', 'backbone', 'ember', 'angular', 'canjs']; + +describe('Bower install packages', function() { + + before(helpers.directory('.test')); + + before(helpers.gruntfile({ + foo: { + bar: '' + } + })); + + before(function(done) { + var yeoman = helpers.run('init --force'); + yeoman + // enter '\n' for both prompts, and grunt confirm + .prompt(/would you like/i) + .prompt(/Do you need to make any changes to the above before continuing?/) + // check exit code + .expect(0) + // run and done + .end(done); + }); + + components.forEach(function(name) { + it('should install ' + name + ' with yeoman install ' + name, function(done) { + console.log(); + helpers.run('install ' + name, { redirect: true }) + .expect(0) + .end(done); + }); + + + it('should have copied resolved components to app/scripts/vendor', function(done) { + var ctx = this; + bower.list({ map: true }) + .on('error', done) + .on('data', function(results) { + ctx.results = results; + var pkg = results[name]; + var source = ctx[name] = pkg.source.main; + var vendor = source.replace(/^components/, 'app/scripts/vendor'); + fs.stat(vendor, done); + }); + }); + }); + + // These tests are failing, and specifically testing out some current issues + // we might have. + + /* * / + describe('should not override non "components" files in app/scripts/vendor', function(done) { + ['esprima.js', 'hm.js', 'jquery.min.js', 'modernizr.min.js', 'require.js'].forEach(function(file) { + it('like ' + file, function(done) { + fs.stat(path.join('app/scripts/vendor', file), done); + }); + }); + }); + /* */ + + /* * / + describe('should have updated the RequireJS configuration for paths', function() { + + before(function() { + this.main = grunt.file.read('app/scripts/main.js'); + }); + + components.forEach(function(name) { + it('configuration for ' + name + ' is updated', function() { + var source = this[name]; + // map the bower resolved package to be within vendor/ + var pathname = source.replace(/^components/, 'vendor').replace(path.extname(source), ''); + + // assert string against lines, to gain diff output + var pathline = this.main.split('\n').filter(function(line) { + return line.indexOf(name + ':') !== -1; + })[0]; + + var pattern = name + ": '" + pathname + "',"; + assert.equal(pathline.trim(), pattern); + }); + }); + }); + /* */ + +});