Permalink
Browse files

test - replace stdout checks and test against the file system

for the test build. Close #450
  • Loading branch information...
mklabs committed Sep 16, 2012
1 parent 3dd71f2 commit 0a6916659708c35723e3100bd42138bbec714325
Showing with 123 additions and 181 deletions.
  1. +1 −1 cli/package.json
  2. +9 −2 cli/tasks/css.js
  3. +2 −2 cli/tasks/yeoman.js
  4. +1 −1 cli/test/helpers/index.js
  5. +110 −175 cli/test/test-build.js
View
@@ -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
@@ -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
@@ -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));
@@ -149,8 +149,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
@@ -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,140 @@ 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);
+ describe('usemin', function() {
+ before(function() {
+ this.body = grunt.file.read('temp/index.html');
});
- 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);
- });
- 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() {
+ 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));
+ assert.ok(/styles\/[a-z0-9]+\.main\.css/.test(manifest));
+ });
});
+
});
});

0 comments on commit 0a69166

Please sign in to comment.