@@ -4,11 +4,15 @@ import fs from 'fs';
4
4
import _ from 'lodash' ;
5
5
import Promise from 'bluebird' ;
6
6
Promise . promisifyAll ( fs ) ;
7
- import { exec } from 'child_process' ;
8
7
import helpers from 'yeoman-test' ;
9
8
import assert from 'yeoman-assert' ;
10
9
import * as getExpectedFiles from './get-expected-files' ;
11
- import recursiveReadDir from 'recursive-readdir' ;
10
+ import {
11
+ copyAsync ,
12
+ runCmd ,
13
+ assertOnlyFiles ,
14
+ getConfig
15
+ } from './test-helpers' ;
12
16
13
17
const defaultOptions = {
14
18
buildtool : 'grunt' ,
@@ -28,52 +32,6 @@ const defaultOptions = {
28
32
} ;
29
33
const TEST_DIR = __dirname ;
30
34
31
- function copyAsync ( src , dest ) {
32
- return fs . readFileAsync ( src )
33
- . then ( data => fs . writeFileAsync ( dest , data ) ) ;
34
- }
35
-
36
- /**
37
- * @callback doneCallback
38
- * @param {null|Error } err
39
- */
40
-
41
- /**
42
- * Run the given command in a child process
43
- * @param {string } cmd - command to run
44
- * @param {doneCallback } done
45
- */
46
- function runCmd ( cmd , done ) {
47
- exec ( cmd , { } , function ( err , stdout , stderr ) {
48
- if ( err ) {
49
- console . error ( stdout ) ;
50
- throw new Error ( `Error running command: ${ cmd } ` ) ;
51
- done ( err ) ;
52
- } else {
53
- if ( DEBUG ) console . log ( stdout ) ;
54
- done ( ) ;
55
- }
56
- } ) ;
57
- }
58
-
59
- function assertOnlyFiles ( expectedFiles , topLevelPath = './' , skip = [ 'node_modules' , 'bower_components' ] ) {
60
- return new Promise ( ( resolve , reject ) => {
61
- recursiveReadDir ( topLevelPath , skip , function ( err , actualFiles ) {
62
- if ( err ) return reject ( err ) ;
63
-
64
- actualFiles = _ . map ( actualFiles . concat ( ) , file => path . normalize ( file . replace ( path . normalize ( `${ topLevelPath } /` ) , '' ) ) ) ;
65
- expectedFiles = _ . map ( expectedFiles , file => path . normalize ( file ) ) ;
66
-
67
- let extras = _ . pullAll ( actualFiles , expectedFiles ) ;
68
-
69
- if ( extras . length !== 0 ) {
70
- return reject ( extras ) ;
71
- }
72
- resolve ( ) ;
73
- } ) ;
74
- } ) ;
75
- }
76
-
77
35
function runGen ( prompts ) {
78
36
return new Promise ( ( resolve , reject ) => {
79
37
let dir ;
@@ -130,12 +88,6 @@ function runEndpointGen(name, opt={}) {
130
88
} ) ;
131
89
}
132
90
133
- function getConfig ( dir ) {
134
- return fs . readFileAsync ( path . join ( dir , '.yo-rc.json' ) , 'utf8' ) . then ( data => {
135
- return JSON . parse ( data ) ;
136
- } ) ;
137
- }
138
-
139
91
describe ( 'angular-fullstack:app' , function ( ) {
140
92
beforeEach ( function ( ) {
141
93
this . gen = runGen ( defaultOptions ) ;
0 commit comments