Skip to content

Commit 36d79c2

Browse files
committed
feat(gen:tests): a bunch of test progress
1 parent d51295a commit 36d79c2

1 file changed

Lines changed: 163 additions & 14 deletions

File tree

src/test/main.test.js

Lines changed: 163 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'use strict';
22
import path from 'path';
33
import fs from 'fs';
4+
import _ from 'lodash';
45
import Promise from 'bluebird';
56
Promise.promisifyAll(fs);
67
import {exec} from 'child_process';
78
import helpers from 'yeoman-test';
89
import assert from 'yeoman-assert';
910
import * as getExpectedFiles from './get-expected-files';
11+
import recursiveReadDir from 'recursive-readdir';
1012

1113
const defaultOptions = {
1214
buildtool: 'grunt',
@@ -26,6 +28,12 @@ const defaultOptions = {
2628
};
2729
// var DEBUG = true;
2830
var DEBUG = false;
31+
const TEST_DIR = __dirname;
32+
33+
function copyAsync(src, dest) {
34+
return fs.readFileAsync(src)
35+
.then(data => fs.writeFileAsync(dest, data));
36+
}
2937

3038
/**
3139
* @callback doneCallback
@@ -50,14 +58,36 @@ function runCmd(cmd, done) {
5058
});
5159
}
5260

53-
describe('angular-fullstack:app', function() {
54-
beforeEach(function() {
55-
this.gen = helpers
61+
function assertOnlyFiles(expectedFiles, topLevelPath='./', skip=['node_modules', 'bower_components']) {
62+
return new Promise((resolve, reject) => {
63+
recursiveReadDir(topLevelPath, skip, function(err, actualFiles) {
64+
if(err) return reject(err);
65+
66+
actualFiles = _.map(actualFiles.concat(), file => path.normalize(file.replace(path.normalize(`${topLevelPath}/`), '')));
67+
expectedFiles = _.map(expectedFiles, file => path.normalize(file));
68+
69+
let extras = _.pullAll(actualFiles, expectedFiles);
70+
71+
if(extras.length !== 0) {
72+
return reject(extras);
73+
}
74+
resolve();
75+
});
76+
});
77+
}
78+
79+
function runGen(prompts) {
80+
return new Promise((resolve, reject) => {
81+
let dir;
82+
helpers
5683
.run(require.resolve('../generators/app'))
57-
.inTmpDir(function(dir) {
84+
.inTmpDir(function(_dir) {
85+
// this will create a new temporary directory for each new generator run
5886
var done = this.async();
59-
if(DEBUG) console.log(`TEMP DIR: ${dir}`);
87+
if(DEBUG) console.log(`TEMP DIR: ${_dir}`);
88+
dir = _dir;
6089

90+
// symlink our dependency directories
6191
return Promise.all([
6292
fs.mkdirAsync(dir + '/client').then(() => {
6393
return fs.symlinkAsync(__dirname + '/fixtures/bower_components', dir + '/client/bower_components');
@@ -70,21 +100,62 @@ describe('angular-fullstack:app', function() {
70100
// [helpers.createDummyGenerator(), 'ng-component:app']
71101
])
72102
.withOptions({
73-
skipInstall: true,
74-
force: true
103+
skipInstall: true
75104
})
76105
// .withArguments(['upperCaseBug'])
77-
.withPrompts(defaultOptions);
106+
.withPrompts(prompts)
107+
.on('error', reject)
108+
.on('end', () => resolve(dir));
109+
});
110+
}
111+
112+
function runEndpointGen(name, opt={}) {
113+
let prompts = opt.prompts || {};
114+
let options = opt.options || {};
115+
let config = opt.config;
116+
117+
return new Promise((resolve, reject) => {
118+
let gen = helpers
119+
.run(require.resolve('../generators/endpoint'), {tmpdir: false})
120+
.withOptions(options)
121+
.withArguments([name])
122+
.withPrompts(prompts);
123+
124+
if(config) {
125+
gen
126+
.withLocalConfig(config);
127+
}
128+
129+
gen
130+
.on('error', reject)
131+
.on('end', () => resolve())
132+
});
133+
}
134+
135+
function getConfig(dir) {
136+
return fs.readFileAsync(path.join(dir, '.yo-rc.json'), 'utf8').then(data => {
137+
return JSON.parse(data);
138+
});
139+
}
140+
141+
describe('angular-fullstack:app', function() {
142+
beforeEach(function() {
143+
this.gen = runGen(defaultOptions);
78144
});
79145

80146
describe('default settings', function() {
81-
beforeEach(function(done) {
82-
this.gen.on('end', done);
147+
var dir;
148+
149+
beforeEach(function() {
150+
return this.gen.then(_dir => {
151+
dir = _dir;
152+
});
83153
});
84154

85-
it('generates the proper files', function(done) {
86-
assert.file(getExpectedFiles.app(defaultOptions));
87-
done();
155+
it('generates the proper files', function() {
156+
const expectedFiles = getExpectedFiles.app(defaultOptions);
157+
assert.file(expectedFiles);
158+
return assertOnlyFiles(expectedFiles, path.normalize(dir)).should.eventually.be.fulfilled;
88159
});
89160

90161
it('passes JSCS', function(done) {
@@ -99,8 +170,86 @@ describe('angular-fullstack:app', function() {
99170
runCmd('grunt test:client', done);
100171
});
101172

102-
it('passes client tests', function(done) {
173+
it('passes server tests', function(done) {
103174
runCmd('grunt test:server', done);
104175
});
176+
177+
describe('with a generated endpont', function() {
178+
beforeEach(function() {
179+
getConfig(dir).then(config => {
180+
return runEndpointGen('foo', {config: config['generator-angular-fullstack']});
181+
});
182+
});
183+
184+
it('should pass jscs'); //'foo'
185+
186+
it('should pass lint');
187+
188+
it('should run server tests successfully', function(done) {
189+
runCmd('grunt test:server', done);
190+
});
191+
});
192+
193+
describe.only('with a generated capitalized endpont', function() {
194+
beforeEach(function() {
195+
getConfig(dir).then(config => {
196+
return runEndpointGen('Foo', {config: config['generator-angular-fullstack']});
197+
});
198+
});
199+
200+
it('should pass jscs');
201+
202+
it('should pass lint');
203+
204+
it('should run server tests successfully', function(done) {
205+
runCmd('grunt test:server', done);
206+
});
207+
});
208+
209+
it('should pass lint with generated path name endpoint'); //'foo/bar'
210+
211+
it('should run server tests successfully with generated path name endpoint');
212+
213+
it('should generate expected files with path name endpoint');
214+
// [
215+
// 'server/api/foo/bar/index.js',
216+
// 'server/api/foo/bar/index.spec.js',
217+
// 'server/api/foo/bar/bar.controller.js',
218+
// 'server/api/foo/bar/bar.events.js',
219+
// 'server/api/foo/bar/bar.integration.js',
220+
// 'server/api/foo/bar/bar.model.js',
221+
// 'server/api/foo/bar/bar.socket.js'
222+
// ]
223+
224+
it('should use existing config if available');
225+
// this.timeout(60000);
226+
// return copyAsync(__dirname + '/fixtures/.yo-rc.json', __dirname + '/temp/.yo-rc.json').then(() => {
227+
// var gen = helpers.createGenerator('angular-fullstack:app', [
228+
// '../../generators/app',
229+
// '../../generators/endpoint',
230+
// [
231+
// helpers.createDummyGenerator(),
232+
// 'ng-component:app'
233+
// ]
234+
// ], [], {
235+
// skipInstall: true
236+
// });
237+
// helpers.mockPrompt(gen, {
238+
// skipConfig: true
239+
// });
240+
// gen.run(function () {
241+
// assert.file([
242+
// 'client/app/main/main.less',
243+
// 'server/auth/google/passport.js'
244+
// ]);
245+
// done();
246+
// });
247+
// });
248+
249+
if(!process.env.SKIP_E2E) {
250+
it('should run e2e tests successfully'); //'grunt test:e2e'
251+
252+
it('should run e2e tests successfully for production app'); //'grunt test:e2e:prod'
253+
}
105254
});
106255
});

0 commit comments

Comments
 (0)