Skip to content

Commit 316e93f

Browse files
committed
feat(gen:tests): step 1 of new test structure
1 parent ead201a commit 316e93f

File tree

3 files changed

+348
-22
lines changed

3 files changed

+348
-22
lines changed

Diff for: src/test/get-expected-files.js

+237
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/**
2+
* Generate an array of files to expect from a set of options
3+
*
4+
* @param {Object} options - generator options
5+
* @return {Array} - array of files
6+
*
7+
*/
8+
export function app(options) {
9+
var mapping = {
10+
stylesheet: {
11+
sass: 'scss',
12+
stylus: 'styl',
13+
less: 'less',
14+
css: 'css'
15+
},
16+
markup: {
17+
jade: 'jade',
18+
html: 'html'
19+
},
20+
script: {
21+
js: 'js',
22+
ts: 'ts'
23+
}
24+
},
25+
files = [];
26+
27+
/**
28+
* Generate an array of OAuth files based on type
29+
*
30+
* @param {String} type - type of oauth
31+
* @return {Array} - array of files
32+
*
33+
*/
34+
var oauthFiles = function(type) {
35+
return [
36+
'server/auth/' + type + '/index.js',
37+
'server/auth/' + type + '/passport.js',
38+
];
39+
};
40+
41+
42+
var script = mapping.script[options.transpiler === 'ts' ? 'ts' : 'js'],
43+
markup = mapping.markup[options.markup],
44+
stylesheet = mapping.stylesheet[options.stylesheet],
45+
models = options.models ? options.models : options.odms[0];
46+
47+
/* Core Files */
48+
files = files.concat([
49+
'client/.htaccess',
50+
'client/favicon.ico',
51+
'client/robots.txt',
52+
'client/index.html',
53+
'client/app/app.' + script,
54+
'client/app/app.' + stylesheet,
55+
'client/app/main/main.' + script,
56+
'client/app/main/main.' + markup,
57+
'client/app/main/main.' + stylesheet,
58+
'client/app/main/main.controller.' + script,
59+
'client/app/main/main.controller.spec.' + script,
60+
'client/assets/images/yeoman.png',
61+
'client/components/footer/footer.' + stylesheet,
62+
'client/components/footer/footer.' + markup,
63+
'client/components/footer/footer.directive.' + script,
64+
'client/components/navbar/navbar.' + markup,
65+
'client/components/navbar/navbar.controller.' + script,
66+
'client/components/navbar/navbar.directive.' + script,
67+
'client/components/util/util.module.' + script,
68+
'client/components/util/util.service.' + script,
69+
'server/.jshintrc',
70+
'server/.jshintrc-spec',
71+
'server/app.js',
72+
'server/index.js',
73+
'server/routes.js',
74+
'server/api/thing/index.js',
75+
'server/api/thing/index.spec.js',
76+
'server/api/thing/thing.controller.js',
77+
'server/api/thing/thing.integration.js',
78+
'server/components/errors/index.js',
79+
'server/config/local.env.js',
80+
'server/config/local.env.sample.js',
81+
'server/config/express.js',
82+
'server/config/environment/index.js',
83+
'server/config/environment/development.js',
84+
'server/config/environment/production.js',
85+
'server/config/environment/test.js',
86+
'server/config/environment/shared.js',
87+
'server/views/404.' + markup,
88+
'e2e/main/main.po.js',
89+
'e2e/main/main.spec.js',
90+
'e2e/components/navbar/navbar.po.js',
91+
'.babelrc',
92+
'.bowerrc',
93+
'.buildignore',
94+
'.editorconfig',
95+
'.gitattributes',
96+
'.gitignore',
97+
'.travis.yml',
98+
'.jscsrc',
99+
'.yo-rc.json',
100+
'Gruntfile.js',
101+
'package.json',
102+
'bower.json',
103+
'karma.conf.js',
104+
'mocha.conf.js',
105+
'protractor.conf.js',
106+
'README.md'
107+
]);
108+
109+
/* TypeScript */
110+
if (options.transpiler === 'ts') {
111+
files = files.concat([
112+
'tsconfig.client.test.json',
113+
'tsconfig.client.json',
114+
'tsd.json',
115+
'tsd_test.json',
116+
'client/tslint.json'
117+
]);
118+
} else {
119+
files = files.concat([
120+
'client/.jshintrc'
121+
]);
122+
}
123+
124+
/* Ui-Router */
125+
if (options.router === 'uirouter') {
126+
files = files.concat([
127+
'client/components/ui-router/ui-router.mock.' + script
128+
]);
129+
}
130+
131+
/* Ui-Bootstrap */
132+
if (options.uibootstrap) {
133+
files = files.concat([
134+
'client/components/modal/modal.' + markup,
135+
'client/components/modal/modal.' + stylesheet,
136+
'client/components/modal/modal.service.' + script
137+
]);
138+
}
139+
140+
/* Models - Mongoose or Sequelize */
141+
if (models) {
142+
files = files.concat([
143+
'server/api/thing/thing.model.js',
144+
'server/api/thing/thing.events.js',
145+
'server/config/seed.js'
146+
]);
147+
}
148+
149+
/* Sequelize */
150+
if (options.odms.indexOf('sequelize') !== -1) {
151+
files = files.concat([
152+
'server/sqldb/index.js'
153+
]);
154+
}
155+
156+
/* Authentication */
157+
if (options.auth) {
158+
files = files.concat([
159+
'client/app/account/account.' + script,
160+
'client/app/account/login/login.' + markup,
161+
'client/app/account/login/login.controller.' + script,
162+
'client/app/account/settings/settings.' + markup,
163+
'client/app/account/settings/settings.controller.' + script,
164+
'client/app/account/signup/signup.' + markup,
165+
'client/app/account/signup/signup.controller.' + script,
166+
'client/app/admin/admin.' + markup,
167+
'client/app/admin/admin.' + stylesheet,
168+
'client/app/admin/admin.module.' + script,
169+
'client/app/admin/admin.router.' + script,
170+
'client/app/admin/admin.controller.' + script,
171+
'client/components/auth/auth.module.' + script,
172+
'client/components/auth/auth.service.' + script,
173+
'client/components/auth/interceptor.service.' + script,
174+
'client/components/auth/router.decorator.' + script,
175+
'client/components/auth/user.service.' + script,
176+
'client/components/mongoose-error/mongoose-error.directive.' + script,
177+
'server/api/user/index.js',
178+
'server/api/user/index.spec.js',
179+
'server/api/user/user.controller.js',
180+
'server/api/user/user.integration.js',
181+
'server/api/user/user.model.js',
182+
'server/api/user/user.model.spec.js',
183+
'server/api/user/user.events.js',
184+
'server/auth/index.js',
185+
'server/auth/auth.service.js',
186+
'server/auth/local/index.js',
187+
'server/auth/local/passport.js',
188+
'e2e/account/login/login.po.js',
189+
'e2e/account/login/login.spec.js',
190+
'e2e/account/logout/logout.spec.js',
191+
'e2e/account/signup/signup.po.js',
192+
'e2e/account/signup/signup.spec.js'
193+
]);
194+
}
195+
196+
if (options.oauth && options.oauth.length) {
197+
/* OAuth (see oauthFiles function above) */
198+
options.oauth.forEach(function(type, i) {
199+
files = files.concat(oauthFiles(type.replace('Auth', '')));
200+
});
201+
202+
203+
files = files.concat([
204+
'client/components/oauth-buttons/oauth-buttons.' + stylesheet,
205+
'client/components/oauth-buttons/oauth-buttons.' + markup,
206+
'client/components/oauth-buttons/oauth-buttons.controller.' + script,
207+
'client/components/oauth-buttons/oauth-buttons.controller.spec.' + script,
208+
'client/components/oauth-buttons/oauth-buttons.directive.' + script,
209+
'client/components/oauth-buttons/oauth-buttons.directive.spec.' + script,
210+
'e2e/components/oauth-buttons/oauth-buttons.po.js'
211+
]);
212+
}
213+
214+
/* Socket.IO */
215+
if (options.socketio) {
216+
files = files.concat([
217+
'client/components/socket/socket.service.' + script,
218+
'client/components/socket/socket.mock.' + script,
219+
'server/api/thing/thing.socket.js',
220+
'server/config/socketio.js'
221+
]);
222+
}
223+
224+
return files;
225+
}
226+
227+
export function endpoint(name, options) {
228+
return [
229+
`server/api/${name}/index.js`,
230+
`server/api/${name}/index.spec.js`,
231+
`server/api/${name}/bar.controller.js`,
232+
`server/api/${name}/bar.events.js`,
233+
`server/api/${name}/bar.integration.js`,
234+
`server/api/${name}/bar.model.js`,
235+
`server/api/${name}/bar.socket.js`
236+
];
237+
}

