@@ -33,6 +33,9 @@ const tsconfigPath = path.join(__dirname, 'tsconfig.json');
3333const tslintPath = path . join ( __dirname , 'tslint.json' ) ;
3434const outDir = 'build' ;
3535const sources = [ 'src/**/*.ts' ] ;
36+ const unitTests = [ 'test/**/*.ts' ] ;
37+ const systemTests = [ 'system-test/**/*.ts' ] ;
38+ const allFiles = sources . concat ( unitTests ) . concat ( systemTests ) ;
3639
3740let exitOnError = true ;
3841function onError ( ) {
@@ -84,15 +87,65 @@ gulp.task('compile', () => {
8487 ] ) ;
8588} ) ;
8689
87- gulp . task ( 'test.compile' , [ 'compile' ] , ( ) => {
88- // TODO: Complete this when the test files have been converted
89- // to Typescript.
90+ gulp . task ( 'test.system.copy' , ( ) => {
91+ return gulp . src ( [ 'system- test/**/*' ] )
92+ . pipe ( gulp . dest ( ` ${ outDir } /system-test` ) ) ;
9093} ) ;
9194
92- gulp . task ( 'test.unit' , [ 'compile' ] , cb => {
93- spawn ( 'bash' , [ './bin/run-test.sh' ] , {
95+ gulp . task ( 'test.system.compile' , [ 'compile' , 'test.system.copy' ] , ( ) => {
96+ const tsResult = gulp . src ( systemTests )
97+ . pipe ( sourcemaps . init ( ) )
98+ . pipe ( ts . createProject ( tsconfigPath ) ( ) )
99+ . on ( 'error' , onError ) ;
100+ return merge ( [
101+ tsResult . js
102+ . pipe ( sourcemaps . write (
103+ '.' , { includeContent : false , sourceRoot : '../../system-test' } ) )
104+ . pipe ( gulp . dest ( `${ outDir } /system-test` ) ) ,
105+ tsResult . js . pipe ( gulp . dest ( `${ outDir } /system-test` ) )
106+ ] ) ;
107+ } ) ;
108+
109+ gulp . task ( 'test.packagejson.copy' , ( ) => {
110+ return gulp . src ( [ 'package.json' ] )
111+ . pipe ( gulp . dest ( `${ outDir } ` ) ) ;
112+ } ) ;
113+
114+ gulp . task ( 'test.unit.copy' , ( ) => {
115+ return gulp . src ( [ 'test/**/*' ] )
116+ . pipe ( gulp . dest ( `${ outDir } /test` ) ) ;
117+ } ) ;
118+
119+ gulp . task ( 'test.unit.compile' , [ 'test.unit.copy' , 'test.packagejson.copy' , 'compile' ] , ( ) => {
120+ const tsResult = gulp . src ( unitTests )
121+ . pipe ( sourcemaps . init ( ) )
122+ . pipe ( ts . createProject ( tsconfigPath ) ( ) )
123+ . on ( 'error' , onError ) ;
124+ return merge ( [
125+ tsResult . js
126+ . pipe ( sourcemaps . write (
127+ '.' , { includeContent : false , sourceRoot : '../../test' } ) )
128+ . pipe ( gulp . dest ( `${ outDir } /test` ) ) ,
129+ tsResult . js . pipe ( gulp . dest ( `${ outDir } /test` ) )
130+ ] ) ;
131+ } ) ;
132+
133+ function runTests ( withCoverage , cb ) {
134+ var args = [ path . join ( '.' , 'bin' , 'run-test.sh' ) ] ;
135+ if ( withCoverage ) {
136+ args = args . concat ( '-c' ) ;
137+ }
138+ spawn ( 'bash' , args , {
94139 stdio : 'inherit'
95140 } ) . on ( 'close' , cb ) ;
141+ }
142+
143+ gulp . task ( 'test.run' , [ 'test.unit.compile' , 'test.system.compile' ] , cb => {
144+ runTests ( false , cb ) ;
145+ } ) ;
146+
147+ gulp . task ( 'test.coverage.run' , [ 'test.unit.compile' , 'test.system.compile' ] , cb => {
148+ runTests ( true , cb ) ;
96149} ) ;
97150
98151gulp . task ( 'watch' , ( ) => {
@@ -102,5 +155,8 @@ gulp.task('watch', () => {
102155 return gulp . watch ( sources , [ 'test.compile' ] ) ;
103156} ) ;
104157
105- gulp . task ( 'test' , [ 'test.unit' , 'test.check-format' , 'test.check-lint' ] ) ;
106- gulp . task ( 'default' , [ 'compile' ] ) ;
158+ // TODO: Enable linting and checking format after the conversion to
159+ // Typescript is complete.
160+ gulp . task ( 'test' , [ 'test.run' ] ) ; //, 'test.check-format', 'test.check-lint']);
161+ gulp . task ( 'test.coverage' , [ 'test.coverage.run' ] ) ; //, 'test.check-format', 'test.check-lint']);
162+ gulp . task ( 'default' , [ 'compile' , 'test.unit.compile' , 'test.system.compile' ] ) ;
0 commit comments