Skip to content

Commit

Permalink
feat(gen): make generator tests faster, and easier to run
Browse files Browse the repository at this point in the history
  • Loading branch information
DaftMonk committed Aug 21, 2014
1 parent 76e8c03 commit 84acb74
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ test/temp
demo
.idea
.DS_Store
release.txt
release.txt
fixtures/bower.json
fixtures/package.json
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ before_install:
- gem update --system
- gem install sass --version "=3.3.7"
- npm install -g bower grunt-cli
- cd test/fixtures && npm install && bower install && cd .. && cd ..
services: mongodb
55 changes: 55 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var shell = require('shelljs');
var process = require('child_process');
var Q = require('q');
var helpers = require('yeoman-generator').test;
var fs = require('fs-extra');
var path = require('path');

module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
Expand Down Expand Up @@ -56,6 +58,17 @@ module.exports = function (grunt) {
},
all: ['Gruntfile.js', '*/index.js']
},
mochaTest: {
test: {
src: [
'test/*.js'
],
options: {
reporter: 'spec',
timeout: 120000
}
}
},
clean: {
demo: {
files: [{
Expand Down Expand Up @@ -186,6 +199,48 @@ module.exports = function (grunt) {
}
});

grunt.registerTask('updateFixtures', 'updates package and bower fixtures', function() {
var done = this.async();
var packageJson = fs.readFileSync(path.resolve('app/templates/_package.json'), 'utf8');
var bowerJson = fs.readFileSync(path.resolve('app/templates/_bower.json'), 'utf8');

// replace package name
packageJson = packageJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
packageJson = packageJson.replace(/<%(.*)%>/g, '');

// remove all ejs conditionals
bowerJson = bowerJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
bowerJson = bowerJson.replace(/<%(.*)%>/g, '');

// save files
fs.writeFile(path.resolve(__dirname + '/test/fixtures/package.json'), packageJson, function() {
fs.writeFile(path.resolve(__dirname + '/test/fixtures/bower.json'), bowerJson, function() {
done();
});
});
});

grunt.registerTask('installFixtures', 'install package and bower fixtures', function() {
var done = this.async();

shell.cd('test/fixtures');
grunt.log.ok('installing npm dependencies for generated app');
process.exec('npm install --quiet', {cwd: '../fixtures'}, function (error, stdout, stderr) {

grunt.log.ok('installing bower dependencies for generated app');
process.exec('bower install', {cwd: '../fixtures'}, function (error, stdout, stderr) {
shell.cd('../../');
done();
})
});
});

grunt.registerTask('test', [
'updateFixtures',
'installFixtures',
'mochaTest'
]);

grunt.registerTask('demo', [
'clean:demo',
'generateDemo'
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"url": "git://github.com/DaftMonk/generator-angular-fullstack.git"
},
"scripts": {
"test": "mocha"
"test": "grunt test"
},
"dependencies": {
"yeoman-generator": "~0.17.0",
Expand All @@ -38,14 +38,16 @@
"chai": "^1.9.1",
"fs-extra": "^0.9.1",
"grunt": "~0.4.1",
"grunt-build-control": "DaftMonk/grunt-build-control",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-conventional-changelog": "~1.0.0",
"grunt-build-control": "DaftMonk/grunt-build-control",
"grunt-mocha": "^0.4.11",
"grunt-mocha-test": "^0.11.0",
"grunt-release": "~0.6.0",
"load-grunt-tasks": "~0.2.0",
"marked": "~0.2.8",
"mocha": "~1.14.0",
"mocha": "~1.21.0",
"q": "^1.0.1",
"semver": "~2.2.1",
"shelljs": "^0.3.0",
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/bower.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "fixtures",
"name": "tempApp",
"version": "0.0.0",
"dependencies": {
"angular": ">=1.2.*",
"json3": "~3.3.1",
"es5-shim": "~3.0.1",
"jquery": "~1.11.0",
"bootstrap-sass-official": "~3.1.1",
"bootstrap-stylus": "latest",
"bootstrap": "~3.1.1",
"angular-resource": ">=1.2.*",
"angular-cookies": ">=1.2.*",
Expand Down
27 changes: 18 additions & 9 deletions test/fixtures/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"name": "fixtures",
"name": "tempApp",
"version": "0.0.0",
"main": "server/app.js",
"dependencies": {
"express": "~4.0.0",
"morgan": "~1.0.0",
Expand All @@ -23,16 +25,16 @@
"passport-google-oauth": "latest",
"composable-middleware": "^0.3.0",
"connect-mongo": "^0.4.1",
"socket.io": "~1.0.6",
"socket.io": "^1.0.6",
"socket.io-client": "^1.0.6",
"socketio-jwt": "^2.0.2"
},
"devDependencies": {
"grunt": "~0.4.4",
"grunt-autoprefixer": "~0.7.2",
"grunt-bower-install": "~1.4.0",
"grunt-wiredep": "~1.8.0",
"grunt-concurrent": "~0.5.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-compass": "~0.7.2",
"grunt-contrib-concat": "~0.4.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-cssmin": "~0.9.0",
Expand All @@ -44,10 +46,9 @@
"grunt-contrib-coffee": "^0.10.1",
"grunt-contrib-jade": "^0.11.0",
"grunt-contrib-less": "^0.11.0",
"grunt-contrib-stylus": "latest",
"grunt-google-cdn": "~0.4.0",
"grunt-newer": "~0.7.0",
"grunt-ngmin": "~0.0.3",
"grunt-ng-annotate": "^0.2.3",
"grunt-rev": "~0.1.0",
"grunt-svgmin": "~0.4.0",
"grunt-usemin": "~2.1.1",
Expand All @@ -59,8 +60,10 @@
"grunt-protractor-runner": "^1.1.0",
"grunt-asset-injector": "^0.1.0",
"grunt-karma": "~0.8.2",
"grunt-build-control": "DaftMonk/grunt-build-control",
"grunt-mocha-test": "~0.10.2",
"grunt-contrib-sass": "^0.7.3",
"grunt-contrib-stylus": "latest",
"jit-grunt": "^0.5.0",
"time-grunt": "~0.3.1",
"grunt-express-server": "~0.4.17",
Expand All @@ -72,13 +75,13 @@
"karma-firefox-launcher": "~0.1.3",
"karma-script-launcher": "~0.1.0",
"karma-html2js-preprocessor": "~0.1.0",
"karma-ng-jade2js-preprocessor": "^0.1.2",
"karma-jasmine": "~0.1.5",
"karma-chrome-launcher": "~0.1.3",
"requirejs": "~2.1.11",
"karma-requirejs": "~0.2.1",
"karma-coffee-preprocessor": "~0.2.1",
"karma-jade-preprocessor": "0.0.11",
"karma-ng-jade2js-preprocessor": "^0.1.2",
"karma-phantomjs-launcher": "~0.1.4",
"karma": "~0.12.9",
"karma-ng-html2js-preprocessor": "~0.1.0",
Expand All @@ -87,5 +90,11 @@
},
"engines": {
"node": ">=0.10.0"
}
}
},
"scripts": {
"start": "node server/app.js",
"test": "grunt test",
"update-webdriver": "node node_modules/grunt-protractor-runner/node_modules/protractor/bin/webdriver-manager update"
},
"private": true
}
14 changes: 9 additions & 5 deletions test/test-file-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('angular-fullstack generator', function () {
auth: true,
oauth: [],
socketio: true
};
}, dependenciesInstalled = false;

function generatorTest(generatorType, name, mockPrompt, callback) {
gen.run({}, function () {
Expand Down Expand Up @@ -54,10 +54,12 @@ describe('angular-fullstack generator', function () {
});

describe('running app', function() {
;
beforeEach(function() {
this.timeout(20000);
fs.copySync(__dirname + '/fixtures/node_modules', __dirname + '/temp/node_modules');
fs.copySync(__dirname +'/fixtures/bower_components', __dirname +'/temp/client/bower_components');
fs.mkdirSync(__dirname + '/temp/client');
fs.symlinkSync(__dirname + '/fixtures/node_modules', __dirname + '/temp/node_modules');
fs.symlinkSync(__dirname +'/fixtures/bower_components', __dirname +'/temp/client/bower_components');
});

describe('with default options', function() {
Expand Down Expand Up @@ -178,7 +180,7 @@ describe('angular-fullstack generator', function () {
});

describe('with other preprocessors and no server options', function() {
beforeEach(function() {
beforeEach(function(done) {
helpers.mockPrompt(gen, {
script: 'coffee',
markup: 'jade',
Expand All @@ -189,6 +191,7 @@ describe('angular-fullstack generator', function () {
oauth: [],
socketio: false
});
done();
});

it('should run client tests successfully', function(done) {
Expand Down Expand Up @@ -224,7 +227,7 @@ describe('angular-fullstack generator', function () {
});

describe('with no preprocessors and no server options', function() {
beforeEach(function() {
beforeEach(function(done) {
helpers.mockPrompt(gen, {
script: 'js',
markup: 'html',
Expand All @@ -235,6 +238,7 @@ describe('angular-fullstack generator', function () {
oauth: [],
socketio: false
});
done();
});

it('should run client tests successfully', function(done) {
Expand Down

0 comments on commit 84acb74

Please sign in to comment.