Diff for: src/test/main.test.js

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
'use strict';
2+
import path from 'path';
3+
import fs from 'fs';
4+
import Promise from 'bluebird';
5+
Promise.promisifyAll(fs);
6+
import {exec} from 'child_process';
7+
import helpers from 'yeoman-test';
8+
import assert from 'yeoman-assert';
9+
import * as getExpectedFiles from './get-expected-files';
10+
11+
const defaultOptions = {
12+
buildtool: 'grunt',
13+
script: 'js',
14+
transpiler: 'babel',
15+
markup: 'html',
16+
stylesheet: 'sass',
17+
router: 'uirouter',
18+
testing: 'mocha',
19+
chai: 'expect',
20+
bootstrap: true,
21+
uibootstrap: true,
22+
odms: ['mongoose'],
23+
auth: true,
24+
oauth: [],
25+
socketio: true
26+
};
27+
// var DEBUG = true;
28+
var DEBUG = false;
29+
30+
function runCmd(cmd, done) {
31+
exec(cmd, {}, function(err, stdout, stderr) {
32+
if(err) {
33+
console.error(stdout);
34+
throw new Error(`Error running command: ${cmd}`);
35+
done(err);
36+
} else {
37+
if(DEBUG) console.log(stdout);
38+
done();
39+
}
40+
});
41+
}
42+
43+
describe('angular-fullstack:app', function() {
44+
beforeEach(function() {
45+
this.gen = helpers
46+
.run(require.resolve('../generators/app'))
47+
.inTmpDir(function(dir) {
48+
var done = this.async();
49+
if(DEBUG) console.log(`TEMP DIR: ${dir}`);
50+
51+
return Promise.all([
52+
fs.mkdirAsync(dir + '/client').then(() => {
53+
return fs.symlinkAsync(__dirname + '/fixtures/bower_components', dir + '/client/bower_components');
54+
}),
55+
fs.symlinkAsync(__dirname + '/fixtures/node_modules', dir + '/node_modules')
56+
]).then(done);
57+
})
58+
.withGenerators([
59+
require.resolve('../generators/endpoint'),
60+
// [helpers.createDummyGenerator(), 'ng-component:app']
61+
])
62+
.withOptions({
63+
skipInstall: true,
64+
force: true
65+
})
66+
// .withArguments(['upperCaseBug'])
67+
.withPrompts(defaultOptions);
68+
});
69+
70+
describe('default settings', function() {
71+
beforeEach(function(done) {
72+
this.gen.on('end', done);
73+
});
74+
75+
it('generates the proper files', function(done) {
76+
assert.file(getExpectedFiles.app(defaultOptions));
77+
done();
78+
});
79+
80+
it('passes JSCS', function(done) {
81+
runCmd('grunt jscs', done);
82+
});
83+
84+
it('passes JSHint', function(done) {
85+
runCmd('grunt jshint', done);
86+
});
87+
88+
it('passes client tests', function(done) {
89+
runCmd('grunt test:client', done);
90+
});
91+
92+
it('passes client tests', function(done) {
93+
runCmd('grunt test:server', done);
94+
});
95+
});
96+
});

0 commit comments

Comments
 (0)