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
+ } ) ;
0 commit comments