Skip to content
Browse files

Merge pull request #473 from mklabs/tests

Fixes for #450 - remove stdout checks, test against fs
  • Loading branch information...
2 parents 10da16b + cfafece commit c3660c19ffcbd31b8a700aa90ecb12ec904aebca @addyosmani committed Sep 16, 2012
View
2 cli/package.json
@@ -28,7 +28,7 @@
"url": "git://github.com/yeoman/yeoman.git"
},
"scripts": {
- "test": "node node_modules/mocha/bin/mocha test/test-*.js test/generators/",
+ "test": "node node_modules/mocha/bin/mocha test/test-*.js",
"manpages": "./scripts/docs-build"
},
"dependencies": {
View
11 cli/tasks/css.js
@@ -26,7 +26,15 @@ module.exports = function(grunt) {
// concat prior to rjs optimize css, and before min max info
grunt.log.write('Writing css files to ' + target + '...');
- grunt.file.write(target, grunt.helper('mincss', files));
+ var out = grunt.helper('mincss', files);
+ // only go through if their's file to process
+ if(!out) {
+ return cb();
+ }
+
+ // write minified file before going through rjs:optimize to possibly inline
+ // @imports (that are not handled by compass within .scss or .sass files)
+ grunt.file.write(target, out);
// replace @import statements
//
@@ -73,6 +81,5 @@ module.exports = function(grunt) {
});
});
-
};
View
4 cli/tasks/yeoman.js
@@ -40,12 +40,12 @@ module.exports = function(grunt) {
// task internally does this check)
var targets = {
default : ' rjs concat css min img rev usemin manifest',
- usemin : 'usemin-handler rjs concat css img rev usemin manifest',
+ usemin : 'usemin-handler rjs concat css min img rev usemin manifest',
text : 'usemin-handler rjs concat css min rev usemin manifest',
buildkit : 'usemin-handler rjs concat css min img rev usemin manifest html:buildkit',
basics : 'usemin-handler rjs concat css min img rev usemin manifest html:basics',
minify : 'usemin-handler rjs concat css min img rev usemin manifest html:compress',
- test : 'usemin-handler rjs concat css img rev usemin manifest'
+ test : 'usemin-handler rjs concat css min img rev usemin manifest'
};
var targetList = grunt.log.wordlist(Object.keys(targets));
View
1 cli/test/generators/fixtures/foo-template.js
@@ -1 +0,0 @@
-var <%= foo %> = '<%= foo %>';
View
1 cli/test/generators/fixtures/foo.js
@@ -1 +0,0 @@
-var foo = 'foo';
View
232 cli/test/generators/test-actions.js
@@ -1,232 +0,0 @@
-
-var fs = require('fs'),
- path = require('path'),
- util = require('util'),
- events = require('events'),
- rimraf = require('rimraf'),
- assert = require('assert'),
- yeoman = require('../../'),
- grunt = require('grunt');
-
-
-describe('yeoman.generators.Base', function() {
-
- before(function() {
- function Dummy() {
- yeoman.generators.Base.apply(this, arguments);
- }
-
- util.inherits(Dummy, yeoman.generators.Base);
-
- Dummy.prototype.test = function () {
- this.shouldRun = true;
- };
-
- this.dummy = new Dummy;
- this.Dummy = Dummy;
- });
-
- // Initialize task system so that the helpers can be used.
- before(function() {
- grunt.task.init([]);
- });
-
- // cleaup the test dir
- before(function(done) {
- process.chdir(path.join(__dirname, '../../'));
- rimraf('.test', done);
- });
-
- describe('grunt.file API', function() {
- it('should be available in the generator API', function() {
- var methods = Object.keys(grunt.file);
- methods.forEach(function(method) {
- assert.equal(typeof this.dummy[method], typeof grunt.file[method]);
- }, this);
- });
- });
-
- describe('grunt.log API', function() {
- it('should be available in the generator API through this.log property', function() {
- var methods = Object.keys(grunt.log);
- methods.forEach(function(method) {
- assert.equal(typeof this.dummy.log[method], typeof grunt.log[method]);
- }, this);
- });
- });
-
- describe('generator.helper(name, args)', function() {
- it('should be a 1:1 mapping with grunt.helper()', function() {
- assert.equal(grunt.helper, this.dummy.helper);
- });
- });
-
- describe('generator.prompt(defaults, prompts, cb)', function() {
- it('should be a 1:1 mapping with grunt.helper("prompts", ...)', function(done) {
- this.dummy.prompt([], done);
- });
- });
-
- describe('generator.promptForObj()', function() {
- it('should be a 1:1 mapping with grunt.helper("prompt_for_obj")', function() {
- var obj = this.dummy.promptForObj();
-
- // expected props
- var props = [
- 'name',
- 'title',
- 'description',
- 'version',
- 'repository',
- 'homepage',
- 'bugs',
- 'licenses',
- 'author_name',
- 'author_email',
- 'author_url',
- 'jquery_version',
- 'node_version',
- 'main',
- 'bin',
- 'npm_test',
- 'grunt_version'
- ];
-
- props.forEach(function(prop) {
- var prompt = obj[prop];
- assert.ok(prompt);
- assert.ok(prompt.message, 'Undfined message for ' + prop);
- assert.ok(prompt['default'], 'Undfined default for ' + prop);
- });
- });
- });
-
- describe('generator.promptFor(name, default)', function() {
- it('should be a 1:1 mapping with grunt.helper("prompt_for", ...)', function() {
- var obj = this.dummy.promptFor('name');
- assert.equal(obj.message, 'Project name');
-
- obj = this.dummy.promptFor('name', {
- message: 'Enter a project name'
- });
-
- assert.equal(obj.altDefault.message, 'Enter a project name');
- });
- });
-
- describe('generator.sourceRoot(root)', function() {
- it('should update the "_sourceRoot" property when root is given', function() {
- this.dummy.sourceRoot('./test/generators/fixtures');
- assert.equal(this.dummy._sourceRoot, path.resolve('./test/generators/fixtures'));
- });
-
- it('should return the uddated or current value of "_sourceRoot"', function() {
- assert.equal(this.dummy.sourceRoot(), path.resolve('./test/generators/fixtures'));
- });
- });
-
- describe('generator.destinationRoot(root)', function() {
- it('should update the "_destinationRoot" property when root is given', function() {
- this.dummy.destinationRoot('.test');
- assert.equal(this.dummy._destinationRoot, process.cwd());
- });
-
- it('should return the uddated or current value of "_destinationRoot"', function() {
- assert.equal(this.dummy.destinationRoot(), process.cwd());
- });
- });
-
- describe('generator.copy(source, destination, options)', function() {
- it('should copy source files relative to the "sourceRoot" value', function(done) {
- this.dummy.copy('foo.js', 'write/to/foo.js');
- fs.stat('write/to/foo.js', done);
- });
-
- it('should allow absolute path, and prevent the relative paths join', function(done) {
- this.dummy.copy(path.join(__dirname, 'fixtures/foo.js'), 'write/to/bar.js');
- fs.stat('write/to/bar.js', done);
- });
- });
-
- describe('generator.read(filepath, encoding)', function() {
- it('should read files relative to the "sourceRoot" value', function() {
- var body = this.dummy.read('foo.js');
- assert.equal(body, 'var foo = \'foo\';\n');
- });
- it('should allow absolute path, and prevent the relative paths join', function() {
- var body = this.dummy.read(path.join(__dirname, 'fixtures/foo.js'));
- assert.equal(body, 'var foo = \'foo\';\n');
- });
- });
-
- describe('generator.write(filepath, content)', function() {
- it('should write the specified files relative to the "destinationRoot" value', function(done) {
- var body = 'var bar = \'bar\';\n';
- this.dummy.write('write/to/bar.js', body);
- fs.readFile('write/to/bar.js', 'utf8', function(err, actual) {
- if(err) return done(err);
- assert.ok(actual, body);
- done();
- });
- });
- });
-
- describe('generator.template(source, destination, data)', function() {
-
- before(function() {
- this.dummy.foo = 'fooooooo';
- });
-
- it('should copy and process source file to destination', function(done) {
- this.dummy.template('foo-template.js', 'write/to/from-template.js');
- fs.stat('write/to/from-template.js', done);
- });
-
- it('should defaults the destination to the source filepath value, relative to "destinationRoot" value', function() {
- this.dummy.template('foo-template.js');
- var body = fs.readFileSync('foo-template.js', 'utf8');
- assert.equal(body, 'var fooooooo = \'fooooooo\';\n');
- });
-
- it('should process underscore templates with the passed-in data', function() {
- this.dummy.template('foo-template.js', 'write/to/from-template.js', {
- foo: 'bar'
- });
- var body = fs.readFileSync('write/to/from-template.js', 'utf8');
- assert.equal(body, 'var bar = \'bar\';\n');
- });
-
- it('should process underscore templates with the actual generator instance, when no data is given', function() {
- this.dummy.template('foo-template.js', 'write/to/from-template.js');
- var body = fs.readFileSync('write/to/from-template.js', 'utf8');
- assert.equal(body, 'var fooooooo = \'fooooooo\';\n');
- });
- });
-
- describe('generator.directory(source, destination)', function() {
-
- it('should copy and process source files to destination', function(done) {
- this.dummy.directory('./', 'directory');
- fs.stat('directory/foo-template.js', function(err) {
- if(err) return done(err);
- fs.stat('directory/foo.js', done);
- });
- });
-
- it('should defaults the destination to the source filepath value, relative to "destinationRoot" value', function(done) {
- this.dummy.directory('./');
- fs.stat('foo-template.js', function(err) {
- if(err) return done(err);
- fs.stat('foo.js', done);
- });
- });
-
-
- it('should process underscore templates with the actual generator instance', function() {
- var body = fs.readFileSync('directory/foo-template.js', 'utf8');
- var foo = this.dummy.foo;
- assert.equal(body, 'var ' + foo + ' = \'' + foo + '\';\n');
- });
- });
-
-});
View
178 cli/test/generators/test-base.js
@@ -1,178 +0,0 @@
-
-var fs = require('fs'),
- path = require('path'),
- util = require('util'),
- events = require('events'),
- assert = require('assert'),
- rimraf = require('rimraf'),
- mkdirp = require('mkdirp'),
- yeoman = require('../../'),
- grunt = require('grunt');
-
-describe('yeoman.generators.Base', function() {
-
- before(function() {
- function Dummy() {
- yeoman.generators.Base.apply(this, arguments);
- }
-
- util.inherits(Dummy, yeoman.generators.Base);
-
- Dummy.prototype.test = function () {
- this.shouldRun = true;
- };
-
- this.dummy = new Dummy(['bar', 'baz', 'bom'], {
- foo: true,
- something: 'else'
- });
- this.Dummy = Dummy;
-
- // actual generator
- this.generator = yeoman.generators.setup(grunt)
- .create('app', [], {}, {});
- });
-
- // cleaup the test dir, and cd into it
- before(function(done) {
- process.chdir(path.join(__dirname, '../../'));
- rimraf('.test', function(err) {
- if(err) return done(err);
- mkdirp('.test', function() {
- if(err) return done(err);
- process.chdir('.test');
- done();
- });
- });
- });
-
- describe('generator.run(args, cb)', function() {
- it('should run all methods in the given generator', function() {
- this.dummy.run();
- });
-
- it('should have the _running flag turned on', function() {
- assert.ok(this.dummy._running);
- });
- });
-
- describe('generator.runHooks(cb)', function() {
- it('should go through all registered hooks, and invoke them in series', function(done) {
- this.generator.runHooks(function(err) {
- if(err) return err;
- fs.stat('test/index.html', done);
- });
- });
- });
-
- describe('generator.argument(name, config)', function() {
- it('should add a new argument to the generator instance', function() {
- assert.equal(this.dummy._arguments.length, 0);
- this.dummy.argument('foo');
- assert.equal(this.dummy._arguments.length, 1);
- });
-
- it('should create the property specified with value from positional args', function() {
- assert.equal(this.dummy.foo, 'bar');
- });
-
- it('should slice positional arguments when config.type is Array', function() {
- this.dummy.argument('bar', {
- type: Array
- });
-
- assert.deepEqual(this.dummy.bar, ['baz', 'bom']);
- });
- });
-
- describe('generator.option(name, config)', function() {
- it('should add a new option to the set of generator expected options', function() {
- // every generator have the --help options
- assert.equal(this.dummy._options.length, 1);
- this.dummy.option('foo');
- assert.equal(this.dummy._options.length, 2);
- assert.deepEqual(this.dummy._options.pop(), {
- desc: 'Description for foo',
- name: 'foo',
- type: Boolean,
- defaults: false,
- hide: false
- });
- });
- });
-
- describe('generator.hookFor(name, config)', function() {
- it('should emit errors if called when running', function() {
- try {
- this.dummy.hookFor('maoow');
- } catch(e) {
- assert.equal(e.message, 'hookFor must be used within the constructor only');
- }
- });
-
- it('should create the macthing option', function() {
- this.dummy._running = false;
- this.dummy.hookFor('something');
- assert.deepEqual(this.dummy._options.pop(), {
- desc: 'Something to be invoked',
- name: 'something',
- type: Boolean,
- defaults: 'else',
- hide: false
- });
- });
-
- it('should update the internal hooks holder', function() {
- assert.deepEqual(this.dummy._hooks.pop(), {
- name: 'something'
- });
- });
- });
-
- describe('generator.defaultFor(config)', function() {
- it('should return the value for the option name, doing lookup in options and Grunt config', function() {
- var name = this.dummy.defaultFor('something');
- assert.equal(name, 'else');
- });
- });
-
- describe('generator.desc(decription)', function() {
- it('should update the internal description', function() {
- this.dummy.desc('A new desc for this generator');
- assert.equal(this.dummy.description, 'A new desc for this generator');
- });
- });
-
- describe('generator.help()', function() {
- it('should return the expected help / usage output', function() {
- this.dummy.option('ooOoo');
- var help = this.dummy.help();
-
- assert.ok(help.match('Usage:'));
- assert.ok(help.match('yeoman init FOO one two three \\[options\\]'));
- assert.ok(help.match('A new desc for this generator'));
- assert.ok(help.match('Options:'));
- assert.ok(help.match(' -h, --help # Print generator\'s options and usage'));
- assert.ok(help.match(' --ooOoo # Description for ooOoo'));
- });
- });
-
- describe('generator.usage()', function() {
- it('should return the expected help / usage output', function() {
- var usage = this.dummy.usage();
- assert.equal(usage, 'yeoman init FOO one two three [options]\n\nA new desc for this generator');
- });
- });
-
- describe('generator.optionsHelp()', function() {
- it('should return the expected help / usage output', function() {
- var help = this.dummy.optionsHelp();
- assert.equal(help, [
- ' -h, --help # Print generator\'s options and usage ',
- ' # Default: false',
- ' --ooOoo # Description for ooOoo ',
- ' # Default: false'
- ].join('\n'));
- });
- });
-});
View
53 cli/test/generators/test-fetch.js
@@ -1,53 +0,0 @@
-
-var util = require('util'),
- events = require('events'),
- assert = require('assert'),
- yeoman = require('../../');
-
-describe('yeoman.generators.Base', function() {
-
- before(function() {
- function Dummy() {
- yeoman.generators.Base.apply(this, arguments);
- }
-
- util.inherits(Dummy, yeoman.generators.Base);
-
- Dummy.prototype.test = function () {
- this.shouldRun = true;
- };
-
- this.dummy = new Dummy;
- this.Dummy = Dummy;
- });
-
- describe('generator.tarball(tarball, destination, cb)', function() {
- it('should allow the fecthing / untar of a given tarball, at the given location');
- });
-
- describe('generator.fetch(url, destination, cb)', function() {
- it('should allow the fething of a single file');
- it('should write at the specified location');
- });
-
- describe('generator.remote(user, repo, branch, cb)', function() {
- it('should remotely fetch a package on github');
- it('should have the result cached internally into a `_cache` folder');
- it('should invoke `cb` with a remote object to interract with the downloaded package');
-
- describe('remote.copy(source, destination, options)', function() {
- it('should copy a given file from package at the given destination');
- });
-
- describe('remote.template(source, destination, data)', function() {
- it('should copy and process a given template file from package at the given destination');
- });
-
- describe('remote.directory(source, destination, options)', function() {
- it('should recursively process and copy source directory from downloaded package');
- it('should write files at the given destination');
- });
-
- });
-
-});
View
173 cli/test/generators/test-generators.js
@@ -1,173 +0,0 @@
-
-var path = require('path'),
- events = require('events'),
- assert = require('assert'),
- yeoman = require('../../'),
- rimraf = require('rimraf'),
- mkdirp = require('mkdirp'),
- grunt = require('grunt');
-
-describe('Generators', function() {
-
- before(function(done) {
- var cwd = process.cwd(),
- dirname = path.basename(cwd);
-
- if(dirname === '.test') return done();
-
- rimraf('.test', function(err) {
- if(err) return done(err);
- mkdirp('.test', function(err) {
- if(err) return done(err);
- process.chdir('.test');
- done();
- });
- });
- });
-
- describe('yeoman.generators', function() {
- it('should have a Base object to extend from', function() {
- assert.ok(yeoman.generators.Base);
- });
-
- it('should have a NamedBase object to extend from', function() {
- assert.ok(yeoman.generators.NamedBase);
- });
- });
-
- describe('yeoman.generators.Base', function() {
- before(function() {
- this.generator = new yeoman.generators.Base();
- });
-
- it('should be an EventEmitter', function(done) {
- assert.ok(this.generator instanceof events.EventEmitter);
- assert.ok(typeof this.generator.on === 'function');
- assert.ok(typeof this.generator.emit === 'function');
- this.generator.on('yay-o-man', done);
- this.generator.emit('yay-o-man');
- });
- });
-
- describe('yeoman.generators.NamedBase', function() {
- before(function() {
- this.generator = new yeoman.generators.NamedBase(['namedArg']);
- });
-
- it('should be a Base generator', function() {
- assert.ok(this.generator instanceof yeoman.generators.Base);
- });
-
- it('and it should have a name property', function() {
- assert.equal(this.generator.name, 'namedArg');
- });
- });
-
- describe('yeoman.generators.prepare', function() {
-
- before(function() {
- grunt.cli.tasks = ['init', 'generatorname', 'some', 'args'];
- grunt.cli.options = {
- foo: 'bar',
- bar: 'baz'
- };
-
- yeoman.generators.prepare(grunt);
-
- this.generators = yeoman.generators;
- this.tasks = grunt.cli.tasks;
- this.options = grunt.cli.options;
- });
-
- it('should parse out grunt.cli for arguments and options', function() {
- assert.deepEqual(this.generators.args, ['some', 'args']);
- });
-
-
- it('should setup the invoked generator name from arguments', function() {
- assert.equal(this.generators.name, 'generatorname');
- });
-
- it('should setup the hash options from grunt.cli.options', function() {
- assert.deepEqual(this.generators.options, {
- foo: 'bar',
- bar: 'baz'
- });
- });
-
- it('should prefix each positional arguments with `init:`', function() {
- assert.deepEqual(this.tasks, ['init:yeoman', 'init:generatorname', 'init:some', 'init:args']);
- });
-
- it('and turn off the internal grunt help output', function() {
- assert.equal(this.options.help, false);
- assert.equal(typeof this.generators.options.help, 'undefined');
- });
- });
-
- //
- // Comment out this step. To be re-added when the generators test suite is
- // moved to its repo. Mainly because of prompt now in app generator, should
- // be tested by the global test-build.js suite with the Runnable helper.
-
- // describe('yeoman.generators.init', function() {
-
- // before(function(done) {
- // yeoman.generators.name = 'app';
- // yeoman.generators.args = ['.test'];
- // this.cwd = process.cwd();
- // this.generator = yeoman.generators.init(grunt);
- // this.generators = yeoman.generators;
- // assert.ok(this.generator, 'init app should return the specified generator');
- // this.generator.on('end', done);
- // });
-
- // it('should setup the current working directory property', function() {
- // assert.equal(this.generators.cwd, this.cwd);
- // });
-
- // it('should find Gruntfile throughout the file tree');
- // it('should setup the base property and cd into that directory');
- // it('should try to locate installed yeoman plugins');
- // it('should ouptut help when no generator name is given');
- // });
-
- describe('yeoman.generators.help', function() {
- it('should output according help / usage');
- });
-
- describe('yeoman.generators.printList', function() {
- it('should output according help / usage');
- });
-
- describe('yeoman.generators.invoke', function() {
- it('should output the list of paths lookup on invalid generator');
- it('should output generator specific help on --help');
- it('should create, invoke and run the specified generator');
- });
-
- describe('yeoman.generators.create', function() {
- it('should return undefined on invalid generators');
- it('should properly create the specified generator');
- it('should have namespace information attached');
- it('should have name / path information attached');
- it('should have hooks registered created and available as `_hooks`');
- });
-
- describe('yeoman.generators.findByNamespace', function() {
- it('should do the necessary lookup and return specified generator');
- });
-
- describe('yeoman.generators.lookup', function() {
- it('should do the necessary lookup and return specified generator');
- });
-
- describe('yeoman.generators.lookupHelp', function() {
- it('should load any generator in the load path and return an array of generators');
- });
-
- describe('yeoman.generators.namespacesToPaths', function() {
- it('should convert namespaces to paths by replacing ":" for "/"');
- });
-
-});
View
8 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) {
@@ -149,8 +145,8 @@ helpers.gruntfile = function(options) {
// Setups the relevant Boolean flag on the test context.
//
helpers.installed = function installed(command, cb) {
- var ctx = this;
return function installed(done) {
+ var ctx = this;
which(command, function(err) {
ctx[command] = !err;
done();
View
96 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: '<config.baz>'
+ }
+ }));
+
+ 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);
+ });
+ });
+ });
+ /* */
+
+});
View
288 cli/test/test-build.js
@@ -1,5 +1,6 @@
/*global describe, before, after, beforeEach, afterEach, describe, it */
var fs = require('fs');
+var path = require('path');
var grunt = require('grunt');
var assert = require('assert');
var helpers = require('./helpers');
@@ -27,48 +28,14 @@ describe('yeoman init && yeoman build', function() {
before(helpers.installed('phantomjs'));
describe('When I run init app with default prompts', function(done) {
- it('should output to stdout expected file writes', function(done) {
+ before(function(done) {
var yeoman = helpers.run('init --force', opts);
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 few pattern in the process stdout
- // Check app generator invoke
- .expect(/Invoke (.+)?app/)
-
- // top level files
- .expect(/Writing Gruntfile\.js/)
- .expect(/Writing package.json/)
-
- // some expected files from h5bp
- .expect(/Writing app\/index\.html/)
- .expect(/Writing app\/404\.html/)
- .expect(/Writing app\/styles\/main\.css/)
- .expect(/Writing app\/scripts\/main\.js/)
-
- // same for bootstrap
- .expect(/Writing app\/scripts\/vendor\/bootstrap\/bootstrap-(.+)\.js/)
-
- // stylesheet hook - sass:app - to be re-added if we decide to go back
- // to use a hook for SASS part of the app generator, or simply delete
- // this line
- //
- // .expect(/Invoke sass:app/)
- .expect(/Writing app\/styles\/main\.scss/)
- .expect(/Writing app\/styles\/_compass_twitter_bootstrap\.scss/)
- .expect(/Writing app\/styles\/compass_twitter_bootstrap\/(.+).scss/)
-
- // test hook - jasmine:app
- .expect(/Invoke mocha:app/)
- .expect(/Writing test\/index\.html/)
- .expect(/Writing test\/lib\/chai\.js/)
- .expect(/Writing test\/lib\/expect\.js/)
- .expect(/Writing test\/lib\/mocha\/mocha\.css/)
- .expect(/Writing test\/lib\/mocha\/mocha\.js/)
- .expect(/Writing test\/runner\/mocha\.js/)*/
-
+ // check exit code
+ .expect(0)
// run and done
.end(done);
});
@@ -108,172 +75,143 @@ describe('yeoman init && yeoman build', function() {
it('should generate a Gruntfile.js file', function(done) {
fs.stat('Gruntfile.js', done);
});
- });
-
-
- describe('And I run a build', function() {
- before(function() {
- var self = this;
- // setup the runnable, the actual run happens on last step
- this.yeoman = helpers.run('build:test --no-color', opts);
- });
-
- afterEach(function(done) {
- this.yeoman.end(done);
- });
-
- it('should run the correct set of task', function() {
- this.yeoman
- .expect(0)
- // intro clean mkdirs coffee compass usemin-handler rjs concat css img rev usemin manifest copy time
- .expect(/Running "build(:.+)?" (\(.+\) )?task/)
- .expect(/Running "clean(:.+)?" (\(.+\) )?task/)
- .expect(/Running "mkdirs(:.+)?" (\(.+\) )?task/)
- .expect(/Running "coffee(:.+)?" (\(.+\) )?task/)
- .expect(/Running "usemin-handler(:.+)?" (\(.+\) )?task/)
- .expect(/Running "rjs(:.+)?" (\(.+\) )?task/)
- .expect(/Running "concat(:.+)?" (\(.+\) )?task/)
- .expect(/Running "css(:.+)?" (\(.+\) )?task/)
- .expect(/Running "img(:.+)?" (\(.+\) )?task/)
- .expect(/Running "rev(:.+)?" (\(.+\) )?task/)
- .expect(/Running "usemin(:.+)?" (\(.+\) )?task/)
- .expect(/Running "copy(:.+)?" (\(.+\) )?task/)
- .expect(/Running "time(:.+)?" (\(.+\) )?task/);
-
- if( this.compass ) {
- this.yeoman.expect(/Running "compass(:.+)?" (\(.+\) )?task/);
- }
-
- if( this.phantomjs ) {
- this.yeoman.expect(/Running "manifest(:.+)?" (\(.+\) )?task/);
- }
- });
-
- describe('build', function() {
- it('should output the list of task at the beginning of the build', function() {
- this.yeoman.expect(/intro clean/);
- this.yeoman.expect(/mkdirs usemin-handler rjs concat css img rev usemin/);
- if( this.compass ) {
- this.yeoman.expect(/compass mkdirs/);
- }
+ describe('And I run a build', function() {
+ before(function() {
+ // setup some very basic coffee setup, to test out
+ // coffee output
+ grunt.file.write('app/scripts/foo.coffee', 'foo = "yeo"');
+ });
- if( this.phantomjs) {
- this.yeoman.expect(/usemin manifest copy/);
- }
+ before(function(done) {
+ // setup the runnable
+ this.yeoman = helpers.run('build:test --no-color', opts)
+ .expect(0)
+ .end(done);
});
- });
- describe('mkdirs', function() {
- it('should copy to the staging directory', function() {
- this.yeoman
- .expect(/Copying into/)
- .expect(/Ignoring .gitignore, .ignore, .buildignore/)
- .expect(/(.+)app -> (.+)temp/);
+ describe('mkdirs', function() {
+ var dirs = ['index.html', 'images/', 'styles/', 'scripts/', 'templates'];
+ dirs.forEach(function(filepath) {
+ it('should copy ' + filepath + ' to the staging directory', function(done) {
+ fs.stat(path.join('temp', filepath), done);
+ });
+ });
});
- });
- describe('coffee', function() {
- it('should go through coffee:dist', function() {
- this.yeoman.expect(/Running "coffee:dist" \(coffee\) task/);
+ describe('coffee', function() {
+ it('should go through coffee:dist', function() {
+ // handled version file, get back filename via grunt globbing
+ var foo = grunt.file.expandFiles('temp/scripts/*.foo.js')[0];
+ assert.equal(grunt.file.read(foo), 'var foo;\n\nfoo = "yeo";\n');
+ assert.equal(grunt.file.read(foo), 'var foo;\n\nfoo = "yeo";\n');
+ });
});
- });
- describe('compass', function() {
- it('should go through compass:dist', function() {
- if( !this.compass ) { return; }
- this.yeoman.expect(/Running "compass:dist" \(compass\) task/);
+ describe('compass', function() {
+ it('should go through compass:dist', function() {
+ if( !this.compass ) { return; }
+ var main = grunt.file.expandFiles('temp/styles/*.main.css')[0];
+ var body = grunt.file.read(main);
+ assert.ok(/article,aside,details/.test(body));
+ });
});
- it('should write to styles/main.css', function() {
- if( !this.compass ) { return; }
- this.yeoman.expect(/(overwrite|identical|create)(.+)styles\/main.css/);
+ describe('img', function() {
+ // TBD: setup some fixture, check that files in temp/images are smaller
+ // than the one in app/images
+ it('should go through img:dist');
});
- });
- describe('img', function() {
- it('should go through img:dist', function() {
- this.yeoman.expect(/Running "img:dist" \(img\) task/);
+ describe('rjs', function() {
+ it('should optimize scripts/main', function() {
+ var file = grunt.file.expandFiles('temp/scripts/*.amd-app.js')[0];
+ var body = grunt.file.read(file);
+ assert.ok(/Hello from Yeoman!/, body);
+ });
});
- });
- describe('rjs', function() {
- it('should optimize scripts/main', function() {
- this.yeoman.expect(/rjs optimized module: (.+)/);
- });
- });
+ describe('concat', function() {
+ it('should write plugins.js concat target', function() {
+ var file = grunt.file.expandFiles('temp/scripts/*.plugins.js')[0];
+ var body = grunt.file.read(file);
- describe('concat', function() {
- it('should write plugins.js concat target', function() {
- this.yeoman
- .expect(/Running "concat:scripts\/plugins\.js" \(concat\) task/)
- .expect(/File "scripts\/plugins\.js" created\./);
- });
+ // some of the expected bootstrap plugins
+ ['affix', 'alert', 'dropdown', 'tooltip', 'modal', 'button'].forEach(function(str) {
+ assert.ok(body.indexOf(str) !== -1);
+ });
+ });
- it('should write amd-app.js concat target', function() {
- this.yeoman
- .expect(/Running "concat:scripts\/amd-app.js" \(concat\) task/)
- .expect(/File "scripts\/amd-app\.js" created\./);
- });
- });
+ it('should write amd-app.js concat target', function() {
+ var file = grunt.file.expandFiles('temp/scripts/*.amd-app.js')[0];
+ var body = grunt.file.read(file);
- describe('css', function() {
- it('should process styles/main.css', function() {
- this.yeoman
- .expect(/Running "css:styles\/main.css" \(css\) task/)
- .expect(/Writing css files to styles\/main.css/);
+ // some of the expected pattern in this optimized minified file
+ ['Hello from Yeoman!', 'requirejs'].forEach(function(str) {
+ assert.ok(body.indexOf(str) !== -1);
+ });
+ });
});
- });
- describe('rev', function() {
- describe('rev: should find and process the following files', function() {
- it('scripts/main.js >> {rev}.main.js', function() {
- this.yeoman.expect(/scripts\/main.js >> ([a-z0-9]+)\.main\.js/i);
- });
- it('scripts/vendor/bootstrap-alert.js >> {rev}.bootstrap-alert.js', function() {
- this.yeoman.expect(/scripts\/vendor\/bootstrap\/bootstrap-alert\.js >> ([a-z0-9]+)\.bootstrap-alert\.js/i);
- });
- it('scripts/vendor/jquery.min.js >> {rev}.jquery.min.js', function() {
- this.yeoman.expect(/scripts\/vendor\/jquery.min\.js >> ([a-z0-9]+)\.jquery.min\.js/i);
- });
- it('scripts/vendor/require.js >> {rev}.require.js', function() {
- this.yeoman.expect(/scripts\/vendor\/require\.js >> ([a-z0-9]+)\.require\.js/i);
+ describe('rev', function() {
+ describe('rev: should find and process the following files', function() {
+ it('scripts/main.js >> {rev}.main.js', function() {
+ var file = grunt.file.expandFiles('temp/scripts/*.main.js')[0];
+ assert.ok(/[a-z0-9]+\.main\.js/.test(file));
+ });
+ it('scripts/vendor/bootstrap-alert.js >> {rev}.bootstrap-alert.js', function() {
+ var file = grunt.file.expandFiles('temp/scripts/vendor/bootstrap/*.bootstrap-alert.js')[0];
+ assert.ok(/[a-z0-9]+\.bootstrap-alert\.js/.test(file));
+ });
+ it('scripts/vendor/jquery.min.js >> {rev}.jquery.min.js', function() {
+ var file = grunt.file.expandFiles('temp/scripts/vendor/*.jquery.min.js')[0];
+ assert.ok(/[a-z0-9]+\.jquery\.min\.js/.test(file));
+ });
+ it('scripts/vendor/require.js >> {rev}.require.js', function() {
+ var file = grunt.file.expandFiles('temp/scripts/vendor/*.require.js')[0];
+ assert.ok(/[a-z0-9]+\.require\.js/.test(file));
+ });
});
});
- });
- describe('usemin', function() {
- describe('usemin: should find and replace the following files', function() {
- it('scripts/vendor/modernizr.min.js', function() {
- this.yeoman
- .expect('was <script src="scripts/vendor/modernizr.min.js')
- .expect(/now <script src="scripts\/vendor\/([a-z0-9]+)\.modernizr.min\.js/i);
- });
- it('scripts/amp-app.js', function() {
- this.yeoman
- .expect('was <script src="scripts/amd-app.js')
- .expect(/now <script src="scripts\/([a-z0-9]+)\.amd-app\.js/i);
+ describe('usemin', function() {
+ before(function() {
+ this.body = grunt.file.read('temp/index.html');
});
- it('styles/main.css', function() {
- this.yeoman
- .expect('was <link rel="stylesheet" href="styles/main.css')
- .expect(/now <link rel="stylesheet" href="styles\/([a-z0-9]+)\.main\.css/i);
+
+ describe('usemin: should find and replace the following files', function() {
+ it('scripts/vendor/modernizr.min.js', function() {
+ var file = path.basename(grunt.file.expandFiles('temp/scripts/vendor/*.modernizr.min.js')[0]);
+ assert.ok(this.body.indexOf(file) !== -1);
+ });
+ it('scripts/amp-app.js', function() {
+ var file = path.basename(grunt.file.expandFiles('temp/scripts/*.amd-app.js')[0]);
+ assert.ok(this.body.indexOf(file) !== -1);
+ });
+ it('styles/main.css', function() {
+ if( !this.compass ) { return; }
+ var file = path.basename(grunt.file.expandFiles('temp/styles/*.main.css')[0]);
+ assert.ok(this.body.indexOf(file) !== -1);
+ });
});
});
- });
- describe('manifest', function() {
- it('should start a webserver automatically', function() {
- this.yeoman.expect('Starting static web server on port 3501');
- });
- it('should write to manifest.appcache', function() {
- if( !this.phantomjs ) { return; }
- this.yeoman
- .expect('Writing to manifest.appcache')
- .expect('This manifest was created by confess.js, http://github.com/jamesgpearce/confess')
- .expect(/styles\/([1-9a-z]+)\.main\.css/);
+ describe('manifest', function() {
+ it('should write to manifest.appcache', function() {
+ if( !this.phantomjs ) { return; }
+
+ var manifest = grunt.file.read('temp/manifest.appcache');
+ assert.ok(/CACHE:/.test(manifest));
+ assert.ok(/scripts\/[a-z0-9]+\.amd-app\.js/.test(manifest));
+ assert.ok(/scripts\/[a-z0-9]+\.plugins\.js/.test(manifest));
+ assert.ok(/scripts\/vendor\/[a-z0-9]+\.modernizr\.min\.js/.test(manifest));
+
+ if( !this.compass ) { return; }
+ assert.ok(/styles\/[a-z0-9]+\.main\.css/.test(manifest));
+ });
});
+
});
});

0 comments on commit c3660c1

Please sign in to comment.
Something went wrong with that request. Please try again.