@@ -26,6 +26,7 @@ const fs = require('fs');
26
26
const path = require ( 'path' ) ;
27
27
const Vinyl = require ( 'vinyl' ) ;
28
28
const Stream = require ( 'stream' ) ;
29
+ const moment = require ( 'moment' ) ;
29
30
const gulpHeaderComment = require ( '../src/index' ) ;
30
31
const EOL = '\n' ;
31
32
@@ -296,4 +297,35 @@ describe('gulp-header-comment', () => {
296
297
stream . write ( vinyl ) ;
297
298
stream . end ( ) ;
298
299
} ) ;
300
+
301
+ it ( 'should prepend header with interpolated template' , ( done ) => {
302
+ const filePath = path . join ( base , 'test.js' ) ;
303
+ const code = fs . readFileSync ( filePath , 'utf-8' ) ;
304
+ expect ( code ) . not . toEqual ( '' ) ;
305
+
306
+ const contents = new Buffer ( code ) ;
307
+ const vinyl = new Vinyl ( { cwd, base, contents, path : filePath } ) ;
308
+ const header = `Generated on <%= moment().format('YYYY') %>` ;
309
+ const expectedHeader =
310
+ '/**' + EOL +
311
+ ' * Generated on ' + moment ( ) . format ( 'YYYY' ) + EOL +
312
+ ' */' ;
313
+
314
+ const stream = gulpHeaderComment ( header ) ;
315
+
316
+ stream . on ( 'data' , ( newFile ) => {
317
+ expect ( newFile . contents ) . toEqual ( new Buffer ( expectedHeader + EOL + EOL + code ) ) ;
318
+ } ) ;
319
+
320
+ stream . once ( 'error' , ( err ) => {
321
+ done . fail ( err ) ;
322
+ } ) ;
323
+
324
+ stream . once ( 'end' , ( ) => {
325
+ done ( ) ;
326
+ } ) ;
327
+
328
+ stream . write ( vinyl ) ;
329
+ stream . end ( ) ;
330
+ } ) ;
299
331
} ) ;
0 commit comments