@@ -4,11 +4,15 @@ import fs from 'fs';
44import _ from 'lodash' ;
55import Promise from 'bluebird' ;
66Promise . promisifyAll ( fs ) ;
7- import { exec } from 'child_process' ;
87import helpers from 'yeoman-test' ;
98import assert from 'yeoman-assert' ;
109import * 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' ;
1216
1317const defaultOptions = {
1418 buildtool : 'grunt' ,
@@ -28,52 +32,6 @@ const defaultOptions = {
2832} ;
2933const TEST_DIR = __dirname ;
3034
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-
7735function runGen ( prompts ) {
7836 return new Promise ( ( resolve , reject ) => {
7937 let dir ;
@@ -130,12 +88,6 @@ function runEndpointGen(name, opt={}) {
13088 } ) ;
13189}
13290
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-
13991describe ( 'angular-fullstack:app' , function ( ) {
14092 beforeEach ( function ( ) {
14193 this . gen = runGen ( defaultOptions ) ;
0 commit comments