diff --git a/.gitignore b/.gitignore index d546f99f3..9e436b36f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ test/temp demo .idea .DS_Store -release.txt \ No newline at end of file +release.txt +fixtures/bower.json +fixtures/package.json \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 96b052993..5dd047094 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 6479ed53b..afeaa0abc 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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); @@ -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: [{ @@ -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' diff --git a/package.json b/package.json index 6cb74ede5..eff5d5f0b 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/test/fixtures/bower.json b/test/fixtures/bower.json index dea41015a..7d9aae354 100644 --- a/test/fixtures/bower.json +++ b/test/fixtures/bower.json @@ -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.*", diff --git a/test/fixtures/package.json b/test/fixtures/package.json index bd2b41da9..997d9b952 100644 --- a/test/fixtures/package.json +++ b/test/fixtures/package.json @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -87,5 +90,11 @@ }, "engines": { "node": ">=0.10.0" - } -} \ No newline at end of file + }, + "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 +} diff --git a/test/test-file-creation.js b/test/test-file-creation.js index c0ff58e47..bea7ae79c 100644 --- a/test/test-file-creation.js +++ b/test/test-file-creation.js @@ -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 () { @@ -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() { @@ -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', @@ -189,6 +191,7 @@ describe('angular-fullstack generator', function () { oauth: [], socketio: false }); + done(); }); it('should run client tests successfully', function(done) { @@ -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', @@ -235,6 +238,7 @@ describe('angular-fullstack generator', function () { oauth: [], socketio: false }); + done(); }); it('should run client tests successfully', function(done) {