Skip to content

Commit 84acb74

Browse files
committed
feat(gen): make generator tests faster, and easier to run
1 parent 76e8c03 commit 84acb74

File tree

7 files changed

+92
-21
lines changed

7 files changed

+92
-21
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ test/temp
44
demo
55
.idea
66
.DS_Store
7-
release.txt
7+
release.txt
8+
fixtures/bower.json
9+
fixtures/package.json

Diff for: .travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ before_install:
55
- gem update --system
66
- gem install sass --version "=3.3.7"
77
- npm install -g bower grunt-cli
8-
- cd test/fixtures && npm install && bower install && cd .. && cd ..
98
services: mongodb

Diff for: Gruntfile.js

+55
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var shell = require('shelljs');
66
var process = require('child_process');
77
var Q = require('q');
88
var helpers = require('yeoman-generator').test;
9+
var fs = require('fs-extra');
10+
var path = require('path');
911

1012
module.exports = function (grunt) {
1113
require('load-grunt-tasks')(grunt);
@@ -56,6 +58,17 @@ module.exports = function (grunt) {
5658
},
5759
all: ['Gruntfile.js', '*/index.js']
5860
},
61+
mochaTest: {
62+
test: {
63+
src: [
64+
'test/*.js'
65+
],
66+
options: {
67+
reporter: 'spec',
68+
timeout: 120000
69+
}
70+
}
71+
},
5972
clean: {
6073
demo: {
6174
files: [{
@@ -186,6 +199,48 @@ module.exports = function (grunt) {
186199
}
187200
});
188201

202+
grunt.registerTask('updateFixtures', 'updates package and bower fixtures', function() {
203+
var done = this.async();
204+
var packageJson = fs.readFileSync(path.resolve('app/templates/_package.json'), 'utf8');
205+
var bowerJson = fs.readFileSync(path.resolve('app/templates/_bower.json'), 'utf8');
206+
207+
// replace package name
208+
packageJson = packageJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
209+
packageJson = packageJson.replace(/<%(.*)%>/g, '');
210+
211+
// remove all ejs conditionals
212+
bowerJson = bowerJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
213+
bowerJson = bowerJson.replace(/<%(.*)%>/g, '');
214+
215+
// save files
216+
fs.writeFile(path.resolve(__dirname + '/test/fixtures/package.json'), packageJson, function() {
217+
fs.writeFile(path.resolve(__dirname + '/test/fixtures/bower.json'), bowerJson, function() {
218+
done();
219+
});
220+
});
221+
});
222+
223+
grunt.registerTask('installFixtures', 'install package and bower fixtures', function() {
224+
var done = this.async();
225+
226+
shell.cd('test/fixtures');
227+
grunt.log.ok('installing npm dependencies for generated app');
228+
process.exec('npm install --quiet', {cwd: '../fixtures'}, function (error, stdout, stderr) {
229+
230+
grunt.log.ok('installing bower dependencies for generated app');
231+
process.exec('bower install', {cwd: '../fixtures'}, function (error, stdout, stderr) {
232+
shell.cd('../../');
233+
done();
234+
})
235+
});
236+
});
237+
238+
grunt.registerTask('test', [
239+
'updateFixtures',
240+
'installFixtures',
241+
'mochaTest'
242+
]);
243+
189244
grunt.registerTask('demo', [
190245
'clean:demo',
191246
'generateDemo'

Diff for: package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"url": "git://github.com/DaftMonk/generator-angular-fullstack.git"
2424
},
2525
"scripts": {
26-
"test": "mocha"
26+
"test": "grunt test"
2727
},
2828
"dependencies": {
2929
"yeoman-generator": "~0.17.0",
@@ -38,14 +38,16 @@
3838
"chai": "^1.9.1",
3939
"fs-extra": "^0.9.1",
4040
"grunt": "~0.4.1",
41+
"grunt-build-control": "DaftMonk/grunt-build-control",
4142
"grunt-contrib-clean": "^0.6.0",
4243
"grunt-contrib-jshint": "^0.10.0",
4344
"grunt-conventional-changelog": "~1.0.0",
44-
"grunt-build-control": "DaftMonk/grunt-build-control",
45+
"grunt-mocha": "^0.4.11",
46+
"grunt-mocha-test": "^0.11.0",
4547
"grunt-release": "~0.6.0",
4648
"load-grunt-tasks": "~0.2.0",
4749
"marked": "~0.2.8",
48-
"mocha": "~1.14.0",
50+
"mocha": "~1.21.0",
4951
"q": "^1.0.1",
5052
"semver": "~2.2.1",
5153
"shelljs": "^0.3.0",

Diff for: test/fixtures/bower.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "fixtures",
2+
"name": "tempApp",
3+
"version": "0.0.0",
34
"dependencies": {
45
"angular": ">=1.2.*",
56
"json3": "~3.3.1",
67
"es5-shim": "~3.0.1",
78
"jquery": "~1.11.0",
89
"bootstrap-sass-official": "~3.1.1",
9-
"bootstrap-stylus": "latest",
1010
"bootstrap": "~3.1.1",
1111
"angular-resource": ">=1.2.*",
1212
"angular-cookies": ">=1.2.*",

Diff for: test/fixtures/package.json

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"name": "fixtures",
2+
"name": "tempApp",
3+
"version": "0.0.0",
4+
"main": "server/app.js",
35
"dependencies": {
46
"express": "~4.0.0",
57
"morgan": "~1.0.0",
@@ -23,16 +25,16 @@
2325
"passport-google-oauth": "latest",
2426
"composable-middleware": "^0.3.0",
2527
"connect-mongo": "^0.4.1",
26-
"socket.io": "~1.0.6",
28+
"socket.io": "^1.0.6",
29+
"socket.io-client": "^1.0.6",
2730
"socketio-jwt": "^2.0.2"
2831
},
2932
"devDependencies": {
3033
"grunt": "~0.4.4",
3134
"grunt-autoprefixer": "~0.7.2",
32-
"grunt-bower-install": "~1.4.0",
35+
"grunt-wiredep": "~1.8.0",
3336
"grunt-concurrent": "~0.5.0",
3437
"grunt-contrib-clean": "~0.5.0",
35-
"grunt-contrib-compass": "~0.7.2",
3638
"grunt-contrib-concat": "~0.4.0",
3739
"grunt-contrib-copy": "~0.5.0",
3840
"grunt-contrib-cssmin": "~0.9.0",
@@ -44,10 +46,9 @@
4446
"grunt-contrib-coffee": "^0.10.1",
4547
"grunt-contrib-jade": "^0.11.0",
4648
"grunt-contrib-less": "^0.11.0",
47-
"grunt-contrib-stylus": "latest",
4849
"grunt-google-cdn": "~0.4.0",
4950
"grunt-newer": "~0.7.0",
50-
"grunt-ngmin": "~0.0.3",
51+
"grunt-ng-annotate": "^0.2.3",
5152
"grunt-rev": "~0.1.0",
5253
"grunt-svgmin": "~0.4.0",
5354
"grunt-usemin": "~2.1.1",
@@ -59,8 +60,10 @@
5960
"grunt-protractor-runner": "^1.1.0",
6061
"grunt-asset-injector": "^0.1.0",
6162
"grunt-karma": "~0.8.2",
63+
"grunt-build-control": "DaftMonk/grunt-build-control",
6264
"grunt-mocha-test": "~0.10.2",
6365
"grunt-contrib-sass": "^0.7.3",
66+
"grunt-contrib-stylus": "latest",
6467
"jit-grunt": "^0.5.0",
6568
"time-grunt": "~0.3.1",
6669
"grunt-express-server": "~0.4.17",
@@ -72,13 +75,13 @@
7275
"karma-firefox-launcher": "~0.1.3",
7376
"karma-script-launcher": "~0.1.0",
7477
"karma-html2js-preprocessor": "~0.1.0",
78+
"karma-ng-jade2js-preprocessor": "^0.1.2",
7579
"karma-jasmine": "~0.1.5",
7680
"karma-chrome-launcher": "~0.1.3",
7781
"requirejs": "~2.1.11",
7882
"karma-requirejs": "~0.2.1",
7983
"karma-coffee-preprocessor": "~0.2.1",
8084
"karma-jade-preprocessor": "0.0.11",
81-
"karma-ng-jade2js-preprocessor": "^0.1.2",
8285
"karma-phantomjs-launcher": "~0.1.4",
8386
"karma": "~0.12.9",
8487
"karma-ng-html2js-preprocessor": "~0.1.0",
@@ -87,5 +90,11 @@
8790
},
8891
"engines": {
8992
"node": ">=0.10.0"
90-
}
91-
}
93+
},
94+
"scripts": {
95+
"start": "node server/app.js",
96+
"test": "grunt test",
97+
"update-webdriver": "node node_modules/grunt-protractor-runner/node_modules/protractor/bin/webdriver-manager update"
98+
},
99+
"private": true
100+
}

Diff for: test/test-file-creation.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('angular-fullstack generator', function () {
1717
auth: true,
1818
oauth: [],
1919
socketio: true
20-
};
20+
}, dependenciesInstalled = false;
2121

2222
function generatorTest(generatorType, name, mockPrompt, callback) {
2323
gen.run({}, function () {
@@ -54,10 +54,12 @@ describe('angular-fullstack generator', function () {
5454
});
5555

5656
describe('running app', function() {
57+
;
5758
beforeEach(function() {
5859
this.timeout(20000);
59-
fs.copySync(__dirname + '/fixtures/node_modules', __dirname + '/temp/node_modules');
60-
fs.copySync(__dirname +'/fixtures/bower_components', __dirname +'/temp/client/bower_components');
60+
fs.mkdirSync(__dirname + '/temp/client');
61+
fs.symlinkSync(__dirname + '/fixtures/node_modules', __dirname + '/temp/node_modules');
62+
fs.symlinkSync(__dirname +'/fixtures/bower_components', __dirname +'/temp/client/bower_components');
6163
});
6264

6365
describe('with default options', function() {
@@ -178,7 +180,7 @@ describe('angular-fullstack generator', function () {
178180
});
179181

180182
describe('with other preprocessors and no server options', function() {
181-
beforeEach(function() {
183+
beforeEach(function(done) {
182184
helpers.mockPrompt(gen, {
183185
script: 'coffee',
184186
markup: 'jade',
@@ -189,6 +191,7 @@ describe('angular-fullstack generator', function () {
189191
oauth: [],
190192
socketio: false
191193
});
194+
done();
192195
});
193196

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

226229
describe('with no preprocessors and no server options', function() {
227-
beforeEach(function() {
230+
beforeEach(function(done) {
228231
helpers.mockPrompt(gen, {
229232
script: 'js',
230233
markup: 'html',
@@ -235,6 +238,7 @@ describe('angular-fullstack generator', function () {
235238
oauth: [],
236239
socketio: false
237240
});
241+
done();
238242
});
239243

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

0 commit comments

Comments
 (0)