Skip to content

Commit 887476f

Browse files
committed
feat(gen:test): add endpoint-specific tests
1 parent 2a1d702 commit 887476f

File tree

3 files changed

+202
-8
lines changed

3 files changed

+202
-8
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"jit-grunt": "~0.10.0",
7575
"lazypipe": "^1.0.1",
7676
"merge-stream": "^1.0.0",
77+
"minimatch": "^3.0.0",
7778
"mocha": "^2.2.5",
7879
"q": "^1.0.1",
7980
"recursive-readdir": "^2.0.0",

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

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
'use strict';
2+
import path from 'path';
3+
import fs from 'fs';
4+
import _ from 'lodash';
5+
import Promise from 'bluebird';
6+
Promise.promisifyAll(fs);
7+
import helpers from 'yeoman-test';
8+
import assert from 'yeoman-assert';
9+
import minimatch from 'minimatch';
10+
import * as getExpectedFiles from './get-expected-files';
11+
import {
12+
copyAsync,
13+
runCmd,
14+
assertOnlyFiles,
15+
getConfig
16+
} from './test-helpers';
17+
18+
const TEST_DIR = __dirname;
19+
20+
const defaultOptions = {
21+
buildtool: 'grunt',
22+
script: 'js',
23+
transpiler: 'babel',
24+
markup: 'html',
25+
stylesheet: 'sass',
26+
router: 'uirouter',
27+
testing: 'mocha',
28+
chai: 'expect',
29+
bootstrap: true,
30+
uibootstrap: true,
31+
odms: ['mongoose'],
32+
auth: true,
33+
oauth: [],
34+
socketio: true
35+
};
36+
function runGen(prompts) {
37+
return new Promise((resolve, reject) => {
38+
let dir;
39+
helpers
40+
.run(require.resolve('../generators/app'))
41+
.inTmpDir(function(_dir) {
42+
// this will create a new temporary directory for each new generator run
43+
var done = this.async();
44+
if(DEBUG) console.log(`TEMP DIR: ${_dir}`);
45+
dir = _dir;
46+
47+
// symlink our dependency directories
48+
return Promise.all([
49+
fs.mkdirAsync(dir + '/client').then(() => {
50+
return fs.symlinkAsync(__dirname + '/fixtures/bower_components', dir + '/client/bower_components');
51+
}),
52+
fs.symlinkAsync(__dirname + '/fixtures/node_modules', dir + '/node_modules')
53+
]).then(done);
54+
})
55+
.withGenerators([
56+
require.resolve('../generators/endpoint'),
57+
// [helpers.createDummyGenerator(), 'ng-component:app']
58+
])
59+
.withOptions({
60+
skipInstall: true
61+
})
62+
.withPrompts(prompts)
63+
.on('error', reject)
64+
.on('end', () => resolve(dir));
65+
});
66+
}
67+
68+
function runEndpointGen(name, opt={}) {
69+
let prompts = opt.prompts || {};
70+
let options = opt.options || {};
71+
let config = opt.config;
72+
73+
return new Promise((resolve, reject) => {
74+
let dir;
75+
let gen = helpers
76+
.run(require.resolve('../generators/endpoint'))
77+
.inTmpDir(function(_dir) {
78+
// this will create a new temporary directory for each new generator run
79+
var done = this.async();
80+
if(DEBUG) console.log(`TEMP DIR: ${_dir}`);
81+
dir = _dir;
82+
83+
// symlink our dependency directories
84+
return Promise.all([
85+
fs.mkdirAsync(dir + '/client').then(() => {
86+
return fs.symlinkAsync(__dirname + '/fixtures/bower_components', dir + '/client/bower_components');
87+
}),
88+
fs.symlinkAsync(__dirname + '/fixtures/node_modules', dir + '/node_modules')
89+
]).then(done);
90+
})
91+
.withOptions(options)
92+
.withArguments([name])
93+
.withPrompts(prompts);
94+
95+
if(config) {
96+
gen
97+
.withLocalConfig(config);
98+
}
99+
100+
gen
101+
.on('error', reject)
102+
.on('end', () => resolve(dir))
103+
});
104+
}
105+
106+
let jshintCmd = path.join(TEST_DIR, '/fixtures/node_modules/.bin/jshint');
107+
function jshint(_path, opt={}) {
108+
let {exclude, config} = opt;
109+
let cmd = `${jshintCmd} ${path.normalize(_path)}`;
110+
if(exclude) cmd += ` --exclude ${exclude}`;
111+
if(config) cmd += ` --config ${config}`;
112+
return runCmd(cmd);
113+
}
114+
115+
var config;
116+
var genDir;
117+
118+
before(function() {
119+
return Promise.all([
120+
runGen(defaultOptions).then(_dir => {
121+
genDir = _dir;
122+
}),
123+
getConfig(path.join(TEST_DIR, 'fixtures/.yo-rc.json')).then(_config => {
124+
_config['generator-angular-fullstack'].insertRoutes = false;
125+
_config['generator-angular-fullstack'].pluralizeRoutes = false;
126+
_config['generator-angular-fullstack'].insertSockets = false;
127+
_config['generator-angular-fullstack'].insertModels = false;
128+
config = _config;
129+
})
130+
]);
131+
});
132+
133+
describe('angular-fullstack:endpoint', function() {
134+
describe(`with a generated endpont 'foo'`, function() {
135+
var dir;
136+
beforeEach(function() {
137+
return runEndpointGen('foo', {config: config['generator-angular-fullstack']}).then(_dir => {
138+
dir = _dir;
139+
140+
return Promise.all([
141+
copyAsync(path.join(genDir, '/server/.jshintrc'), './server/.jshintrc'),
142+
copyAsync(path.join(genDir, '/server/.jshintrc-spec'), './server/.jshintrc-spec')
143+
]);
144+
});
145+
});
146+
147+
it('should generate the expected files', function() {
148+
assert.file(getExpectedFiles.endpoint('foo'));
149+
});
150+
151+
it('should pass jscs');
152+
153+
it('should pass lint', function() {
154+
let endpointDir = path.join(dir, 'server/api/foo/');
155+
let regFiles = fs.readdirAsync(endpointDir)
156+
.then(files => files.filter(file => minimatch(file, '**/!(*.spec|*.mock|*.integration).js', {dot: true})))
157+
.map(file => jshint(`./server/api/foo/${file}`));
158+
159+
let specFiles = fs.readdirAsync(endpointDir)
160+
.then(files => files.filter(file => minimatch(file, '**/+(*.spec|*.mock|*.integration).js', {dot: true})))
161+
.map(file => jshint(`./server/api/food/${file}`, {config: 'server/.jshintrc-spec'}));
162+
163+
return Promise.all([regFiles, specFiles]).should.be.fulfilled();
164+
});
165+
});
166+
167+
describe('with a generated capitalized endpont', function() {
168+
var dir;
169+
beforeEach(function() {
170+
return runEndpointGen('foo', {config: config['generator-angular-fullstack']}).then(_dir => {
171+
dir = _dir;
172+
});
173+
});
174+
175+
it('should pass jscs');
176+
177+
it('should pass lint');
178+
});
179+
180+
describe('with a generated path name endpont', function() {
181+
var dir;
182+
beforeEach(function() {
183+
return runEndpointGen('foo', {config: config['generator-angular-fullstack']}).then(_dir => {
184+
dir = _dir;
185+
});
186+
});
187+
188+
it('should pass jscs');
189+
190+
it('should pass lint');
191+
});
192+
});

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,15 @@ export function app(options) {
224224
return files;
225225
}
226226

227-
export function endpoint(name, options) {
227+
export function endpoint(name, path) {
228+
if(!path) path = name;
228229
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`
230+
`server/api/${path}/index.js`,
231+
`server/api/${path}/index.spec.js`,
232+
`server/api/${path}/${name}.controller.js`,
233+
`server/api/${path}/${name}.events.js`,
234+
`server/api/${path}/${name}.integration.js`,
235+
`server/api/${path}/${name}.model.js`,
236+
`server/api/${path}/${name}.socket.js`
236237
];
237238
}

0 commit comments

Comments
 (0)