Skip to content

Commit e0650d5

Browse files
committed
chore(cleanup): Cleaned up the init tests
1 parent 307172d commit e0650d5

File tree

1 file changed

+103
-107
lines changed

1 file changed

+103
-107
lines changed

tests/init.test.js

Lines changed: 103 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,121 @@
1-
var chai = require( 'chai' )
2-
, expect = chai.expect
3-
, exec = require('child_process').exec
4-
, path = require( 'path' )
1+
var path = require( 'path' )
52
, rimraf = require( 'rimraf' )
63
, async = require( 'async' )
74
, fs = require( 'fs' )
5+
, exec = require('child_process').exec
6+
, chai = require( 'chai' )
7+
, expect = chai.expect
88
, binPath = path.join( __dirname, '..', 'bin' )
99
, assetPath = path.join( __dirname, 'assets' );
1010

11-
function tap ( options, done ) {
12-
var modules = [ ].concat( options.args || [ ], options.backendModules || [ ], options.frontendModules || [ ] )
13-
, command = path.join( binPath, 'clever-init' ) + ' -f -S ' + options.name + (modules.length > 0 ? ' ' + modules.join( ' ' ) : '' );
11+
function tap( options, done ) {
12+
var modules = [ ].concat( options.args || [ ], options.backendModules || [ ], options.frontendModules || [ ] )
13+
, command = path.join( binPath, 'clever-init' ) + ' -f -S ' + options.name + ( modules.length > 0 ? ' ' + modules.join( ' ' ) : '' );
1414

15-
exec( command, { cwd: assetPath }, function ( err, stdout, stderr ) {
16-
expect( stderr ).to.equal( '' );
15+
exec( command, { cwd: assetPath }, function( err, stdout, stderr ) {
16+
expect( stderr ).to.equal( '' );
1717

18-
if (options.backend === true) {
19-
var backendPath = ( options.frontend === true )
20-
? path.join( assetPath, options.name, 'backend' )
21-
: path.join( assetPath, options.name );
18+
if ( options.backend === true ) {
19+
var backendPath = ( options.frontend === true ) ? path.join( assetPath, options.name, 'backend' ) : path.join( assetPath, options.name );
20+
expect( fs.existsSync( backendPath ) ).to.be.true;
2221

23-
expect( fs.existsSync( backendPath ) ).to.be.true;
24-
var pkgPath = path.join( backendPath, 'package.json' )
25-
, pkgJson = require( pkgPath );
22+
var pkgPath = path.join( backendPath, 'package.json' )
23+
, pkgJson = require( pkgPath );
2624

27-
expect( fs.existsSync( pkgPath ) ).to.be.true;
28-
expect( pkgJson.name ).to.equal( 'node-seed' );
29-
} else {
30-
expect( fs.existsSync( path.join( assetPath, options.name, 'backend' ) ) ).to.be.false;
31-
}
25+
expect( fs.existsSync( pkgPath ) ).to.be.true;
26+
expect( pkgJson.name ).to.equal( 'node-seed' );
27+
} else {
28+
expect( fs.existsSync( path.join( assetPath, options.name, 'backend' ) ) ).to.be.false;
29+
}
3230

33-
if (options.frontend === true) {
34-
var frontendPath = ( options.backend === true )
35-
? path.join( assetPath, options.name, 'frontend' )
36-
: path.join( assetPath, options.name );
31+
if ( options.frontend === true ) {
32+
var frontendPath = ( options.backend === true ) ? path.join( assetPath, options.name, 'frontend' ) : path.join( assetPath, options.name );
33+
expect( fs.existsSync( frontendPath ) ).to.be.true;
3734

38-
expect( fs.existsSync( frontendPath ) ).to.be.true;
39-
var pkgPath2 = path.join( frontendPath, 'package.json' )
40-
, bowerPath = path.join( frontendPath, 'bower.json' );
35+
var pkgPath2 = path.join( frontendPath, 'package.json' )
36+
, bowerPath = path.join( frontendPath, 'bower.json' );
4137

42-
expect( fs.existsSync( pkgPath2 ) ).to.be.true;
43-
expect( fs.existsSync( bowerPath ) ).to.be.true;
38+
expect( fs.existsSync( pkgPath2 ) ).to.be.true;
39+
expect( fs.existsSync( bowerPath ) ).to.be.true;
4440

45-
var pkgJson2 = require( pkgPath2 );
46-
expect( pkgJson2.name ).to.equal( 'angular-seed' );
47-
} else {
48-
expect( fs.existsSync( path.join( assetPath, options.name, 'frontend' ) ) ).to.be.false;
49-
}
41+
var pkgJson2 = require( pkgPath2 );
42+
expect( pkgJson2.name ).to.equal( 'angular-seed' );
43+
} else {
44+
expect( fs.existsSync( path.join( assetPath, options.name, 'frontend' ) ) ).to.be.false;
45+
}
5046

51-
done( err );
52-
} );
47+
done( err );
48+
});
5349
}
5450

5551
describe( 'Init (these tests will take a long time)', function ( ) {
56-
after( function ( done ) {
57-
fs.readdir( assetPath, function ( err, dirs ) {
58-
async.each( dirs, function ( dir, next ) {
59-
// always keep .gitkeep and we'll use my-new-project within other tests
60-
// to help reduce total test time and rebuilding projects
61-
if ([ '.gitkeep', 'my-new-project' ].indexOf( dir ) > -1) {
62-
return next( );
63-
}
64-
65-
rimraf( path.join( assetPath, dir ), next );
66-
}, done );
67-
} );
68-
} );
69-
70-
describe( 'should be able to initialize a new project with both backend and frontend', function ( ) {
71-
it( 'with no other modules', function ( done ) {
72-
tap( {
73-
name: 'my-new-project',
74-
frontend: true,
75-
backend: true
76-
}, done );
77-
} );
78-
79-
it( 'with modules', function ( done ) {
80-
tap( {
81-
name: 'my-new-project2',
82-
backend: true,
83-
frontend: true,
84-
backendModules: [ 'backend-example-module' ],
85-
frontendModules: [ 'clever-datatables' ]
86-
}, function ( err ) {
87-
expect( fs.existsSync( path.join( assetPath, 'my-new-project2', 'backend', 'modules', 'backend-example-module' ) ) ).to.be.true;
88-
expect( fs.existsSync( path.join( assetPath, 'my-new-project2', 'frontend', 'app', 'modules', 'cs_datatables' ) ) ).to.be.true;
89-
90-
var csData = path.join( assetPath, 'my-new-project2', 'frontend', 'app', 'modules', 'cs_datatables', 'bower.json' );
91-
expect( fs.existsSync( csData ) ).to.be.true;
92-
93-
var csJson = require( csData );
94-
expect( csJson.name ).to.equal( 'clever-datatables' );
95-
96-
done( err );
97-
} );
98-
} );
99-
100-
it( 'backend', function ( done ) {
101-
tap( {
102-
name: 'my-new-project3',
103-
args: [ 'backend' ],
104-
frontend: false,
105-
backend: true
106-
}, done );
107-
} );
108-
109-
it( 'frontend', function ( done ) {
110-
tap( {
111-
name: 'my-new-project4',
112-
args: [ 'frontend' ],
113-
frontend: true,
114-
backend: false
115-
}, done );
116-
} );
117-
118-
it( 'should not be able to initialize a new project with the same name', function ( done ) {
119-
exec( path.join( binPath, 'clever-init' ) + ' --skip-protractor my-new-project', { cwd: assetPath }, function ( err, stdout ) {
120-
expect( stdout ).to.match( /folder already exists/ );
121-
done( err );
122-
} );
123-
} );
124-
} );
125-
} );
52+
after( function( done ) {
53+
fs.readdir( assetPath, function( err, dirs ) {
54+
async.each( dirs, function( dir, next ) {
55+
// always keep .gitkeep and we'll use my-new-project within other tests
56+
// to help reduce total test time and rebuilding projects
57+
if ( [ '.gitkeep', 'my-new-project' ].indexOf( dir ) > -1 ) {
58+
return next( );
59+
}
60+
61+
rimraf( path.join( assetPath, dir ), next );
62+
}, done );
63+
});
64+
});
65+
66+
describe( 'should be able to initialize a new project with both backend and frontend', function ( ) {
67+
it( 'with no other modules', function( done ) {
68+
tap({
69+
name : 'my-new-project',
70+
backend : true,
71+
frontend : true
72+
}, done );
73+
});
74+
75+
it( 'with modules', function( done ) {
76+
tap({
77+
name : 'my-new-project2',
78+
backend : true,
79+
frontend : true,
80+
backendModules : [ 'backend-example-module' ],
81+
frontendModules : [ 'clever-datatables' ]
82+
}, function( err ) {
83+
expect( fs.existsSync( path.join( assetPath, 'my-new-project2', 'backend', 'modules', 'backend-example-module' ) ) ).to.be.true;
84+
expect( fs.existsSync( path.join( assetPath, 'my-new-project2', 'frontend', 'app', 'modules', 'cs_datatables' ) ) ).to.be.true;
85+
86+
var csData = path.join( assetPath, 'my-new-project2', 'frontend', 'app', 'modules', 'cs_datatables', 'bower.json' );
87+
expect( fs.existsSync( csData ) ).to.be.true;
88+
89+
var csJson = require( csData );
90+
expect( csJson.name ).to.equal( 'clever-datatables' );
91+
92+
done( err );
93+
});
94+
});
95+
96+
it( 'backend', function( done ) {
97+
tap({
98+
name : 'my-new-project3',
99+
args : [ 'backend' ],
100+
backend : true,
101+
frontend : false
102+
}, done );
103+
});
104+
105+
it( 'frontend', function ( done ) {
106+
tap( {
107+
name : 'my-new-project4',
108+
args : [ 'frontend' ],
109+
backend : false,
110+
frontend : true
111+
}, done );
112+
});
113+
114+
it( 'should not be able to initialize a new project with the same name', function( done ) {
115+
exec( path.join( binPath, 'clever-init' ) + ' --skip-protractor my-new-project', { cwd: assetPath }, function( err, stdout ) {
116+
expect( stdout ).to.match( /folder already exists/ );
117+
done( err );
118+
});
119+
});
120+
});
121+
});

0 commit comments

Comments
 (0)