Skip to content

Commit

Permalink
upgrade testing to use 0.17.0 goodness
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemonge committed Jun 19, 2014
1 parent fef8a9f commit 0a996d9
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
temp/
.tmp
42 changes: 22 additions & 20 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,10 @@ module.exports = yeoman.generators.Base.extend({
this.coffee = this.options.coffee;

this.pkg = require('../package.json');

this.on('end', function () {
this.invoke(this.options['test-framework']+':app', {
options: {
'skip-message': this.options['skip-install-message'],
'skip-install': this.options['skip-install'],
'coffee': this.options.coffee
}
});

if (!this.options['skip-install']) {
this.installDependencies({
skipMessage: this.options['skip-install-message'],
skipInstall: this.options['skip-install']
});
}
});
},

askFor: function () {
var cb = this.async();
var done = this.async();

// welcome message
if (!this.options['skip-welcome-message']) {
Expand Down Expand Up @@ -88,7 +71,7 @@ module.exports = yeoman.generators.Base.extend({
var features = answers.features;

function hasFeature(feat) {
return features.indexOf(feat) !== -1;
return features && features.indexOf(feat) !== -1;
}

this.includeSass = hasFeature('includeSass');
Expand All @@ -98,7 +81,7 @@ module.exports = yeoman.generators.Base.extend({
this.includeLibSass = answers.libsass;
this.includeRubySass = !answers.libsass;

cb();
done();
}.bind(this));
},

Expand Down Expand Up @@ -189,5 +172,24 @@ module.exports = yeoman.generators.Base.extend({
else {
this.write('app/scripts/main.js', 'console.log(\'\\\'Allo \\\'Allo!\');');
}
},

install: function () {
this.on('end', function () {
this.invoke(this.options['test-framework'], {
options: {
'skip-message': this.options['skip-install-message'],
'skip-install': this.options['skip-install'],
'coffee': this.options.coffee
}
});

if (!this.options['skip-install']) {
this.installDependencies({
skipMessage: this.options['skip-install-message'],
skipInstall: this.options['skip-install']
});
}
});
}
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"generator-mocha": ">=0.1.0"
},
"devDependencies": {
"mocha": "*"
"mocha": "*",
"underscore": "^1.6.0"
}
}
227 changes: 171 additions & 56 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,188 @@
var path = require('path');
var assert = require('assert');
var helpers = require('yeoman-generator').test;
var assert = require('yeoman-generator').assert;
var _ = require('underscore');

describe('Webapp generator test', function () {
var expectedContent = [
['bower.json', /"name": "temp"/],
['package.json', /"name": "temp"/]
];
var expected = [
'Gruntfile.js',
'app/404.html',
'app/favicon.ico',
'app/robots.txt',
'app/index.html',
'app/styles/main.scss'
];

beforeEach(function (done) {
helpers.testDirectory(path.join(__dirname, 'temp'), function (err) {
if (err) {
return done(err);
}

this.webapp = helpers.createGenerator('webapp:app', [
'../../app', [
helpers.createDummyGenerator(),
'mocha:app'
]
], null, {
'skip-install': true,
'skip-welcome-message': true,
'skip-message': true
});

done();
}.bind(this));
});

describe('Webapp generator', function () {
// not testing the actual run of generators yet
it('the generator can be required without throwing', function () {
// not testing the actual run of generators yet
this.app = require('../app');
});

it('creates expected CoffeeScript files', function (done) {
helpers.mockPrompt(this.webapp, {
features: ['includeSass']
describe('run test', function () {

var expectedContent = [
['bower.json', /"name": "tmp"/],
['package.json', /"name": "tmp"/]
];
var expected = [
'.editorconfig',
'.gitignore',
'.gitattributes',
'package.json',
'bower.json',
'Gruntfile.js',
'app/404.html',
'app/favicon.ico',
'app/robots.txt',
'app/index.html',
'app/.htaccess'
];

var options = {
'skip-install-message': true,
'skip-install': true,
'skip-welcome-message': true,
'skip-message': true
};

var runGen;

beforeEach(function () {
runGen = helpers
.run(path.join(__dirname, '../app'))
.inDir(path.join(__dirname, '.tmp'))
.withGenerators([[helpers.createDummyGenerator(), 'mocha:app']]);
});

this.webapp.coffee = true;
this.webapp.run({}, function () {
helpers.assertFile([].concat(expected, ['app/scripts/main.coffee']));
assert.fileContent([].concat(
expectedContent,
[['Gruntfile.js', /coffee/]]
));
done();
it('creates expected files', function (done) {
runGen.withOptions(options).on('end', function () {

assert.file([].concat(
expected,
'app/styles/main.css',
'app/scripts/main.js'
));
assert.noFile([
'app/styles/main.scss',
'app/scripts/main.coffee'
]);

assert.fileContent(expectedContent);
assert.noFileContent([
['Gruntfile.js', /coffee/],
['Gruntfile.js', /modernizr/],
['app/index.html', /modernizr/],
['bower.json', /modernizr/],
['package.json', /modernizr/],
['Gruntfile.js', /bootstrap/],
['app/index.html', /bootstrap/],
['bower.json', /bootstrap/],
['Gruntfile.js', /sass/],
['app/index.html', /Sass/],
['.gitignore', /\.sass-cache/],
['package.json', /grunt-contrib-sass/],
['package.json', /grunt-sass/],
['Gruntfile.js', /bootstrap-sass-official/],
['app/index.html', /Sass is a mature/],
['bower.json', /bootstrap-sass-official/]
]);
done();
});
});
});

it('creates expected files in non-coffee mode', function (done) {
helpers.mockPrompt(this.webapp, {
features: ['includeSass']
it('creates expected CoffeeScript files', function (done) {
runGen.withOptions(
_.extend(options, {coffee: true})
).on('end', function () {

assert.file([].concat(
expected,
'app/scripts/main.coffee'
));
assert.noFile('app/scripts/main.js');

assert.fileContent([].concat(
expectedContent,
[['Gruntfile.js', /coffee/]]
));

done();
});
});

it('creates expected modernizr components', function (done) {
runGen.withOptions(options).withPrompt({features: ['includeModernizr']})
.on('end', function () {

assert.fileContent([
['Gruntfile.js', /modernizr/],
['app/index.html', /modernizr/],
['bower.json', /modernizr/],
['package.json', /modernizr/],
]);

done();
});
});

this.webapp.coffee = false;
this.webapp.run({}, function () {
helpers.assertFile([].concat(expected, ['app/scripts/main.js']));
assert.noFileContent('Gruntfile.js', /coffee/);
done();
it('creates expected bootstrap components', function (done) {
runGen.withOptions(options).withPrompt({features: ['includeBootstrap']})
.on('end', function () {

assert.fileContent([
['Gruntfile.js', /bootstrap/],
['app/index.html', /bootstrap/],
['bower.json', /bootstrap/]
]);

done();
});
});

it('creates expected ruby SASS components', function (done) {
runGen.withOptions(options).withPrompt({features: ['includeSass']})
.on('end', function () {

assert.fileContent([
['Gruntfile.js', /sass/],
['app/index.html', /Sass/],
['.gitignore', /\.sass-cache/],
['package.json', /grunt-contrib-sass/]
]);

assert.noFileContent([
['package.json', /grunt-sass/],
['app/index.html', /Sass is a mature/]
]);

done();
});
});

it('creates expected node SASS files', function (done) {
runGen.withOptions(options).withPrompt({
features: ['includeSass'],
libsass: true
}).on('end', function () {

assert.fileContent([
['package.json', /grunt-sass/]
]);

assert.noFileContent([
['package.json', /grunt-contrib-sass/],
['Gruntfile.js', /bootstrap-sass-official/]
]);

done();
});
});

it('creates expected SASS and Bootstrap components', function (done) {
runGen.withOptions(options).withPrompt({
features: ['includeSass', 'includeBootstrap']
}).on('end', function () {

assert.fileContent([
['Gruntfile.js', /bootstrap-sass-official/],
['app/index.html', /Sass is a mature/],
['bower.json', /bootstrap-sass-official/]
]);

done();
});
});
});
});

0 comments on commit 0a996d9

Please sign in to comment.